FAT32 Structure Information

Master Boot Record

The Master Boot Record is the same for pretty much all Operating Systems.  It is located on the first Sector of the Hard Drive, at Cylinder 0, Head 0, Sector 1.  It is the first piece of code that your computer runs after it has checked all of your hardware (POST) and turned control of loading software over the hard drive.  It also contains the partition table, which defines the different sections of your hard drive.  Basically if anything happens to this little 512 byte section, your hard drive is brain dead.  Kinda scary, eh? :)

OffsetDescriptionSize
000hExecutable Code (Boots Computer)446 Bytes
1BEh1st Partition Entry (See Next Table)16 Bytes
1CEh2nd Partition Entry16 Bytes
1DEh3rd Partition Entry16 Bytes
1EEh4th Partition Entry16 Bytes
1FEhBoot Record Signature (55h AAh)2 Bytes


Partition Entry (Part of MBR)

OffsetDescriptionSize
00hCurrent State of Partition (00h=Inactive, 80h=Active)1 Byte
01hBeginning of Partition - Head1 Byte
02h Beginning of Partition - Cylinder/Sector (See Below)1 Word
04hType of Partition (See List Below)1 Byte
05hEnd of Partition - Head1 Byte
06hEnd of Partition - Cylinder/Sector1 Word
08hNumber of Sectors Between the MBR and the First Sector in the Partition1 Double Word
0ChNumber of Sectors in the Partition1 Double Word


Cylinder/Sector Encoding

I guess back in the days of 10MB hard drives and 8086's, code was at a premium.   So they did everything they could to preserve space.  Unfortunately now we have to live with it, but luckily they created new ways of translating the system so the 1024 Cylinder Limit (2^10) isn't too big of a problem, for newer computers, at least.   Older ones usually need some sort of Disk Overlay program to make them see the whole hard drive.  

Anyway, to get the Sector out of this, you need to apply an AND mask ($3F) to it.   To get the Cylinder, you take the high byte and OR it with the low byte that has been AND masked with ($C0) and then Shifted Left Two.  It's not very easy to explain, so I'll just show you how I did it with two routines I made (In Pascal) for Encoding and Decoding the Cylinder/Sector.  Hopefully even if you don't know Pascal you'll be able to read it.

Function CylSecEncode(Cylinder, Sector : Word) : Word;
Begin
    CylSecEncode := (Lo(Cylinder) shl 8) or (Hi(Cylinder) shl 6) or Sector;
End;

Procedure CylSecDecode(Var Cylinder, Sector : Word; CylSec : Word);
Begin
    Cylinder := Hi(CylSec) or ((Lo(CylSec) and $C0) shl 2);
    Sector := (CylSec and $3F);
End;

1514131211109876543210
Cylinder Bits 7 to 0Cylinder Bits 9+8Sector Bits 5 to 0


Partition Type Listing

There are more than just these shown, but I've only included that ones relevant to MS Operating Systems.

ValueDescription
00hUnknown or Nothing
01h12-bit FAT
04h16-bit FAT (Partition Smaller than 32MB)
05hExtended MS-DOS Partition
06h16-bit FAT (Partition Larger than 32MB)
0Bh32-bit FAT (Partition Up to 2048GB)
0ChSame as 0BH, but uses LBA1 13h Extensions
0EhSame as 06H, but uses LBA1 13h Extensions
0FhSame as 05H, but uses LBA1 13h Extensions


Reading Multiple Partitions

Although having multiple partitions in FAT32 isn't as likely as in FAT16, it still works the same way.  The first partition is the Primary Partition, and everything else is stored in the Extended Partition.  It's a little tricky when it comes to reading those extra partitions though (not a lot, just a little).  The first record in the partition table shows where the Primary partition is (how big it is, where it starts, and where it ends).  The second entry in the partition table shows where the Entire Extended Partition is (which may include more than just one partition).  To read any more partitions, you go to the where it says the Extended Partition starts, and read the first sector.  It acts just like the MBR.  It'll have blank where the code is supposed to be, and in the partition table it will have for it's first entry the next Partition in the Drive, and if there are anymore, there will be another Extended partition, just like before.  However, all references to Sector Numbers are made using the that new MBR point as the reference, making it a virtual drive.  Just incase this doesn't make much sense (and by the way I explain things I can understand if it doesn't), let me show you how a drive with three partitions is setup.

MBR of Whole Drive

    Entry #1 - Points to Partition #1
    Entry #2 - Points to the Entire Extended Partition

You would read the first sector of that Extended Partition, and see another MBR Structure.

MBR of Extended Partition

    Entry #1 - Points to Partition #2
    Entry #2 - Points to Rest of Extended Partition after Partition #2

Now, all references to Sector Numbers (most specifically the entry at Offset 08h) in those Entries wouldn't be referenced from the start of the drive, but from the start of the Extended Partition.  However, the CHS (Cylinder, Head, Sector) numbers would still be right.

Once again, you would read the first sector of that Extended Partition, and see the next MBR.

MBR of Rest of Extended Partition

    Entry #1 - Points to Partition #3
    No Entry #2, since this was the Last Partition

If there were another partition, the pattern would continue just like before, until the last one was reached.

 


