Skip to content

Commit

Permalink
Added some checks that metadata_max makes sense
Browse files Browse the repository at this point in the history
Like the read/prog/block_size checks, these are just asserts. If these
invariants are broken the filesystem will break in surprising ways.
  • Loading branch information
geky committed Oct 4, 2024
1 parent 2d62d2f commit ea431bd
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -4210,6 +4210,15 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
LFS_ASSERT(lfs->cfg->compact_thresh == (lfs_size_t)-1
|| lfs->cfg->compact_thresh <= lfs->cfg->block_size);

// check that metadata_max is a multiple of read_size and prog_size,
// and a factor of the block_size
LFS_ASSERT(!lfs->cfg->metadata_max
|| lfs->cfg->metadata_max % lfs->cfg->read_size == 0);
LFS_ASSERT(!lfs->cfg->metadata_max
|| lfs->cfg->metadata_max % lfs->cfg->prog_size == 0);
LFS_ASSERT(!lfs->cfg->metadata_max
|| lfs->cfg->block_size % lfs->cfg->metadata_max == 0);

// setup read cache
if (lfs->cfg->read_buffer) {
lfs->rcache.buffer = lfs->cfg->read_buffer;
Expand Down

0 comments on commit ea431bd

Please sign in to comment.