Explorar el Código

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 hace 5 años
padre
commit
5783eea0de
Se han modificado 1 ficheros con 6 adiciones y 2 borrados
  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);