FAT32 Boot Record

This information is located in the first sector of every partition.

OffsetDescriptionSize
00hJump Code + NOP3 Bytes
03hOEM Name (Probably MSWIN4.1)8 Bytes
0BhBytes Per Sector1 Word
0DhSectors Per Cluster1 Byte
0EhReserved Sectors1 Word
10hNumber of Copies of FAT1 Byte
11hMaximum Root Directory Entries (N/A for FAT32)1 Word
13hNumber of Sectors in Partition Smaller than 32MB (N/A for FAT32)1 Word
15hMedia Descriptor (F8h for Hard Disks)1 Byte
16hSectors Per FAT in Older FAT Systems (N/A for FAT32)1 Word
18hSectors Per Track1 Word
1AhNumber of Heads1 Word
1ChNumber of Hidden Sectors in Partition1 Double Word
20hNumber of Sectors in Partition1 Double Word
24hNumber of Sectors Per FAT1 Double Word
28hFlags (Bits 0-4 Indicate Active FAT Copy) (Bit 7 Indicates whether FAT Mirroring is Enabled or Disabled <Clear is Enabled>) (If FAT Mirroring is Disabled, the FAT Information is only written to the copy indicated by bits 0-4)1 Word
2AhVersion of FAT32 Drive (High Byte = Major Version, Low Byte = Minor Version)1 Word
2ChCluster Number of the Start of the Root Directory1 Double Word
30hSector Number of the File System Information Sector (See Structure Below) (Referenced from the Start of the Partition)1 Word
32hSector Number of the Backup Boot Sector (Referenced from the Start of the Partition)1 Word
34hReserved12 Bytes
40hLogical Drive Number of Partition1 Byte
41hUnused (Could be High Byte of Previous Entry)1 Byte
42hExtended Signature (29h)1 Byte
43hSerial Number of Partition1 Double Word
47hVolume Name of Partition11 Bytes
52hFAT Name (FAT32)8 Bytes
5AhExecutable Code420 Bytes
1FEhBoot Record Signature (55h AAh)2 Bytes


File System Information Sector

Usually this is the Second Sector of the partition, although since there is a reference in the Boot Sector to it, I'm assuming it can be moved around.  I never got a complete picture of this one.  Although I do know where the important fields are at.

OffsetDescriptionSize
00hFirst Signature (52h 52h 61h 41h)1 Double Word
04hUnknown, Currently (Might just be Null)480 Bytes
1E4hSignature of FSInfo Sector (72h 72h 41h 61h)1 Double Word
1E8hNumber of Free Clusters (Set to -1 if Unknown)1 Double Word
1EChCluster Number of Cluster that was Most Recently Allocated.1 Double Word
1F0hReserved12 Bytes
1FChUnknown or Null2 Bytes
1FEhBoot Record Signature (55h AAh)2 Bytes


FAT32 Drive Layout

OffsetDescription
Start of PartitionBoot Sector
Start + # of Reserved SectorsFat Tables
Start + # of Reserved + (# of Sectors Per FAT * 2) <Assuming that FAT Mirroring is Enabled, I personally haven't seen a case where it wasn't, but I guess there is always the possibility>Data Area (Starts with Cluster #2)

 

Cluster Meaning

A Cluster is a Group of Sectors on the Hard Drive that have information in them.   A 4K Cluster has 8 Sectors in it (512*8=4096).  Each Cluster is given a spot in the FAT Table.  When you look at an Entry in the FAT, the number there tells you whether or not that cluster has data in it, and if so, if it is the end of the data or there is another cluster after it.  All Data on a Partition starts with Cluster #2.    If the FAT Entry is 0, then there is no data in that cluster.  If the FAT Entry is 0FFFFFFFh, then it is the last entry in the chain. 

This is one of my biggest holes in my information.  I am unable to find anyplace that shows what numbers mean what when it comes to the FAT table.  I was able to tell the end of the chain just by looking at a FAT32 Drive, but I don't know what stands for a BAD Cluster or what the maximum valid number for showing data is. 

For now, you can calculate the maximum valid cluster in a partition with this formula:

( (# of Sectors in Partition) - (# of Sectors per Fat * 2) - (# of Reserved Sectors) ) /  (# of Sectors per Cluster)

If there is any remainder in the answer to that formula, it just means that there were a few extra clusters at the end of the partition (probably not enough to make another cluster), so you can just get rid of anything after the decimal point.

    Thanks to Andrew Clausen for pointing this formula out to me.

 

Directory Table

Another aspect when looking at a File System at Low Level is the Directory Table.   The Directory Table is what stores all of the File and Directory Entries.   Basically there is only one difference between the Directory Table of FAT16 and FAT32, so go here to look at FAT16's Structure.   The Difference is : the Reserved OS/2 Byte (Offset 20 [14h]) in the Short Filename Structure is replaced with the High Word of the Cluster Number (since it's now 4 bytes instead of 2).

Footnotes

1 - LBA = Logical Block Addressing - Uses the Int 13h Extensions built into newer BIOS's to access data above the 8GB barrier, or to access strickly in LBA mode, instead of CHS (Cylinder, Head, Sector).

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值