Fixed issue with rcache going out-of-date when overlapping pcache

This was a inter-abstraction-layer assumption that won't hold true with
the rbyd blocks.

The whole caching layer probably deserves a rewrite at this point.
This commit is contained in:
Christopher Haster
2022-12-26 22:55:05 -06:00
parent b03420ccfc
commit 471f12c79a
2 changed files with 132 additions and 122 deletions
+10
View File
@@ -253,6 +253,16 @@ static int lfs_bd_prog(lfs_t *lfs,
LFS_ASSERT(block == LFS_BLOCK_INLINE || block < lfs->cfg->block_count);
LFS_ASSERT(off + size <= lfs->cfg->block_size);
// update rcache if we overlap
if (rcache
&& block == rcache->block
&& off < rcache->off + rcache->size
&& off + size > rcache->off) {
lfs_off_t off_ = lfs_max(off, rcache->off);
lfs_size_t size_ = lfs_min(size, rcache->size - (off_-rcache->off));
memcpy(&rcache->buffer[off_-rcache->off], data+(off_-off), size_);
}
while (size > 0) {
if (block == pcache->block &&
off >= pcache->off &&