Added LFS_WCOMPAT_RDONLY and LFS_RCOMPAT_WRONLY
LFS_WCOMPAT_RDONLY seems generally useful for tools that just want to mark a filesystem is read-only. This is a common flag that exists in other filesystems (RO_COMPAT_READONLY in ext4 for example). LFS_RCOMPAT_WRONLY, on the other hand, is a bit more of a joke, but there could be some niche use cases for it (preventing double mounts?). Fortunately, these flags require no extra code, and fall out naturally from our wcompat/rcompat handling. --- Originally, the idea was to also add LFS_F_RDONLY, to match LFS_M_RDONLY and set the LFS_WCOMPAT_RDONLY flag during format. But this doesn't really work with the current API, since lfsr_format would just give you an empty filesystem you can't write to. Which is a bit silly. Maybe we should add something like lfsr_fs_mkrdonly in the future? This is probably low-priority.
This commit is contained in:
@@ -716,6 +716,65 @@ code = '''
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# test that we fail to mount rdonly images
|
||||
[cases.test_mount_incompat_rdonly]
|
||||
in = 'lfs.c'
|
||||
code = '''
|
||||
// create a superblock
|
||||
lfs_t lfs;
|
||||
lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0;
|
||||
|
||||
// set the rdonly flag, this prevents writing from a littlefs image
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
uint8_t wcompat_buf[LFSR_WCOMPAT_DSIZE];
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
|
||||
LFSR_RAT(
|
||||
LFSR_TAG_WCOMPAT, 0,
|
||||
LFSR_DATA_WCOMPAT(
|
||||
LFSR_WCOMPAT_COMPAT
|
||||
| LFSR_WCOMPAT_RDONLY,
|
||||
wcompat_buf)))) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
|
||||
// but we _can_ mount readonly
|
||||
lfsr_mount(&lfs, LFS_M_RDONLY, CFG) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
'''
|
||||
|
||||
# test that we fail to mount wronly images
|
||||
[cases.test_mount_incompat_wronly]
|
||||
in = 'lfs.c'
|
||||
code = '''
|
||||
// create a superblock
|
||||
lfs_t lfs;
|
||||
lfsr_format(&lfs, LFS_F_RDWR, CFG) => 0;
|
||||
|
||||
// set the wronly flag, this prevents reading from a littlefs image
|
||||
//
|
||||
// note we're messing around with internals to do this! this
|
||||
// is not a user API
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => 0;
|
||||
uint8_t rcompat_buf[LFSR_RCOMPAT_DSIZE];
|
||||
lfsr_mdir_commit(&lfs, &lfs.mroot, LFSR_RATS(
|
||||
LFSR_RAT(
|
||||
LFSR_TAG_RCOMPAT, 0,
|
||||
LFSR_DATA_RCOMPAT(
|
||||
LFSR_RCOMPAT_COMPAT
|
||||
| LFSR_RCOMPAT_WRONLY,
|
||||
rcompat_buf)))) => 0;
|
||||
lfsr_unmount(&lfs) => 0;
|
||||
|
||||
// mount should now fail
|
||||
lfsr_mount(&lfs, LFS_M_RDWR, CFG) => LFS_ERR_NOTSUP;
|
||||
lfsr_mount(&lfs, LFS_M_RDONLY, CFG) => LFS_ERR_NOTSUP;
|
||||
'''
|
||||
|
||||
# these are just a bit harder to detect
|
||||
[cases.test_mount_incompat_rcompat_overflow]
|
||||
defines.OVERFLOW = 72
|
||||
|
||||
Reference in New Issue
Block a user