Browse Source

Moved dir->count check before commit, limited to < 0xff

This matches the logic originally implemented in 48bd2bf, which was lost
during the big no-recursion refactor 84da4c0.

Other notes:

- Checking >= 0xff matches the split logic during compaction (line
  2158):

    end - split < 0xff

- Grouping dir->erased || dir->count >= 0xff together makes it clear
  these share a common code path.

- Checking for dir->count >= 0xff early avoids committing >8-bit ids to
  disk.

  The cat may already be out-of-the bag on this one, but opening the id
  space up to the full 10-bits should probably be on a non-patch
  release.

Found by dschendt
Christopher Haster 2 months ago
parent
commit
f24ff9fb25
1 changed files with 1 additions and 5 deletions
  1. 1 5
      lfs.c

+ 1 - 5
lfs.c

@@ -2264,7 +2264,7 @@ static int lfs_dir_relocatingcommit(lfs_t *lfs, lfs_mdir_t *dir,
         }
     }
 
-    if (dir->erased) {
+    if (dir->erased || dir->count >= 0xff) {
         // try to commit
         struct lfs_commit commit = {
             .block = dir->pair[0],
@@ -2333,10 +2333,6 @@ static int lfs_dir_relocatingcommit(lfs_t *lfs, lfs_mdir_t *dir,
         lfs->gdisk = lfs->gstate;
         lfs->gdelta = (lfs_gstate_t){0};
 
-        if(dir->count == 0x3ff)
-        {
-            goto compact;
-        }
         goto fixmlist;
     }