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:
author田昕 <tianxin7@xiaomi.com>2021-11-30 15:52:29 +0300
committerChristopher Haster <chaster@utexas.edu>2022-03-21 04:53:48 +0300
commit1363c9f9d411e59f8ac8f509e5bf51c2ef5315bd (patch)
treecd55bb1044e9c413a02ddd4f70b0cc94b7593d81 /lfs.c
parentead50807f1ca3fdf2da00b77a0ce02651ded2d13 (diff)
fix bug:lfs_alloc will alloc one block repeatedly in multiple split
BUG CASE:Assume there are 6 blocks in littlefs, block 0,1,2,3 already allocated. 0 has a tail pair of {2, 3}. Now we try to write more into 0. When writing to block 0, we will split(FIRST SPLIT), thus allocate block 4 and 5. Up to now , everything is as expected. Then we will try to commit in block 4, during which split(SECOND SPLIT) is triggered again(In our case, some files are large, some are small, one split may not be enough). Still as expected now. BUG happens when we try to alloc a new block pair for the second split: As lookahead buffer reaches the end , a new lookahead buffer will be generated from flash content, and block 4, 5 are unused blocks in the new lookahead buffer because they are not programed yet. HOWEVER, block 4,5 should be occupied in the first split!!!!! The result is block 4,5 are allocated again(This is where things are getting wrong). commit ce2c01f results in this bug. In the commit, a lfs_alloc_ack is inserted in lfs_dir_split, which will cause split to reset lfs->free.ack to block count. In summary, this problem exists after 2.1.3. Solution: don't call lfs_alloc_ack in lfs_dir_split.
Diffstat (limited to 'lfs.c')
-rw-r--r--lfs.c1
1 files changed, 0 insertions, 1 deletions
diff --git a/lfs.c b/lfs.c
index d976389..dfb2850 100644
--- a/lfs.c
+++ b/lfs.c
@@ -1509,7 +1509,6 @@ static int lfs_dir_split(lfs_t *lfs,
lfs_mdir_t *dir, const struct lfs_mattr *attrs, int attrcount,
lfs_mdir_t *source, uint16_t split, uint16_t end) {
// create tail directory
- lfs_alloc_ack(lfs);
lfs_mdir_t tail;
int err = lfs_dir_alloc(lfs, &tail);
if (err) {