Page 1 of 1

Building FAT Driver

Posted: Mon Apr 02, 2007 11:36 am
by ~
I have started to build a FAT code, that should support FAT12, FAT16 and FAT32.

I know that FAT12 is "packed", it means that it takes up 1.5 bytes, or 12 bits out of 16 bits of a word. The remaining 4 bits are taken up by the next packed 12 bits of the next entry.

Is the FAT32 packed as well, using only 28 bits per entry and then using the remaining 4 bits for the next entry? Or is it aligned to (4-byte) 32-bit boundary?

Posted: Mon Apr 02, 2007 12:31 pm
by Combuster
IIRC in FAT32 the remaining bits are 'reserved', making all entries align to 32-bit boundaries.

Posted: Mon Apr 02, 2007 12:32 pm
by Dex
I think the number in the fat answer your ? , eg: fat12 = 12bits, fat16 = 16bits, fat32 = 32bits :wink: .
That also why fat16/fat32 are much easier to code, compeared to fat12.
But still a good ?.

Posted: Mon Apr 02, 2007 1:09 pm
by mystran
Could one not simply define something like:

Code: Select all

struct fat12_2 {
   unsigned a : 12;
   unsigned b : 12;
} __attribute__((packed));
That totals 3 bytes, so one would expect that if you do a pointer to an array of those, you'll get GCC do all the hard work for you, right?

Haven't tested. Will test in a minute, since my next project is to read the fat off the floppies, which I now got working properly. :)

Posted: Mon Apr 02, 2007 6:47 pm
by pcmattman
Read the FAT document (released by M$). It has tables to show you the directory structure, BPB structure etc... and also has code that shows how to handle the FAT structure itself.

It's what it took for me to finally be able to read FAT12 floppies. Now I'm onto reading FAT16 and FAT32 on hard drives, and soon I'll support NTFS. The documents M$ releases are so useful sometimes.

NB: The same goes for the ATA specs...