Building FAT Driver

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
~
Member
Member
Posts: 1228
Joined: Tue Mar 06, 2007 11:17 am
Libera.chat IRC: ArcheFire

Building FAT Driver

Post 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?
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

IIRC in FAT32 the remaining bits are 'reserved', making all entries align to 32-bit boundaries.
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
User avatar
Dex
Member
Member
Posts: 1444
Joined: Fri Jan 27, 2006 12:00 am
Contact:

Post 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 ?.
User avatar
mystran
Member
Member
Posts: 670
Joined: Thu Mar 08, 2007 11:08 am

Post 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. :)
The real problem with goto is not with the control transfer, but with environments. Properly tail-recursive closures get both right.
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Post 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...
Post Reply