diff options
author | Christopher Haster <chaster@utexas.edu> | 2019-05-22 01:21:52 +0300 |
---|---|---|
committer | Christopher Haster <chaster@utexas.edu> | 2019-05-24 00:42:47 +0300 |
commit | 9899c7fe486d4a581fb84ecf832a574896d411b7 (patch) | |
tree | eb1fdf66049a6ac6cf93034319bbd6824b032ec3 | |
parent | bc7bed740b211fec03bc3202f778f0dfa71a54a3 (diff) |
Fixed read cache amount based on hint and offset
Found by apmorton
-rw-r--r-- | lfs.c | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -84,9 +84,12 @@ static int lfs_bd_read(lfs_t *lfs, LFS_ASSERT(block < lfs->cfg->block_count); rcache->block = block; rcache->off = lfs_aligndown(off, lfs->cfg->read_size); - rcache->size = lfs_min(lfs_alignup(off+hint, lfs->cfg->read_size), - lfs_min(lfs->cfg->block_size - rcache->off, - lfs->cfg->cache_size)); + rcache->size = lfs_min( + lfs_min( + 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, rcache->off, rcache->buffer, rcache->size); if (err) { |