Skip to content

Commit 3f31c8c

Browse files
committed
Fixed corner case with immediate exhaustion and lookahead==block_count
The previous math for determining if we scanned all of disk wasn't set up correctly in the lfs_mount function. If lookahead == block_count the lfs_alloc function would think we had already searched the entire disk. This is only an issue if we manage to exhaust a block on the first pass after mount, since lfs_alloc_ack resets the lookahead region into a valid state after a succesful block allocation.
1 parent f4aeb83 commit 3f31c8c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

lfs.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -1922,7 +1922,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
19221922
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
19231923
lfs->free.begin = 0;
19241924
lfs->free.off = 0;
1925-
lfs->free.end = lfs->free.begin + lfs->cfg->block_count;
1925+
lfs->free.end = lfs->free.begin + lfs->free.off + lfs->cfg->block_count;
19261926

19271927
// create superblock dir
19281928
lfs_alloc_ack(lfs);
@@ -2000,7 +2000,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
20002000
// setup free lookahead
20012001
lfs->free.begin = -lfs->cfg->lookahead;
20022002
lfs->free.off = lfs->cfg->lookahead;
2003-
lfs->free.end = lfs->free.begin + lfs->cfg->block_count;
2003+
lfs->free.end = lfs->free.begin + lfs->free.off + lfs->cfg->block_count;
20042004

20052005
// load superblock
20062006
lfs_dir_t dir;

0 commit comments

Comments
 (0)