PeachOS icon indicating copy to clipboard operation
PeachOS copied to clipboard

Error in fat16.c in function fat16_read

Open JaihsonK opened this issue 3 years ago • 1 comments

Hey Dan! Correct me if i am wrong, but I believe there is an error in fat16_read. We never advance fat_desc->pos, thus in a situation such that we would read from a file multiple times, we would read and re-read the same data in the file. The following program when inserted into the function kernel_main will demonstrate the problem: int fd = fopen("0:/hello.txt", "r"); for(int i = 0; i < 5; i++) { char buf [11]; fread(buf, 10, 1, fd); print(buf); } while(1);

my solution is to insert into fat16_read at line 716 in the PeachOS master: fat_desc->pos = offset;

thanks!

Jaihson

JaihsonK avatar Jan 01 '23 21:01 JaihsonK

Hi Jaihson, That is a good spot, you are correct. Whilst we ensure the whole buffer you request is loaded via incrementing the offset variable, we fail to reset the position to the new offset.

Thanks for sharing, I will close the issue when a new lecture is made fixing it

nibblebits avatar Jan 03 '23 19:01 nibblebits