Extended lfsr_mount to accept mount flags
This has been a long-time coming, mount flags are just too useful for
configuring a filesystem at runtime.
Currently this is limited to LFS_M_RDONLY and LFS_M_CKPROGS, but there
are a few more planned in the future:
LFS_M_RDWR = 0x0000, // Mount the filesystem as read and write
LFS_M_RDONLY = 0x0001, // Mount the filesystem as readonly
LFS_M_STRICT* = 0x0002, // Error if on-disk config does not match
LFS_M_FORCE* = 0x0004, // Ignore compat flags, mount readonly
LFS_M_FORCEWITHRECKLESSABANDON*
= 0x0008, // Ignore compat flags, mount read write
LFS_M_CKPROGS = 0x0010, // Check progs by reading back progged data
LFS_M_CKREADS* = 0x0020, // Check reads via checksums
* Hypothetical
As a convenience, we also return mount flags in the struct lfs_fsinfo's
flags field as their relevant LFS_I_* variants. Though only to match
statvfs, and only because it's cheap, littlefs's API is low-level and we
should expect users to know what flags they passed to lfsr_mount.
As for the new mount flags:
- LFS_M_RDONLY - For consistency with existing APIs, this just asserts
on write operations, which makes it a bit useless... But the info flag
LFS_I_RDONLY may be useful for falling back to a readonly mode if
we encounter on-disk compat issues.
At least if implement the theoretical LFS_UNTRUSTED_USER mode
LFS_M_RDONLY could become a runtime error.
- LFS_M_RDWR - This really just exists to compliment LFS_M_RDONLY and to
match LFS_O_RDONLY/LFS_O_RDWR. It's just an alias for 0, and I don't
think there will ever be a reason to make it non-0 (but I can always
be wrong!).
- LFS_M_CKPROGS - This replaces the check_progs config option and avoids
using a full byte to store a bool.
We should probably also have a compile-time option to compile this out
(LFS_NO_CKPROGS?), but that's a future thing to do.
This ended up adding a surprising bit of code, considering we're just
moving flags around, and noise in lfs_alloc added a bit of stack again:
code stack
before: 35880 2672
after: 35932 (+0.1%) 2680 (+0.3%)
This commit is contained in:
+33
-33
@@ -19,7 +19,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_RM | LFSR_TAG_MAGIC, 0,
|
||||
@@ -27,7 +27,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_CORRUPT;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
# test that we fail if we find bad magic
|
||||
@@ -42,7 +42,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_MAGIC, 0,
|
||||
@@ -50,7 +50,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_CORRUPT;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_CORRUPT;
|
||||
'''
|
||||
|
||||
# test that we fail to mount after a major version bump
|
||||
@@ -65,7 +65,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_VERSION, 0,
|
||||
@@ -75,7 +75,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount after a minor version bump
|
||||
@@ -90,7 +90,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_VERSION, 0,
|
||||
@@ -100,7 +100,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount incompatible rcompat flags
|
||||
@@ -116,7 +116,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_RCOMPAT, 0,
|
||||
@@ -126,7 +126,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount incompatible wcompat flags
|
||||
@@ -142,7 +142,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_WCOMPAT, 0,
|
||||
@@ -152,7 +152,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that an incompatible ocompat flag is a noop
|
||||
@@ -168,7 +168,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_OCOMPAT, 0,
|
||||
@@ -178,7 +178,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should _not_ fail, ocompat should always be ignored
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -194,7 +194,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR_CAT(
|
||||
LFSR_TAG_RCOMPAT, 0,
|
||||
@@ -203,7 +203,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
[cases.test_incompat_wcompat_overflow]
|
||||
@@ -217,7 +217,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR_CAT(
|
||||
LFSR_TAG_WCOMPAT, 0,
|
||||
@@ -226,7 +226,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
[cases.test_incompat_ocompat_overflow]
|
||||
@@ -240,7 +240,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR_CAT(
|
||||
LFSR_TAG_OCOMPAT, 0,
|
||||
@@ -249,7 +249,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should _not_ fail, ocompat should always be ignored
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
@@ -266,7 +266,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_GEOMETRY, 0,
|
||||
@@ -276,7 +276,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount after incompatible block counts
|
||||
@@ -292,7 +292,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_GEOMETRY, 0,
|
||||
@@ -302,7 +302,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount after incompatible name limit
|
||||
@@ -318,7 +318,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_NAMELIMIT, 0,
|
||||
@@ -326,7 +326,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test that we fail to mount after incompatible file limit
|
||||
@@ -341,7 +341,7 @@ code = '''
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR_CAT(
|
||||
LFSR_TAG_FILELIMIT, 0,
|
||||
@@ -354,7 +354,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test what happens if we find an unknown config
|
||||
@@ -366,7 +366,7 @@ code = '''
|
||||
lfsr_format(&lfs, CFG) => 0;
|
||||
|
||||
// create an unknown config
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_ATTRS(
|
||||
LFSR_ATTR(
|
||||
LFSR_TAG_CONFIG + 0x13, 0,
|
||||
@@ -374,7 +374,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# test what happens if we find an unknown file type
|
||||
@@ -386,7 +386,7 @@ code = '''
|
||||
lfsr_format(&lfs, CFG) => 0;
|
||||
|
||||
// create some files
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_file_t file;
|
||||
lfsr_file_open(&lfs, &file, "a",
|
||||
LFS_O_WRONLY | LFS_O_CREAT | LFS_O_EXCL) => 0;
|
||||
@@ -406,7 +406,7 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// change a file's type to something unknown
|
||||
lfsr_mount(&lfs, CFG) => 0;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
lfsr_mdir_t mdir;
|
||||
lfsr_did_t did;
|
||||
const char *name;
|
||||
@@ -421,5 +421,5 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
Reference in New Issue
Block a user