FAT32 sector usage
-
Kemp
FAT32 sector usage
I've been reading through the FAT32 specs and the numbers don't seem to add up. Firstly, why does it require 32 reserved sectors? I only count about 5 actual structures that use a sector each. Also, the first data cluster is cluster 2 and with 8 sectors per cluster that means the data area starts at sector 16, so the reserved sectors extend for an extra 16 sectors into the data area. Who wrote this thing anyway? (metaphorical
)
-
B.E
Re:FAT32 sector usage
You forgetting the FAT it self.
this will get you the first data sector:
If(BPB_FATSz16 != 0)
FATSz = BPB_FATSz16;
Else
FATSz = BPB_FATSz32;
FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
this will get you the first data sector:
If(BPB_FATSz16 != 0)
FATSz = BPB_FATSz16;
Else
FATSz = BPB_FATSz32;
FirstDataSector = BPB_ResvdSecCnt + (BPB_NumFATs * FATSz) + RootDirSectors;
-
Kemp
Re:FAT32 sector usage
Ok, let's see if I have this straight.
[pre]
Sector Area Contents
0 Boot sector
1 FSInfo
6 Backup boot sector
16-31 Data All reserved for FAT tables
[/pre]
Is that correct? (Using the standard recommended values in the BPB of course)
The BPB defines the root drectory cluster number, which is normally 2. This places the root directory on top of the fat tables. This is where I get confused also. I always thought of the fat tables as being the map that shows which areas of the disk are already used and etc, whereas the docs refer to the fat as being the root directory list.
[pre]
Sector Area Contents
0 Boot sector
1 FSInfo
6 Backup boot sector
16-31 Data All reserved for FAT tables
[/pre]
Is that correct? (Using the standard recommended values in the BPB of course)
The BPB defines the root drectory cluster number, which is normally 2. This places the root directory on top of the fat tables. This is where I get confused also. I always thought of the fat tables as being the map that shows which areas of the disk are already used and etc, whereas the docs refer to the fat as being the root directory list.
-
B.E
Re:FAT32 sector usage
this directly copied from the spec:
so if FirstDataSector is 32 and if BPB_SecPerClus equal to 8 then the root directory would be theGiven any valid data cluster number N, the sector number of the first sector of that cluster (again relative to sector 0 of the FAT volume) is computed as follows:
FirstSectorofCluster = ((N ? 2) * BPB_SecPerClus) + FirstDataSector;
Code: Select all
FirstSectorofCluster = ((2 -2) * 8) + 32;
= 32;
-
Kemp
Re:FAT32 sector usage
I have that document right here and I know how you work out things like the first sector for a particular cluster. What I want to know is what the sectors are actually used for as I can't find any reason for there to be so many reserved ones.
-
B.E
Re:FAT32 sector usage
The following section it the same specs explains why
What are the two reserved clusters at the start of the FAT for? The first reserved cluster, FAT[ 0 ], contains the BPB_Media byte value in its low 8 bits, and all other bits are set to 1. For example, if the BPB_Media value is 0xF8, for FAT12 FAT[ 0 ] = 0x0FF8, for FAT16 FAT[ 0 ] = 0xFFF8, and for FAT32 FAT[ 0 ] = 0x0FFFFFF8. The second reserved cluster, FAT[ 1 ], is set by FORMAT to the EOC mark. On FAT12 volumes, it is not used and is simply always contains an EOC mark. For FAT16 and FAT32, the file system driver may use the high two bits of the FAT[1] entry for dirty volume flags (all other bits, are always left set to 1). Note that the bit location is different for FAT16 and FAT32, because they are the high 2 bits of the entry.
-
Kemp
Re:FAT32 sector usage
That's one of the other bits that didn't make much sense to me when I read it. A cluster is 8 sectors usually, each one being 512 bytes, which means that they use 4kb of storage for storing an 8 bit value. Plus if those thwo clusters are used for storing that then that means that the FAT isn't in the reserved area. I'm really tempted to just not bother supporting FAT32, they must have been smoking some good s**t when they designed the thing.
And B.E., If I wanted to read quotes from the whitepaper I would read the thing over again, I come to this forum for a human's perspective on things. Does no-one here have a simple "this sector is used for this structure" type table? I'd imagine it would be useful to a lot of people.
And B.E., If I wanted to read quotes from the whitepaper I would read the thing over again, I come to this forum for a human's perspective on things. Does no-one here have a simple "this sector is used for this structure" type table? I'd imagine it would be useful to a lot of people.
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:FAT32 sector usage
Well, it looks like the value is stored in the FAT itself, not on the sectors ... I guess 'smart' formatting tools will make the 'first sector' of the data part coded such that no space is actually lost by that convention.Kemp wrote: That's one of the other bits that didn't make much sense to me when I read it. A cluster is 8 sectors usually, each one being 512 bytes, which means that they use 4kb of storage for storing an 8 bit value.
Re:FAT32 sector usage
Footprint for recovery tools that try to repair a screwed-up FAT partition?Kemp wrote:A cluster is 8 sectors usually, each one being 512 bytes, which means that they use 4kb of storage for storing an 8 bit value.
(Just wild guessing / drawing from half-forgotten memories, I didn't delve into FAT that much myself.)
Some would claim that you have to be distinctly inhuman to do OS development.And B.E., If I wanted to read quotes from the whitepaper I would read the thing over again, I come to this forum for a human's perspective on things.
Which part of the whitepaper information remained unclear to you? Which additional information do you want?
Every good solution is obvious once you've found it.
-
distantvoices
- Member

- Posts: 1600
- Joined: Wed Oct 18, 2006 11:59 am
- Location: Vienna/Austria
- Contact:
Re:FAT32 sector usage
cluster management info is stored in the FAT as Pype states, so I daresay, there aren't 512 bytes wasted.
btw, has someone a good cup o' coffee for me? I'm dead tired today.
btw, has someone a good cup o' coffee for me? I'm dead tired today.
... the osdever formerly known as beyond infinity ...
BlueillusionOS iso image
BlueillusionOS iso image
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:FAT32 sector usage
Here you get it. It should be hot'n'Streamy in about 58 mins.beyond infinity wrote: btw, has someone a good cup o' coffee for me? I'm dead tired today.
-
Kemp
Re:FAT32 sector usage
My question was basically "What are all those sectors used for?". There are a lot more reserved than I can find a reason for (both in and before the data area). As I noted before, I know where the boot sector, file system info, and backup boot sectors go so that's 3 out of 16 sectors used at the beginning, but I can't find reference to the other 13 sectors being used for anything.
Then there's the 16 reserved sectors in the data area, which is where one of my issues with how things are named comes in. There is the root directory entry (which they appear to call the FAT table in the whitepaper) which has its obvious function, and I thought there was an area that basically has a list that says "If you're loading a file from X at the moment then the next part is at Y", which I always called the FAT table (yeah, I know the "table" at the end is redundant, but it doesn't sound right to me otherwise
).
So to summarise, two basic questions:
1) What are all the extra sectors at the start of the disk used for (if anything)?
2) What are the reserved sectors in the data area used for? (though mainly, why do I have these freaky pre-conceptions about what should be there)
I'm gonna keep following number 2 up myself with the info I have and I'll hopefully figure it out properly, I don't expect to be spoon-fed how to do things, sorry if I've appeared that way.
Then there's the 16 reserved sectors in the data area, which is where one of my issues with how things are named comes in. There is the root directory entry (which they appear to call the FAT table in the whitepaper) which has its obvious function, and I thought there was an area that basically has a list that says "If you're loading a file from X at the moment then the next part is at Y", which I always called the FAT table (yeah, I know the "table" at the end is redundant, but it doesn't sound right to me otherwise
So to summarise, two basic questions:
1) What are all the extra sectors at the start of the disk used for (if anything)?
2) What are the reserved sectors in the data area used for? (though mainly, why do I have these freaky pre-conceptions about what should be there)
I'm gonna keep following number 2 up myself with the info I have and I'll hopefully figure it out properly, I don't expect to be spoon-fed how to do things, sorry if I've appeared that way.
Re:FAT32 sector usage
Up to now I've been at school, being required to work and all. I couldn't type a long list of stuff that I recall.Kemp wrote: My question was basically "What are all those sectors used for?". There are a lot more reserved than I can find a reason for (both in and before the data area). As I noted before, I know where the boot sector, file system info, and backup boot sectors go so that's 3 out of 16 sectors used at the beginning, but I can't find reference to the other 13 sectors being used for anything.
Then there's the 16 reserved sectors in the data area, which is where one of my issues with how things are named comes in. There is the root directory entry (which they appear to call the FAT table in the whitepaper) which has its obvious function, and I thought there was an area that basically has a list that says "If you're loading a file from X at the moment then the next part is at Y", which I always called the FAT table (yeah, I know the "table" at the end is redundant, but it doesn't sound right to me otherwise).
So to summarise, two basic questions:
1) What are all the extra sectors at the start of the disk used for (if anything)?
2) What are the reserved sectors in the data area used for? (though mainly, why do I have these freaky pre-conceptions about what should be there)
I'm gonna keep following number 2 up myself with the info I have and I'll hopefully figure it out properly, I don't expect to be spoon-fed how to do things, sorry if I've appeared that way.
Now I'm home. Prepare.
FAT32 is like FAT12 in most areas, except that its file table IS counted in the cluster chain and is a normal cluster chain, where the FAT12 one (as well as the FAT16 one) isn't. FAT32 is technically FAT28 though.
So, from the start you have:
<reserved sectors> <FAT1> <FAT2> ! <file table> <other stuff>
The exclamation mark is where cluster 2 begins. It's called cluster 2 since they needed some 3 bytes of info in the FAT and in FAT12, that used up the first two entries. In fat32 they scaled it to eat 8 bytes, without doing more. Still, that eats the first two cluster entries in the FAT.
Each cluster is between 512 and 32768 bytes large. In NT4 FAT16 systems you could use 65536 but it was very unsafe, since all other OSes didn't support it. The clusters start from the first sector after the FAT, which is sized according to a dword in the header. Note, they may be oversized. Before the two FATs is a block of reserved sectors, which may be used for anything your OS wants to (if it owns the disk). Strictly speaking, it's for a boot loader, extended information, backup boot sector, root sector or sth. Microsoft backs up sector #0 of the partition in sector #6. There is also, iirc, a bit of extra header info in sector #1.
Hope this helps, Candy
[edit] Yep, they're clusters, not cylinders. [/edit]
- Pype.Clicker
- Member

