(bugfix) adding line function to clear out all the global 'free' information so that we can reset it after a failed traversal

This commit is contained in:
Derek Thrasher
2020-03-24 09:22:05 -04:00
committed by Christopher Haster
parent 4677421aba
commit d498b9fb31

18
lfs.c
View File

@@ -10,6 +10,8 @@
#define LFS_BLOCK_NULL ((lfs_block_t)-1) #define LFS_BLOCK_NULL ((lfs_block_t)-1)
#define LFS_BLOCK_INLINE ((lfs_block_t)-2) #define LFS_BLOCK_INLINE ((lfs_block_t)-2)
static void lfs_alloc_ack(lfs_t *lfs);
/// Caching block device operations /// /// Caching block device operations ///
static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) { static inline void lfs_cache_drop(lfs_t *lfs, lfs_cache_t *rcache) {
// do not zero, cheaper if cache is readonly or only going to be // do not zero, cheaper if cache is readonly or only going to be
@@ -24,6 +26,15 @@ static inline void lfs_cache_zero(lfs_t *lfs, lfs_cache_t *pcache) {
pcache->block = LFS_BLOCK_NULL; pcache->block = LFS_BLOCK_NULL;
} }
/// Invalidate the lookahead buffer. This is done during mounting and failed traversals ///
static inline void lfs_setup_invalid_lookahead_buffer(lfs_t *lfs)
{
lfs->free.off = lfs->seed % lfs->cfg->block_size;
lfs->free.size = 0;
lfs->free.i = 0;
lfs_alloc_ack(lfs);
}
static int lfs_bd_read(lfs_t *lfs, static int lfs_bd_read(lfs_t *lfs,
const lfs_cache_t *pcache, lfs_cache_t *rcache, lfs_size_t hint, const lfs_cache_t *pcache, lfs_cache_t *rcache, lfs_size_t hint,
lfs_block_t block, lfs_off_t off, lfs_block_t block, lfs_off_t off,
@@ -477,6 +488,7 @@ static int lfs_alloc(lfs_t *lfs, lfs_block_t *block) {
memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size); memset(lfs->free.buffer, 0, lfs->cfg->lookahead_size);
int err = lfs_fs_traverseraw(lfs, lfs_alloc_lookahead, lfs, true); int err = lfs_fs_traverseraw(lfs, lfs_alloc_lookahead, lfs, true);
if (err) { if (err) {
lfs_setup_invalid_lookahead_buffer(lfs);
return err; return err;
} }
} }
@@ -3772,10 +3784,7 @@ int lfs_mount(lfs_t *lfs, const struct lfs_config *cfg) {
lfs->gdisk = lfs->gstate; lfs->gdisk = lfs->gstate;
// setup free lookahead // setup free lookahead
lfs->free.off = lfs->seed % lfs->cfg->block_size; lfs_setup_invalid_lookahead_buffer(lfs);
lfs->free.size = 0;
lfs->free.i = 0;
lfs_alloc_ack(lfs);
LFS_TRACE("lfs_mount -> %d", 0); LFS_TRACE("lfs_mount -> %d", 0);
return 0; return 0;
@@ -4594,6 +4603,7 @@ static int lfs1_mount(lfs_t *lfs, struct lfs1 *lfs1,
lfs->lfs1->root[1] = LFS_BLOCK_NULL; lfs->lfs1->root[1] = LFS_BLOCK_NULL;
// setup free lookahead // setup free lookahead
// TODO should this also call lfs_setup_invalid_lookahead_buffer(lfs); the free.off is different in the current version of lfs
lfs->free.off = 0; lfs->free.off = 0;
lfs->free.size = 0; lfs->free.size = 0;
lfs->free.i = 0; lfs->free.i = 0;