iansjack wrote:So learn how FAT filesystems work and have fun writing your own code to access them. For goodness sake, don't just cut and paste other people's code without understanding it. What's the point of that?
I agree here. The enjoyment that comes with this kind of work, at least for me and I am sure many others, is the act of learning about how things work and creating the code to do it yourself.
I understand that looking at other's code can help, I do it often, but the actual work, and learning how to make it work is and should be the best part.
The FAT file system is quite simple, especially compared to other more modern file systems. You have a BPB, one or more FAT's, a root directory block, and the the data block. That's it. Depending on the size of the FAT, you either have 12-, 16-, or 32-bits per entry. Depending on the cluster size, you have 1, 2, 4, 8, ... sectors per cluster. (Side note, the file system should have no idea nor dependency on the size of a sector).
Read the documentation, found at
http://www.fysnet.net/docs/fatgen103.pdf and many other places, learn how a file is stored on the disk, as well as the meta-data (the filename, size, etc.) is stored.
A FAT file system can also have Long File Names. These long file names are stored in the Meta-data area just like normal short names with a single modification to the attributes field to indicate a LFN. However, please note that Microsoft still owns the patent on this technique, though I don't think anyone is going to complain too much anymore.
If you wish, I have written a book that included this FAT file system, showing the layout of each section, how the file system is used, and, dare I say, it does include source code. If a book will suite you better, have a look at
http://www.fysnet.net/the_virtual_file_system.htm. If you would rather not, there are numerous references to the FAT file system on the internet. It just takes a little effort to stop and study it first.
On a side note, and for the pure fun of it, I created my own file system (
http://www.fysnet.net/fysfs.htm). It isn't anything to call home about, nor will it break any records (no pun intended). It was simply for the enjoyment of doing it, and as a test to see if my driver code was completely filesystem independent. Later, I adopted the LeanFS file system (
http://freedos-32.sourceforge.net/lean/) from FreeDOS and added a few things myself. The author was very charitable and allowed me to add to it.
There are many other file systems, Ext2/3/4, Reiser, BTRFS, NTFS (again patented), XFS, as well as many others. Once you get a working FAT driver (and I recommend you start there), you will want to move on to something more robust, secure, and capable of larger media.
Ben