From a1138a41ce1a16b1113acb036b7049ca6263b900 Mon Sep 17 00:00:00 2001 From: Christopher Haster Date: Sun, 25 Jun 2017 16:21:14 -0500 Subject: [PATCH] Fixed dirty rcache during directory commit An interesting side-effect of adding internal checks to the littlefs for block errors, is that the littlefs starts to cover up its own flaws. Probably out of embarrassment. In this case, the relocation logic for directories left the littlefs rcache dirty with invalid data. The littlefs detected the error, treated it as a corrupted write, and just moved the "corrupted" block to a new block, which as a side-effect flushes the rcache. Since committing a dir will end up flushing the rcache to check for errors anyways, we can just drop the rcache in lfs_bd_sync. --- lfs.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lfs.c b/lfs.c index 4cad04c..aa40eec 100644 --- a/lfs.c +++ b/lfs.c @@ -237,6 +237,8 @@ static int lfs_bd_erase(lfs_t *lfs, lfs_block_t block) { } static int lfs_bd_sync(lfs_t *lfs) { + lfs->rcache.block = 0xffffffff; + int err = lfs_cache_flush(lfs, &lfs->pcache, NULL); if (err) { return err;