FAT12 FAT16 FAT32 学习

    技术2022-05-11  81

    Currently there are three FAT file system types: FAT12, FAT16 and FAT32. The basic difference in these FATsub types, and the reason for the names, is the size, in bits, of the entries in the actual FATstructure on the disk. There are 12 bits in a FAT12 FAT entry, 16 bits in a FAT16 FAT entryand 32 bits in a FAT32 FAT entry. 

    ContentsNotational Conventions in this Document................................................................................. 6General Comments (Applicable to FAT File System All Types)............................................... 6Boot Sector and BPB ................................................................................................................ 6FAT Data Structure ................................................................................................................. 12FAT Type Determination......................................................................................................... 13FAT Volume Initialization ........................................................................................................ 18FAT32 FSInfo Sector Structure and Backup Boot Sector ...................................................... 20FAT Directory Structure .......................................................................................................... 21Other Notes Relating to FAT Directories ................................................................................ 24Specification Compliance........................................................................................................ 25

    Notational Conventions in this Document

    Numbers that have the characters “0x” at the beginning of them are hexadecimal (base 16) numbers.Any numbers that do not have the characters “0x” at the beginning are decimal (base 10) numbers.The code fragments in this document are written in the ‘C’ programming language. Strict typing andsyntax are not adhered to.There are several code fragments in this document that freely mix 32-bit and 16-bit data elements. It isassumed that you are a programmer who understands how to properly type such operations so thatdata is not lost due to truncation of 32-bit values to 16-bit values. Also take note that all data types areUNSIGNED. Do not do FAT computations with signed integer types, because the computations willbe wrong on some FAT volumes.

    General Comments (Applicable to FAT File System All Types)All of the FAT file systems were originally developed for the IBM PC machine architecture. Theimportance of this is that FAT file system on disk data structure is all “little endian.” If we look at one32-bit FAT entry stored on disk as a series of four 8-bit bytes—the first being byte[0] and the lastbeing byte[4]—here is where the 32 bits numbered 00 through 31 are (00 being the least significantbit):byte[3] 3 3 2 2 2 2 2 21 0 9 8 7 6 5 4byte[2] 2 2 2 2 1 1 1 13 2 1 0 9 8 7 6byte[1] 1 1 1 1 1 1 0 05 4 3 2 1 0 9 8byte[0] 0 0 0 0 0 0 0 07 6 5 4 3 2 1 0This is important if your machine is a “big endian” machine, because you will have to translatebetween big and little endian as you move data to and from the disk.A FAT file system volume is composed of four basic regions, which are laid out in this order on thevolume:0 – Reserved Region1 – FAT Region2 – Root Directory Region (doesn’t exist on FAT32 volumes)3 – File and Directory Data Region

    Boot Sector and BPBThe first important data structure on a FAT volume is called the BPB (BIOS Parameter Block), whichis located in the first sector of the volume in the Reserved Region. This sector is sometimes called the“boot sector” or the “reserved sector” or the “0th sector,” but the important fact is simply that it is thefirst sector of the volume.This is the first thing about the FAT file system that sometimes causes confusion. In MS-DOS version1.x, there was not a BPB in the boot sector. In this first version of the FAT file system, there wereonly two different formats, the one for single-sided and the one for double-sided 360K 5.25-inchfloppy disks. The determination of which type was on the disk was done by looking at the first byte ofthe FAT (the low 8 bits of FAT[0]).This type of media determination was superseded in MS-DOS version 2.x by putting a BPB in theboot sector, and the old style of media determination (done by looking at the first byte of the FAT)was no longer supported. All FAT volumes must have a BPB in the boot sector.This brings us to the second point of confusion relating to FAT volume determination: What exactlydoes a BPB look like? The BPB in the boot sector defined for MS-DOS 2.x only allowed for a FATvolume with strictly less than 65,536 sectors (32 MB worth of 512-byte sectors). This limitation wasdue to the fact that the “total sectors” field was only a 16-bit field. This limitation was addressed byMS-DOS 3.x, where the BPB was modified to include a new 32-bit field for the total sectors value.The next BPB change occurred with the Microsoft Windows 95 operating system, where the FAT32type was introduced. FAT16 was limited by the maximum size of the FAT and the maximum validcluster size to no more than a 2 GB volume if the disk had 512-byte sectors. FAT32 addressed thislimitation on the amount of disk space that one FAT volume could occupy so that disks larger than2 GB only had to have one partition defined.The FAT32 BPB exactly matches the FAT12/FAT16 BPB up to and including the BPB_TotSec32field. They differ starting at offset 36, depending on whether the media type is FAT12/FAT16 orFAT32 (see discussion below for determining FAT type). The relevant point here is that the BPB inthe boot sector of a FAT volume should always be one that has all of the new BPB fields for either theFAT12/FAT16 or FAT32 BPB type. Doing it this way ensures the maximum compatibility of the FATvolume and ensures that all FAT file system drivers will understand and support the volume properly,because it always contains all of the currently defined fields.NOTE: In the following description, all the fields whose names start with BPB_ are part of the BPB.All the fields whose names start with BS_ are part of the boot sector and not really part of the BPB.The following shows the start of sector 0 of a FAT volume, which contains the BPB

     


    最新回复(0)