From 5a12c443b892b7b35d770db59da71a2cbb73ce91 Mon Sep 17 00:00:00 2001 From: Freddie Chopin Date: Fri, 9 Aug 2019 23:02:33 +0200 Subject: [PATCH] Revert "Don't bypass cache in `lfs_cache_prog()` and `lfs_cache_read()`" This reverts commit fdd239fe21a3721dc7fb55a9cf816544af7e9647. Bypassing cache turned out to be a mistake which causes more problems than it solves. Device driver should deal with alignment if this is required - trying to do that in a file system is not a viable solution anyway. --- lfs.c | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lfs.c b/lfs.c index b10c186..a96f327 100644 --- a/lfs.c +++ b/lfs.c @@ -71,6 +71,21 @@ static int lfs_bd_read(lfs_t *lfs, diff = lfs_min(diff, rcache->off-off); } + if (size >= hint && off % lfs->cfg->read_size == 0 && + size >= lfs->cfg->read_size) { + // bypass cache? + diff = lfs_aligndown(diff, lfs->cfg->read_size); + int err = lfs->cfg->read(lfs->cfg, block, off, data, diff); + if (err) { + return err; + } + + data += diff; + off += diff; + size -= diff; + continue; + } + // load to cache, first condition can no longer fail LFS_ASSERT(block < lfs->cfg->block_count); rcache->block = block;