fsrw bug(?): can't open zero-length file
I get error -26 when I use fsrw to open some files of length 0 for writing. This only happens for files created in Windows (via Notepad). If the file was created by fsrw, fsrw opens it no problem.
Also, if I put the SD card into my Windows box and try to copy a zero-length file created by fsrw, I get an error ("The file or directory is corrupted and unreadable").
Apparently, when fsrw creates an empty file, it sets the file's first cluster to $ffff, but when Windows creates an empty file, the first cluster is 0, and fsrw chokes on this (in the freecluster routine).
Right now I'm leaning toward the belief that it's a bug for fsrw to make an empty file's first cluster $ffff and to reject cluster 0 in freecluster, but I'm always ready to be proved wrong.
Perhaps some people can try similar experiments on non-Windows machines.
Also, if I put the SD card into my Windows box and try to copy a zero-length file created by fsrw, I get an error ("The file or directory is corrupted and unreadable").
Apparently, when fsrw creates an empty file, it sets the file's first cluster to $ffff, but when Windows creates an empty file, the first cluster is 0, and fsrw chokes on this (in the freecluster routine).
Right now I'm leaning toward the belief that it's a bug for fsrw to make an empty file's first cluster $ffff and to reject cluster 0 in freecluster, but I'm always ready to be proved wrong.
Perhaps some people can try similar experiments on non-Windows machines.
Comments
I'm not really anywhere I can work on this at the moment.
Is it a real problem at the moment?
Also, $FFFF is a valid end-of-chain indicator. Errors are
before $FFF8.
-tom
Post Edited (rokicki) : 6/8/2009 1:48:31 AM GMT
As for it being a real problem, I guess that depends on how much importance you place on fsrw being compatible with Windows. Sure we're just talking about empty files, but they do exist.
Anyway, it cost me some time to figure out what was going on, but I can work around it now, so I'd call it a real problem but not a real urgent one.
Correct FAT behavior is to set the cluster to -1 for the bit width of the FAT entry (all F's) which is the FAT definition for end of chain.· Windows probably does the zeroes to keep blank files from clogging up the FAT with unused clusters, but the behavior is undocumented and incorrect.· Which isn't much of a surprise considering the source.