volume: Fix bug where reads close to the end of drive may fail

This commit is contained in:
mintsuki 2021-12-24 00:19:24 +01:00
parent e70f48c978
commit 5b3dab3036
1 changed files with 6 additions and 3 deletions

View File

@ -32,10 +32,13 @@ static bool cache_block(struct volume *volume, uint64_t block) {
size_t first_sect = volume->first_sect / (volume->sector_size / 512);
if (!disk_read_sectors(volume, volume->cache,
uint64_t xfer_size = volume->fastest_xfer_size;
while (!disk_read_sectors(volume, volume->cache,
first_sect + block * volume->fastest_xfer_size,
volume->fastest_xfer_size))
return false;
xfer_size)) {
xfer_size--;
}
volume->cache_status = CACHE_READY;
volume->cached_block = block;