I’ve added FAT16 support to my driver. It was as expected a pretty trivial change, since the only real difference is the size of FAT entries and the location (and size) of the root directory. I haven’t tested I/O yet, but directory traversal works fine.
I’ve also realised that the current system of treating directories as files just isn’t going to work. Directories have a length of 0 in their directory entry, which is all I go by when reading or writing to the file. So, they’ll always appear as empty, and have their length erroneously set to non-zero when written to. The only way to determine the length of the directory (aside from the root directory in FAT16, which has a length specified in the boot sector) is to look for the end entry (or, presumably, until you reach the last cluster).
So I guess I’ll have to disallow opening of directories as files. For our purposes we don’t really need to obtain directory listings – we can just always use well defined paths for everything. Still, as an academic exercise I might add some kind of iteration functionality (which we’ll just not compile in if we don’t need it).
It might also be handy to be able to delete files, but as I think I’ve noted previously, I really wouldn’t want that sort of code going into our UAV… we shouldn’t need to delete files, and being able to do so in the event of some trivial coding bug is kinda scary. :)
I still need to add in the ability to create new files and directories, though. I might get around to that some other time; I need to get some [paid] work done today. Still, I’m happy with it as is. Now I’ll just zip up the code and send it off to Rob so he can translate it to AVR assembly. ;)