Move lookahead buffer offset at the first free block if such block doesn't exist move it for whole lookahead size.

This commit is contained in:
ondrap 2023-08-29 12:50:16 +02:00 committed by Christopher Haster
parent b637379210
commit d85a0fe2e2
1 changed files with 3 additions and 1 deletions

4
lfs.c
View File

@ -662,7 +662,9 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
}
int lfs_find_free_blocks(lfs_t *lfs){
lfs->free.off = (lfs->free.off + lfs->free.size)
// Move free offset at the first unused block (lfs->free.i)
// lfs->free.i is equal lfs->free.size when all blocks are used
lfs->free.off = (lfs->free.off + lfs->free.i)
% lfs->block_count;
lfs->free.size = lfs_min(8*lfs->cfg->lookahead_size, lfs->free.ack);
lfs->free.i = 0;