Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/littlefs-project/littlefs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lfs.c
diff options
context:
space:
mode:
authorChristopher Haster <chaster@utexas.edu>2017-12-27 19:44:40 +0300
committerChristopher Haster <chaster@utexas.edu>2017-12-27 21:59:32 +0300
commit425aa3c6944dc7f52a68d153e9caebf3f861826f (patch)
tree598e964d736a6fbf3b091e2f6e33ebd989e4fe32 /lfs.c
parent5ee20e8d774adf0bb538269870b3552fdfc0e046 (diff)
Fixed issue with immediate exhaustion and small unaligned storage
This was a small hole in the logic that handles initializing the lookahead buffer. To imitate exhaustion (so the block allocator will trigger a scan), the lookahead buffer is rewound a full lookahead and set up to look like it is exhausted. However, unlike normal allocation, this rewind was not kept aligned to a multiple of the scan size, which is limited by both the lookahead buffer and the total storage size. This bug went unnoticed for so long because it only causes problems when the block device is both: 1. Not aligned to the lookahead buffer (not a power of 2) 2. Smaller than the lookahead buffer While this seems like a strange corner case for a block device, this turned out to be very common for internal flash, especially when a handleful of blocks are reserved for code.
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c4
1 files changed, 2 insertions, 2 deletions
diff --git a/lfs.c b/lfs.c
index ea116d2..2d0e331 100644
--- a/lfs.c
+++ b/lfs.c
@@ -2040,8 +2040,8 @@ 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.begin = -lfs_min(lfs->cfg->lookahead, lfs->cfg->block_count);
+ lfs->free.off = -lfs->free.begin;
lfs->free.end = lfs->free.begin + lfs->free.off + lfs->cfg->block_count;
// load superblock