ck: Merged FSCK+CK -> CK flag namespace

Unintentionally arriving at the infamous "fsck" name is a bit funny.

But it's probably something we don't want to conflict with if we can
help it, on the off chance we want a sort of lfs3_fsck function in the
future. (This is all hypothetical, but lfs3_fsck may expect an unmounted
filesystem, and have a much larger scope than lfs3_fs_ck. Though typing
this out now I'm realizing how confusing that might be...)

Since lfs3_file_ck and lfs3_fs_ck share a subset of flags, it's not
_entirely_ unreasonable for lfs3_file_ck and lfs3_fs_ck to share the
same namespace.

There's a risk of confusing users around what flags lfs3_file_ck
accepts, but we have asserts, and said flags (LFS3_CK_MKCONSISTENT,
LFS3_CK_LOOKAHEAD, etc) just don't really make sense in lfs3_file_ck:

  fs file
  y     LFS3_CK_MKCONSISTENT 0x00000800  Make the filesystem consistent
  y     LFS3_CK_LOOKAHEAD    0x00001000  Repopulate lookahead buffer
  y     LFS3_CK_LOOKGBMAP    0x00002000  Repopulate the gbmap
  y     LFS3_CK_PREERASE*    0x00004000  Pre-erase unused blocks
  y     LFS3_CK_COMPACTMETA  0x00008000  Compact metadata logs
  y  y  LFS3_CK_CKMETA       0x00010000  Check metadata checksums
  y  y  LFS3_CK_CKDATA       0x00020000  Check metadata + data checksums
  y  y  LFS3_CK_REPAIRMETA*  0x00040000  Repair data blocks
  y  y  LFS3_CK_REPAIRDATA*  0x00080000  Repair metadata + data blocks

  * Planned

Another option would be to document that lfs3_fs_ck accepts both
LFS3_CK_* _and_ LFS3_GC_* flags, but I worry that would be more
confusing. It would also lock us into supporting all LFs3_GC_* flags in
lfs3_fs_ck, which may not always be the case.

Though this is an argument for doing away with the whole
LFS3_M/F/CK/GC/I_* duplication... (tbh another reason for this is to
reduce the number of namespaces by at least one).

No code changes.
This commit is contained in:
Christopher Haster
2025-11-16 00:39:24 -06:00
parent 5c0cebb00b
commit c16c4a00d3
5 changed files with 53 additions and 74 deletions
+17 -10
View File
@@ -12402,8 +12402,13 @@ int lfs3_file_opencfg_(lfs3_t *lfs3, lfs3_file_t *file,
lfs3_handle_open(lfs3, &file->b.h);
// check metadata/data for errors?
if (file->b.h.flags & LFS3_CK_ALL) {
err = lfs3_file_ck(lfs3, file, file->b.h.flags & LFS3_CK_ALL);
if (file->b.h.flags & (
LFS3_CK_CKMETA
| LFS3_CK_CKDATA)) {
err = lfs3_file_ck(lfs3, file,
file->b.h.flags & (
LFS3_CK_CKMETA
| LFS3_CK_CKDATA));
if (err) {
lfs3_handle_close(lfs3, &file->b.h);
goto failed;
@@ -14537,8 +14542,10 @@ int lfs3_file_ck(lfs3_t *lfs3, lfs3_file_t *file, uint32_t flags) {
LFS3_ASSERT(lfs3_handle_isopen(lfs3, &file->b.h));
// can't read from writeonly files
LFS3_ASSERT(!lfs3_o_iswronly(file->b.h.flags));
// unknown ck flags?
LFS3_ASSERT((flags & ~LFS3_CK_ALL) == 0);
// unknown ck flags? note only some ck flags work on files
LFS3_ASSERT((flags & ~(
LFS3_CK_CKMETA
| LFS3_CK_CKDATA)) == 0);
// validate ungrafted data block?
if (lfs3_t_isckdata(flags)
@@ -15659,8 +15666,8 @@ int lfs3_mount(lfs3_t *lfs3, uint32_t flags,
}
// run gc if requested
if (flags & LFS3_FSCK_ALL) {
err = lfs3_fs_ck(lfs3, flags & LFS3_FSCK_ALL);
if (flags & LFS3_GC_ALL) {
err = lfs3_fs_ck(lfs3, flags & LFS3_GC_ALL);
if (err) {
goto failed;
}
@@ -15961,8 +15968,8 @@ int lfs3_format(lfs3_t *lfs3, uint32_t flags,
}
// run gc if requested
if (flags & LFS3_FSCK_ALL) {
err = lfs3_fs_ck(lfs3, flags & LFS3_FSCK_ALL);
if (flags & LFS3_GC_ALL) {
err = lfs3_fs_ck(lfs3, flags & LFS3_GC_ALL);
if (err) {
goto failed;
}
@@ -16305,7 +16312,7 @@ static int lfs3_fs_gc_(lfs3_t *lfs3, lfs3_mgc_t *mgc,
// this just calls lfs3_fs_gc_ with unbounded steps
int lfs3_fs_ck(lfs3_t *lfs3, uint32_t flags) {
// unknown ck flags?
LFS3_ASSERT((flags & ~LFS3_FSCK_ALL) == 0);
LFS3_ASSERT((flags & ~LFS3_GC_ALL) == 0);
// these flags require a writable filesystem
LFS3_ASSERT(!lfs3_m_isrdonly(lfs3->flags)
|| !lfs3_t_ismkconsistent(flags));
@@ -16354,7 +16361,7 @@ int lfs3_fs_gc(lfs3_t *lfs3) {
// unperform janitorial work
int lfs3_fs_unck(lfs3_t *lfs3, uint32_t flags) {
// unknown flags?
LFS3_ASSERT((flags & ~LFS3_FSCK_ALL) == 0);
LFS3_ASSERT((flags & ~LFS3_GC_ALL) == 0);
// reset the requested flags
lfs3->flags |= flags;