Added mlimit to the superconfig, dropped mtreelimit

This should be stored in the superconfig, and we should use it during
mount instead of rederiving it from the block_size (TODO).

Note that this stores the "mlimit", (1 << mbits)-1, not the mbits
directly. littlefs will probably always be limited to powers-of-two for
this, since mbits is fairly arbitrary, but storing the expanded value
allows for non-powers-of-two _just in case_.
This commit is contained in:
Christopher Haster
2023-09-14 15:02:55 -05:00
parent d44f9bdcd0
commit 5504936b10
3 changed files with 68 additions and 54 deletions
+21 -22
View File
@@ -6235,15 +6235,16 @@ static lfsr_data_t lfsr_data_fromsuperconfig(lfs_t *lfs,
LFS_ASSERT(d_ >= 0);
d += d_;
// on-disk mlimit
lfsr_mid_t mlimit = lfsr_mweight(lfs)-1;
d_ = lfs_toleb128(mlimit, &buffer[d], 5);
LFS_ASSERT(d_ >= 0);
d += d_;
// on-disk utag limit
buffer[d] = 0x7f;
d += 1;
// on-disk mtree limit
d_ = lfs_toleb128(0x7fffffff, &buffer[d], 5);
LFS_ASSERT(d_ >= 0);
d += d_;
// on-disk attr limit
d_ = lfs_toleb128(0x7fffffff, &buffer[d], 5);
LFS_ASSERT(d_ >= 0);
@@ -6432,6 +6433,21 @@ static int lfsr_mountinited(lfs_t *lfs) {
return LFS_ERR_INVAL;
}
// check the on-disk mtree limit
// TODO actually use this
lfsr_mid_t mlimit;
err = lfsr_data_readleb128(lfs, &data, (int32_t*)&mlimit);
// treat any leb128 overflows as out-of-range values
if (err && err != LFS_ERR_CORRUPT) {
return err;
}
if (err == LFS_ERR_CORRUPT || mlimit != lfsr_mweight(lfs)-1) {
LFS_ERROR("Incompatible mlimit 0x%"PRIx32,
(err ? (lfsr_mid_t)-1 : mlimit));
return LFS_ERR_INVAL;
}
// check the on-disk utag limit
// TODO actually use this
int32_t utag_limit;
@@ -6449,23 +6465,6 @@ static int lfsr_mountinited(lfs_t *lfs) {
return LFS_ERR_INVAL;
}
// check the on-disk mtree limit
// TODO actually use this
lfsr_smid_t mtree_limit;
err = lfsr_data_readleb128(lfs, &data, &mtree_limit);
// treat any leb128 overflows as out-of-range values
if (err && err != LFS_ERR_CORRUPT) {
return err;
}
if (err == LFS_ERR_CORRUPT || mtree_limit != 0x7fffffff) {
LFS_ERROR("Incompatible mdir limit 0x%"PRIx32
" (> 0x%"PRIx32")",
(err ? -1 : mtree_limit),
0x7fffffff);
return LFS_ERR_INVAL;
}
// check the on-disk attr limit
// TODO actually use this
lfs_ssize_t attr_limit;