From d85a0fe2e2f1a2c48d80b05a29c3c60a28c7e3b0 Mon Sep 17 00:00:00 2001 From: ondrap Date: Tue, 29 Aug 2023 12:50:16 +0200 Subject: [PATCH] Move lookahead buffer offset at the first free block if such block doesn't exist move it for whole lookahead size. --- lfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lfs.c b/lfs.c index 250e7346..3664e801 100644 --- a/lfs.c +++ b/lfs.c @@ -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;