From 3611799fe9dbeb93a165dc24827ac63b52e26420 Mon Sep 17 00:00:00 2001 From: Gyorgy Szombathelyi Date: Tue, 8 Jan 2019 17:24:44 +0100 Subject: [PATCH] Don't read-ahead beyond the file Somewhat affects later writes, too --- user_io.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/user_io.c b/user_io.c index ef96a1d..19572d5 100644 --- a/user_io.c +++ b/user_io.c @@ -1162,15 +1162,19 @@ void user_io_poll() { // for the next request already DISKLED_ON; if(sd_image[drive_index].file.size) { - IDXSeek(&sd_image[drive_index], lba+1); - IDXRead(&sd_image[drive_index], buffer); + // but check if it would overrun on the file + if(((sd_image[drive_index].file.size-1) >> 9) > lba) { + IDXSeek(&sd_image[drive_index], lba+1); + IDXRead(&sd_image[drive_index], buffer); + buffer_lba = lba + 1; + } } else { // sector read // read sector from sd card if it is not already present in // the buffer MMC_Read(lba+1, buffer); + buffer_lba = lba+1; } - buffer_lba = lba+1; buffer_drive_index = drive_index; DISKLED_OFF; }