Fixed lookahead overflow and removed unbounded lookahead pointers

As pointed out by davidefer, the lookahead pointer modular arithmetic
does not work around integer overflow when the pointer size is not a
multiple of the block count.

To avoid overflow problems, the easy solution is to stop trying to
work around integer overflows and keep the lookahead offset inside the
block device. To make this work, the ack was modified into a resetable
counter that is decremented every block allocation.

As a plus, quite a bit of the allocation logic ended up simplified.
This commit is contained in:
Christopher Haster
2018-04-10 15:14:27 -05:00
parent 89a7630d84
commit 9637b96069
2 changed files with 24 additions and 23 deletions

4
lfs.h
View File

@@ -259,9 +259,9 @@ typedef struct lfs_superblock {
} lfs_superblock_t;
typedef struct lfs_free {
lfs_block_t begin;
lfs_block_t size;
lfs_block_t off;
lfs_block_t size;
lfs_block_t i;
lfs_block_t ack;
uint32_t *buffer;
} lfs_free_t;