- Posts: 5964
- Joined: Wed Oct 18, 2006 2:31 am
- Location: In a galaxy, far, far away
- Contact:
Re:FAT32 sector usage
uh? shouldn't we search&replace "cylinder" ==> "cluster" from that point ?Candy wrote: Still, that eats the first two cylinder entries in the FAT.
Each cylinder is between 512 and 32768 bytes large.
Hope this helps, Candy
-
Kemp
Re:FAT32 sector usage
Woooo, thanks for that Candy, it was quite helpful. So I can have
Sector 0 = Boot loader
Sector 1 = FSInfo
Sector 6 = Backup boot sector
and use any others I want for my second stage? I'm doing a proper loader that grabs the right file rather than assuming it'll be the first one on the disk, and 420 bytes isn't quite enough for that ;D Wanted to make sure there weren't any unofficial uses for the other sectors that I should watch out for.
Just to check I'm not missing something:
Thanks again, and if you think of anything else feel free to keep it coming
Sector 0 = Boot loader
Sector 1 = FSInfo
Sector 6 = Backup boot sector
and use any others I want for my second stage? I'm doing a proper loader that grabs the right file rather than assuming it'll be the first one on the disk, and 420 bytes isn't quite enough for that ;D Wanted to make sure there weren't any unofficial uses for the other sectors that I should watch out for.
Just to check I'm not missing something:
What exactly do you mean by that?root sector or sth
Thanks again, and if you think of anything else feel free to keep it coming