Skip to content

Commit d85a0fe

Browse files
ondrapCZEgeky
authored andcommitted
Move lookahead buffer offset at the first free block if such block doesn't exist move it for whole lookahead size.
1 parent b637379 commit d85a0fe

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lfs.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -662,7 +662,9 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
662662
}
663663

664664
int lfs_find_free_blocks(lfs_t *lfs){
665-
lfs->free.off = (lfs->free.off + lfs->free.size)
665+
// Move free offset at the first unused block (lfs->free.i)
666+
// lfs->free.i is equal lfs->free.size when all blocks are used
667+
lfs->free.off = (lfs->free.off + lfs->free.i)
666668
% lfs->block_count;
667669
lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size, lfs->free.ack);
668670
lfs->free.i = 0;

0 commit comments

Comments
 (0)