Skip to content

Commit

Permalink
Fixed corner case with immediate exhaustion and lookahead==block_count
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
geky committed Nov 10, 2017
1 parent f4aeb83 commit 3f31c8c
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -1922,7 +1922,7 @@ int lfs_format(lfs_t *lfs, const struct lfs_config *cfg) {
memset(lfs->free.buffer, 0, lfs->cfg->lookahead/8);
lfs->free.begin = 0;
lfs->free.off = 0;
lfs->free.end = lfs->free.begin + lfs->cfg->block_count;
lfs->free.end = lfs->free.begin + lfs->free.off + lfs->cfg->block_count;

// create superblock dir
lfs_alloc_ack(lfs);
Expand Down Expand Up @@ -2000,7 +2000,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
// setup free lookahead
lfs->free.begin = -lfs->cfg->lookahead;
lfs->free.off = lfs->cfg->lookahead;
lfs->free.end = lfs->free.begin + lfs->cfg->block_count;
lfs->free.end = lfs->free.begin + lfs->free.off + lfs->cfg->block_count;

// load superblock
lfs_dir_t dir;
Expand Down

0 comments on commit 3f31c8c

Please sign in to comment.