Browse Source

Merge pull request #490 from littlefs-project/fix-alloc-eviction

Fix allocation-eviction issue when erase state is multiple of block_cycles+1
Christopher Haster 5 năm trước cách đây
mục cha
commit
5783eea0de
1 tập tin đã thay đổi với 6 bổ sung2 xóa
  1. 6 2
      lfs.c

+ 6 - 2
lfs.c

@@ -1460,8 +1460,12 @@ static int lfs_dir_alloc(lfs_t *lfs, lfs_mdir_t *dir) {
         return err;
     }
 
-    // make sure we don't immediately evict
-    dir->rev += dir->rev & 1;
+    // to make sure we don't immediately evict, align the new revision count
+    // to our block_cycles modulus, see lfs_dir_compact for why our modulus
+    // is tweaked this way
+    if (lfs->cfg->block_cycles > 0) {
+        dir->rev = lfs_alignup(dir->rev, ((lfs->cfg->block_cycles+1)|1));
+    }
 
     // set defaults
     dir->off = sizeof(dir->rev);