Tweaked name/sizelimit parsing for consistency, default to 0xff/0x7fffffff
This is mostly just for consistency with changes to parsing other parts
of the fs config attrs.
This changes name/size limits to default to namelimit=0xff and
sizelimit=0x7fffffff. These are reasonable defaults for 32-bit systems,
which was the original use case for littlefs. Though, with the diversity
of embedded device, I suspect these will be overridden more often than
not. For this reason the 0xff/0x7fffffff case is not treated specially
during lfs_format and these limits are always written. Though this may
change in the future.
The intention behind these defaults is to align with other limits that
may be introduced in the future. Any new artificial limits will
necessarily require defaulting to their existing values for backwards
compatibility, so hopefully this allows all limits to be handled
consistently.
If a future use-case-specific implementation of littlefs can benefit
from assuming these defaults, that's a nice plus.
Name/size-limit attr encodings:
.---+---+---+---. tag (0x000c): 1 be16 2 bytes
| x000c | 0 |siz| weight (0): 1 leb128 1 byte
+---+---+---+---+ size: 1 leb128 1 byte
| name_limit | name_limit: 1 leb128 <=4 bytes
'---+- -+- -+- -' total: <=8 bytes
.---+---+---+---. tag (0x000d): 1 be16 2 bytes
| x000d | 0 |siz| weight (0): 1 leb128 1 byte
+---+---+---+---+- -. size: 1 leb128 1 byte
| size_limit | size_limit: 1 leb128 <=5 bytes
'---+- -+- -+- -+- -' total: <=9 bytes
Code changes:
code stack
before: 34040 2880
after: 34060 (+0.1%) 2880 (+0.0%)
This commit is contained in:
@@ -8077,23 +8077,20 @@ static int lfsr_mountmroot(lfs_t *lfs, const lfsr_mdir_t *mroot) {
|
||||
}
|
||||
|
||||
// read the name limit
|
||||
uint32_t name_limit = 0xff;
|
||||
err = lfsr_mdir_lookup(lfs, mroot, LFSR_TAG_NAMELIMIT,
|
||||
&data);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_NOENT) {
|
||||
LFS_ERROR("No name limit found");
|
||||
return LFS_ERR_INVAL;
|
||||
if (err && err != LFS_ERR_NOENT) {
|
||||
return err;
|
||||
}
|
||||
if (err != LFS_ERR_NOENT) {
|
||||
err = lfsr_data_readleb128(lfs, &data, &name_limit);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
name_limit = -1;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
uint32_t name_limit;
|
||||
err = lfsr_data_readleb128(lfs, &data, &name_limit);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
name_limit = -1;
|
||||
}
|
||||
|
||||
if (name_limit > lfs->name_limit) {
|
||||
@@ -8106,23 +8103,20 @@ static int lfsr_mountmroot(lfs_t *lfs, const lfsr_mdir_t *mroot) {
|
||||
lfs->name_limit = name_limit;
|
||||
|
||||
// read the size limit
|
||||
uint32_t size_limit = 0x7fffffff;
|
||||
err = lfsr_mdir_lookup(lfs, mroot, LFSR_TAG_SIZELIMIT,
|
||||
&data);
|
||||
if (err) {
|
||||
if (err == LFS_ERR_NOENT) {
|
||||
LFS_ERROR("No size limit found");
|
||||
return LFS_ERR_INVAL;
|
||||
if (err && err != LFS_ERR_NOENT) {
|
||||
return err;
|
||||
}
|
||||
if (err != LFS_ERR_NOENT) {
|
||||
err = lfsr_data_readleb128(lfs, &data, &size_limit);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
size_limit = -1;
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
uint32_t size_limit;
|
||||
err = lfsr_data_readleb128(lfs, &data, &size_limit);
|
||||
if (err && err != LFS_ERR_CORRUPT) {
|
||||
return err;
|
||||
}
|
||||
if (err == LFS_ERR_CORRUPT) {
|
||||
size_limit = -1;
|
||||
}
|
||||
|
||||
if (size_limit > lfs->size_limit) {
|
||||
|
||||
Reference in New Issue
Block a user