ck: Traded ckmeta/ckdata for flag-based ck functions

TLDR: Replaced lfs3_file_ckmeta/ckdata and lfs3_fs_ckmeta/ckdata with
flag based ck functions:

- lfs3_file_ckmeta -> lfs3_file_ck + LFS3_CK_CKMETA
- lfs3_file_ckdata -> lfs3_file_ck + LFS3_CK_CKDATA
- lfs3_fs_ckmeta -> lfs3_fs_ck + LFS3_FSCK_CKMETA
- lfs3_fs_ckdata -> lfs3_fs_ck + LFS3_FSCK_CKDATA

Note lfs3_fs_ck is equivalent to lfs3_fs_gc, but:

1. Performs the work in one call (equivalent to littlefs2's lfs2_fs_gc)
2. Takes flags at call time (like lfs3_mount) instead of cfg time (like
   lfs3_fs_gc)
3. Avoids the constant RAM necessary to track incremental GC state

---

Motivation:

I've been thinking: It's a bit weird that users are able to one-shot
janitorial work in lfs3_mount, but there's no equivalent function after
the filesystem is mounted.

Originally this is what lfs3_fs_gc was for, but after adding support for
incremental GC, it made sense to hide lfs3_fs_gc behind the opt-in
LFS3_GC ifdef due to the extra (ironically non-gc-able) state.

In theory lfs3_trv_t fills a bit of the gap, but, without the internal
i_flag handling and traversal restarts, it's a bit hard to use. And
basically requires duplicating said log, which we need anyways for
lfs3_mount!

So ideally we'd add an explicit one-shot GC function, but now lfs3_fs_gc
is taken.

While thinking about alternative names, I realized we can just call this
lfs3_fs_ck and completely replace lfs3_fs_ckmeta/ckdata.

This has some extra benefits:

- Avoids an explosion of ckmeta/ckdata/repairmeta/repairdata functions
- Discourages redundant traversals that could accomplish more work
- Makes it less confusing that ckdata implies ckmeta

---

I also tweaked lfs3_file_ck to match, but note that lfs3_file_ck is
internally very different from lfs3_fs_ck. For one, lfs3_file_ck only
supports "actual" check flags (LFS3_CK_*) vs all gc flags (LFS3_FSCK_*):

lfs3_file_ck:

  LFS3_CK_CKMETA          0x00010000  Check metadata checksums
  LFS3_CK_CKDATA          0x00020000  Check metadata + data checksums
  LFS3_CK_REPAIRMETA*     0x00040000  Repair metadata blocks
  LFS3_CK_REPAIRDATA*     0x00080000  Repair metadata + data blocks

  * Planned

lfs3_fs_ck:

  LFS3_FSCK_MKCONSISTENT  0x00000800  Make the filesystem consistent
  LFS3_FSCK_LOOKAHEAD     0x00001000  Repopulate lookahead buffer
  LFS3_FSCK_LOOKGBMAP     0x00002000  Repopulate the gbmap
  LFS3_FSCK_PREERASE*     0x00004000  Pre-erase unused blocks
  LFS3_FSCK_COMPACTMETA   0x00008000  Compact metadata logs
  LFS3_FSCK_CKMETA        0x00010000  Check metadata checksums
  LFS3_FSCK_CKDATA        0x00020000  Check metadata + data checksums
  LFS3_FSCK_REPAIRMETA*   0x00040000  Repair metadata blocks
  LFS3_FSCK_REPAIRDATA*   0x00080000  Repair metadata + data blocks

  * Planned

As a plus, this also saves a bit of code:

                 code          stack          ctx
  before:       35968           2280          660
  after:        35924 (-0.1%)   2280 (+0.0%)  660 (+0.0%)

                 code          stack          ctx
  gbmap before: 38828           2296          772
  gbmap after:  38812 (-0.0%)   2296 (+0.0%)  772 (+0.0%)
This commit is contained in:
Christopher Haster
2025-11-15 23:27:25 -06:00
parent ad2e8b3498
commit 5c0cebb00b
5 changed files with 207 additions and 224 deletions
+16
View File
@@ -14,6 +14,8 @@ PREFIX_SEEK = ['--seek'] # Filter by LFS3_SEEK_* flags
PREFIX_A = ['--a', '--attr'] # Filter by LFS3_A_* flags
PREFIX_F = ['--f', '--format'] # Filter by LFS3_F_* flags
PREFIX_M = ['--m', '--mount'] # Filter by LFS3_M_* flags
PREFIX_CK = ['--ck'] # Filter by LFS3_CK_* flags
PREFIX_FSCK = ['--fsck'] # Filter by LFS3_FSCK_* flags
PREFIX_GC = ['--gc'] # Filter by LFS3_GC_* flags
PREFIX_I = ['--i', '--info'] # Filter by LFS3_I_* flags
PREFIX_T = ['--t', '--trv'] # Filter by LFS3_T_* flags
@@ -107,6 +109,20 @@ M_COMPACTMETA = 0x00008000 # y- Compact metadata logs
M_CKMETA = 0x00010000 # y- Check metadata checksums
M_CKDATA = 0x00020000 # y- Check metadata + data checksums
# File check flags
CK_CKMETA = 0x00010000 # -- Check metadata checksums
CK_CKDATA = 0x00020000 # -- Check metadata + data checksums
# Filesystem check flags
FSCK_MKCONSISTENT \
= 0x00000800 # -- Make the filesystem consistent
FSCK_LOOKAHEAD = 0x00001000 # -- Repopulate lookahead buffer
FSCK_LOOKGBMAP = 0x00002000 # -- Repopulate the gbmap
FSCK_COMPACTMETA \
= 0x00008000 # -- Compact metadata logs
FSCK_CKMETA = 0x00010000 # -- Check metadata checksums
FSCK_CKDATA = 0x00020000 # -- Check metadata + data checksums
# GC flags
GC_MKCONSISTENT = 0x00000800 # -- Make the filesystem consistent
GC_LOOKAHEAD = 0x00001000 # -- Repopulate lookahead buffer