diff --git a/fs/fat32/fat32.c b/fs/fat32/fat32.c index 7c9fdeb..cf19b6e 100644 --- a/fs/fat32/fat32.c +++ b/fs/fat32/fat32.c @@ -487,7 +487,7 @@ uint32_t fat32_read_file_random_access(const Fat32_CtrlBlock *ctrl, const Fat32_ // reading from a file may involve reading across cluster boundaries // 1. read the beginning from the first cluster - uint32_t first_read_len = MIN(read_len, ctrl->bytes_per_sector - pos); + uint32_t first_read_len = MIN(read_len, ctrl->bytes_per_sector - pos_in_sector); memcpy(p, buffer + pos_in_sector, first_read_len); read_len -= first_read_len; // decrease the total read len with the number of bytes read from the first sector of the file offset += first_read_len; // advance offset @@ -619,7 +619,7 @@ uint32_t fat32_read_file_stream(const Fat32_CtrlBlock *ctrl, Fat32_FileHelper *f // reading from a file may involve reading across cluster boundaries // 1. read the beginning from the first cluster - uint32_t first_read_len = MIN(read_len, ctrl->bytes_per_sector - seek_hint->pos); + uint32_t first_read_len = MIN(read_len, ctrl->bytes_per_sector - pos_in_sector); memcpy(p, buffer + pos_in_sector, first_read_len); read_len -= first_read_len; // decrease the total read len with the number of bytes read from the first sector of the file offset += first_read_len; // advance offset