
Adrian Filipi wrote:
It looks like fat.c is not handling the case where the sectors/cluster is 1, and the rood directory spans multiple clusters.
In my case I was getting garbage directory info after the invalid fat error. The attached patch stops the code from rolling past the end of cluster.
I was also getting these garbage directory entries which appeared to be file nodes being interpreted as directory nodes.
I can confirm that Adrian's patch fixes this particular problem for FAT32. Now, on FAT32, whatever files are displayed by fatls are also readable by fatload. As Adrian mentions below, the files not displayed by fatls are completely inaccessible to the current fat.c with or without Adrian's patch.
FAT16 also suffered from this "garbage" problem when there were 512 files, but the patch also fixes this. (If there is a volume name, it should use one of the root directory entries, leaving only 511 directory entries for files; otherwise, the lack/presence of a volume name probably has no effect on FAT16.)
It looks like a loop to walk the allocation chain is necessary. I think get_contents() does all the right work, but it of course starts with a directory entry, which we don't have yet for /. A little refactoring might do the trick.
Of course this only applies to FAT32. Adrian's patch appears to have fixed the only issue with FAT16 that I'm aware of.
Time permitting, I will try to fix this remaining problem myself. Adrian, thanks for your insight into the problem and a potential solution.
Sincerely,
Ken Fuchs