From af6ea39ccab9fab214655708d82887e011e2564b Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Thu, 9 Jan 2025 18:23:55 -0600 Subject: [PATCH] Reworked rcompat flags Mainly to add LFS_RCOMPAT_MSPROUT. It makes sense that a littlefs driver may not want to support mroot-inlined mdirs, and this flag would be the only way to indicate that. (Currently inlined mdir -> mtree is one way, but this may not always be the case.) This also makes space for a couple planned features: LFS_RCOMPAT_NONSTANDARD 0x00000001 Non-standard filesystem format LFS_RCOMPAT_WRONLY* 0x00000002 Reading is disallowed LFS_RCOMPAT_GRM 0x00000004 May use a global-remove LFS_RCOMPAT_MSPROUT 0x00000010 May use an inlined mdir LFS_RCOMPAT_MLEAF 0x00000020 May use a single mdir pointer LFS_RCOMPAT_MSHRUB 0x00000040 May use an inlined mtree LFS_RCOMPAT_MTREE 0x00000080 May use an mdir btree LFS_RCOMPAT_BSPROUT 0x00000100 Files may use inlined data LFS_RCOMPAT_BLEAF 0x00000200 Files may use single block pointers LFS_RCOMPAT_BSHRUB 0x00000400 Files may use inlined btrees LFS_RCOMPAT_BTREE 0x00000800 Files may use btrees *Planned I've gone ahead and included rcompat flags we reserve but don't currently use (LFS_RCOMPAT_MSHRUB). It seems like a good idea to make these reservations explicit. Though we should still prohibit their use until there is a good reason, in case we want to repurpose these flags in the future. Code changes minimal (larger literal? compiler noise?): code stack ctx before: 37788 2608 620 after: 37792 (+0.0%) 2608 (+0.0%) 620 (+0.0%) --- lfs.c | 23 +++++++++++++---------- scripts/dbgflags.py | 16 +++++++++------- 2 files changed, 22 insertions(+), 17 deletions(-) diff --git a/lfs.c b/lfs.c index 05d20db6..ba7c6ae3 100644 --- a/lfs.c +++ b/lfs.c @@ -13393,25 +13393,28 @@ static int lfs_deinit(lfs_t *lfs) { // enum lfsr_rcompat { LFSR_RCOMPAT_NONSTANDARD = 0x0001, // Non-standard filesystem format - LFSR_RCOMPAT_MLEAF = 0x0002, // May use a single mdir pointer - LFSR_RCOMPAT_MTREE = 0x0008, // May use an mtree - LFSR_RCOMPAT_BSPROUT = 0x0010, // Files may use inlined data - LFSR_RCOMPAT_BLEAF = 0x0020, // Files may use single block pointers - LFSR_RCOMPAT_BSHRUB = 0x0040, // Files may use inlined btrees - LFSR_RCOMPAT_BTREE = 0x0080, // Files may use btrees - LFSR_RCOMPAT_GRM = 0x0100, // May use a global-remove + LFSR_RCOMPAT_GRM = 0x0004, // May use a global-remove + LFSR_RCOMPAT_MSPROUT = 0x0010, // May use an inlined mdir + LFSR_RCOMPAT_MLEAF = 0x0020, // May use a single mdir pointer + LFSR_RCOMPAT_MSHRUB = 0x0040, // May use an inlined mtree + LFSR_RCOMPAT_MTREE = 0x0080, // May use an mtree + LFSR_RCOMPAT_BSPROUT = 0x0100, // Files may use inlined data + LFSR_RCOMPAT_BLEAF = 0x0200, // Files may use single block pointers + LFSR_RCOMPAT_BSHRUB = 0x0400, // Files may use inlined btrees + LFSR_RCOMPAT_BTREE = 0x0800, // Files may use btrees // internal LFSR_rcompat_OVERFLOW = 0x8000, // Can't represent all flags }; #define LFSR_RCOMPAT_COMPAT \ - (LFSR_RCOMPAT_MLEAF \ + (LFSR_RCOMPAT_GRM \ + | LFSR_RCOMPAT_MSPROUT \ + | LFSR_RCOMPAT_MLEAF \ | LFSR_RCOMPAT_MTREE \ | LFSR_RCOMPAT_BSPROUT \ | LFSR_RCOMPAT_BLEAF \ | LFSR_RCOMPAT_BSHRUB \ - | LFSR_RCOMPAT_BTREE \ - | LFSR_RCOMPAT_GRM) + | LFSR_RCOMPAT_BTREE) enum lfsr_wcompat { LFSR_WCOMPAT_NONSTANDARD = 0x0001, // Non-standard filesystem format diff --git a/scripts/dbgflags.py b/scripts/dbgflags.py index cfd8d1af..720df81a 100755 --- a/scripts/dbgflags.py +++ b/scripts/dbgflags.py @@ -149,13 +149,15 @@ FLAGS = [ # Read-compat flags ('RCOMPAT', 'NONSTANDARD', 0x0001, "Non-standard filesystem format" ), - ('RCOMPAT', 'MLEAF', 0x0002, "May use a single mdir pointer" ), - ('RCOMPAT', 'MTREE', 0x0008, "May use an mdir btree" ), - ('RCOMPAT', 'BSPROUT', 0x0010, "Files may use inlined data" ), - ('RCOMPAT', 'BLEAF', 0x0020, "Files may use single block pointers" ), - ('RCOMPAT', 'BSHRUB', 0x0040, "Files may use inlined btrees" ), - ('RCOMPAT', 'BTREE', 0x0080, "Files may use btrees" ), - ('RCOMPAT', 'GRM', 0x0100, "May use a global-remove" ), + ('RCOMPAT', 'GRM', 0x0004, "May use a global-remove" ), + ('RCOMPAT', 'MSPROUT', 0x0010, "May use an inlined mdir" ), + ('RCOMPAT', 'MLEAF', 0x0020, "May use a single mdir pointer" ), + ('RCOMPAT', 'MSHRUB', 0x0040, "May use an inlined mtree" ), + ('RCOMPAT', 'MTREE', 0x0080, "May use an mdir btree" ), + ('RCOMPAT', 'BSPROUT', 0x0100, "Files may use inlined data" ), + ('RCOMPAT', 'BLEAF', 0x0200, "Files may use single block pointers" ), + ('RCOMPAT', 'BSHRUB', 0x0400, "Files may use inlined btrees" ), + ('RCOMPAT', 'BTREE', 0x0800, "Files may use btrees" ), ('rcompat', 'OVERFLOW',0x8000, "Can't represent all flags" ),