nibblebits / PeachOS

Simple kernel designed for a online course
GNU General Public License v2.0
133 stars 55 forks source link

Error in fat16.c in function fat16_read #14

Open JaihsonK opened 1 year ago

JaihsonK commented 1 year ago

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

nibblebits commented 1 year ago

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