Fixed read cache amount based on hint and offset

Found by apmorton
This commit is contained in:
Christopher Haster
2019-05-21 17:21:52 -05:00
parent f35fb8c148
commit c64bf1a17b

9
lfs.c
View File

@@ -84,9 +84,12 @@ static int lfs_bd_read(lfs_t *lfs,
LFS_ASSERT(block < lfs->cfg->block_count); LFS_ASSERT(block < lfs->cfg->block_count);
rcache->block = block; rcache->block = block;
rcache->off = lfs_aligndown(off, lfs->cfg->read_size); rcache->off = lfs_aligndown(off, lfs->cfg->read_size);
rcache->size = lfs_min(lfs_alignup(off+hint, lfs->cfg->read_size), rcache->size = lfs_min(
lfs_min(lfs->cfg->block_size - rcache->off, lfs_min(
lfs->cfg->cache_size)); lfs_alignup(off+hint, lfs->cfg->read_size),
lfs->cfg->block_size)
- rcache->off,
lfs->cfg->cache_size);
int err = lfs->cfg->read(lfs->cfg, rcache->block, int err = lfs->cfg->read(lfs->cfg, rcache->block,
rcache->off, rcache->buffer, rcache->size); rcache->off, rcache->buffer, rcache->size);
if (err) { if (err) {