Skip to content

Commit ea431bd

Browse files
committed
Added some checks that metadata_max makes sense
Like the read/prog/block_size checks, these are just asserts. If these invariants are broken the filesystem will break in surprising ways.
1 parent 2d62d2f commit ea431bd

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

lfs.c

+9
Original file line numberDiff line numberDiff line change
@@ -4210,6 +4210,15 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
42104210
LFS_ASSERT(lfs->cfg->compact_thresh == (lfs_size_t)-1
42114211
|| lfs->cfg->compact_thresh <= lfs->cfg->block_size);
42124212

4213+
// check that metadata_max is a multiple of read_size and prog_size,
4214+
// and a factor of the block_size
4215+
LFS_ASSERT(!lfs->cfg->metadata_max
4216+
|| lfs->cfg->metadata_max % lfs->cfg->read_size == 0);
4217+
LFS_ASSERT(!lfs->cfg->metadata_max
4218+
|| lfs->cfg->metadata_max % lfs->cfg->prog_size == 0);
4219+
LFS_ASSERT(!lfs->cfg->metadata_max
4220+
|| lfs->cfg->block_size % lfs->cfg->metadata_max == 0);
4221+
42134222
// setup read cache
42144223
if (lfs->cfg->read_buffer) {
42154224
lfs->rcache.buffer = lfs->cfg->read_buffer;

0 commit comments

Comments
 (0)