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

Fix allocation-eviction issue when erase state is multiple of block_cycles+1
This commit is contained in:
Christopher Haster
2020-12-04 00:49:09 -06:00
committed by GitHub

8
lfs.c
View File

@@ -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);