全部博文(60)
分类: 嵌入式
2010-04-14 22:44:56
The Partition Boot Sector contains information that the file system uses to access the volume. On x86-based computers, the Master Boot Record use the Partition Boot Sector on the system partition to load the operating system kernel files.
Table 4-2 describes the fields in the Partition Boot Sector for a volume formatted with the FAT file system.
Table 4-2 Fields in Partition Boot Sector (FAT File System)
Byte Offset (in hex) |
Field Length |
Sample Value |
Meaning |
---|---|---|---|
00 |
3 bytes |
EB 3C 90 |
Jump instruction |
03 |
8 bytes |
MSDOS5.0 |
OEM Name in text |
0B |
25 bytes |
|
BIOS Parameter Block |
24 |
26 bytes |
|
Extended BIOS Parameter Block |
3E |
448 bytes |
|
Bootstrap code |
1FE |
2 bytes |
0x55AA |
End of sector marker |
Table 4-3 describes BIOS Parameter Block and Extended BIOS Parameter Block Fields.
Table 4-3 BIOS Parameter Block and Extended BIOS Parameter Block Fields
Byte Offset |
Field Length |
Sample Value |
Meaning |
---|---|---|---|
0x0B |
WORD |
0x0002 |
Bytes per Sector. The size of a hardware sector. For most disks in use in the United States, the value of this field is 512. |
0x0D |
BYTE |
0x08 |
Sectors Per Cluster. The number of sectors in a cluster. The default cluster size for a volume depends on the volume size and the file system. |
0x0E |
WORD |
0x0100 |
Reserved Sectors. The number of sectors from the Partition Boot Sector to the start of the first file allocation table, including the Partition Boot Sector. The minimum value is 1. If the value is greater than 1, it means that the bootstrap code is too long to fit completely in the Partition Boot Sector. |
0x10 |
BYTE |
0x02 |
Number of file allocation tables (FATs). The number of copies of the file allocation table on the volume. Typically, the value of this field is 2. |
0x11 |
WORD |
0x0002 |
Root Entries. The total number of file name entries that can be stored in the root folder of the volume. One entry is always used as a Volume Label. Files with long filenames use up multiple entries per file. Therefore, the largest number of files in the root folder is typically 511, but you will run out of entries sooner if you use long filenames. |
0x13 |
WORD |
0x0000 |
Small Sectors. The number of sectors on the volume if the number fits in 16 bits (65535). For volumes larger than 65536 sectors, this field has a value of 0 and the Large Sectors field is used instead. |
0x15 |
BYTE |
0xF8 |
Media Type. Provides information about the media being used. A value of 0xF8 indicates a hard disk. |
0x16 |
WORD |
0xC900 |
Sectors per file allocation table (FAT). Number of sectors occupied by each of the file allocation tables on the volume. By using this information, together with the Number of FATs and Reserved Sectors, you can compute where the root folder begins. By using the number of entries in the root folder, you can also compute where the user data area of the volume begins. |
0x18 |
WORD |
0x3F00 |
Sectors per Track. The apparent disk geometry in use when the disk was low-level formatted. |
0x1A |
WORD |
0x1000 |
Number of Heads. The apparent disk geometry in use when the disk was low-level formatted. |
0x1C |
DWORD |
3F 00 00 00 |
Hidden Sectors. Same as the Relative Sector field in the Partition Table. |
0x20 |
DWORD |
51 42 06 00 |
Large Sectors. If the Small Sectors field is zero, this field contains the total number of sectors in the volume. If Small Sectors is nonzero, this field contains zero.. |
0x24 |
BYTE |
0x80 |
Physical Disk Number. This is related to the BIOS physical disk number. Floppy drives are numbered starting with 0x00 for the A disk. Physical hard disks are numbered starting with 0x80. The value is typically 0x80 for hard disks, regardless of how many physical disk drives exist, because the value is only relevant if the device is the startup disk. |
0x25 |
BYTE |
0x00 |
Current Head. Not used by the FAT file system. |
0x26 |
BYTE |
0x29 |
Signature. Must be either 0x28 or 0x29 in order to be recognized by Windows NT. |
0x27 |
4 bytes |
CE 13 46 30 |
Volume Serial Number. A unique number that is created when you format the volume. |
0x2B |
11 bytes |
NO NAME |
Volume Label. This field was used to store the volume label, but the volume label is now stored as special file in the root directory. |
0x36 |
8 bytes |
FAT16 |
System ID. Either FAT12 or FAT16, depending on the format of the disk. |
The FAT file allocation system is named for its method of organization, the file allocation table, which resides at the beginning of the volume. To protect the volume, two copies of the table are kept, in case one becomes damaged. In addition, the file allocation tables must be stored in a fixed location so that the files needed to start the system can be correctly located.
The file allocation table contains the following types of information about each cluster on the volume (see example below for FAT16):
There is no organization to the FAT folder structure, and files are given the first available location on the volume. The starting cluster number is the address of the first cluster used by the file. Each cluster contains a pointer to the next cluster in the file, or an indication (0xFFFF) that this cluster is the end of the file. These links and end of file indicators are shown below.
Example of File Allocation Table
Figure 4-2 Example of File Allocation Table
This illustration shows three files. The file File1.txt is a file that is large enough to use three clusters. The second file, File2.txt, is a fragmented file that also requires three clusters. A small file, File3.txt, fits completely in one cluster. In each case, the folder structure points to the first cluster of the file.
The root folder contains an entry for each file and folder on the root. The only difference between the root folder and other folders is that the root folder is on a specified location on the disk and has a fixed size (512 entries for a hard disk, number of entries on a floppy disk depends on the size of the disk).
See topic for details about folder organization.
Folders have set of 32-byte Folder Entries for each file and subfolder contained in the folder (see example figure below).
The Folder Entry includes the following information:
There is no organization to the FAT folder structure, and files are given the first available location on the volume. The starting cluster number is the address of the first cluster used by the file. Each cluster contains a pointer to the next cluster in the file, or an indication (0xFFFF) that this cluster is the end of the file. See for details.
The information in the folder is used by all operating systems that support the FAT file system. In addition, Windows NT can store additional time stamps in a FAT folder entry. These time stamps show when the file was created or last accessed and are used principally by POSIX applications.
Because all entries in a folder are the same size, the attribute byte for each entry in a folder describes what kind of entry it is. One bit indicates that the entry is for a subfolder, while another bit marks the entry as a volume label. Normally, only the operating system controls the settings of these bits.
A FAT file has four attributes bits that can be turned on or off by the user - archive file, system file, hidden file, and read-only file.
Beginning with Windows NT 3.5, files created or renamed on FAT volumes use the attribute bits to support long filenames in a way that does not interfere with how MS-DOS or OS/2 accesses the volume. Whenever a user creates a file with a long filename, Windows creates an eight-plus-three name for the file. In addition to this conventional entry, Windows creates one or more secondary folder entries for the file, one for each 13 characters in the long filename. Each of these secondary folder entries stores a corresponding part of the long filename in Unicode. Windows sets the volume, read-only, system, and hidden file attribute bits of the secondary folder entry to mark it as part of a long filename. MS-DOS and OS/2 generally ignore folder entries with all four of these attribute bits set, so these entries are effectively invisible to these operating systems. Instead, MS-DOS and OS/2 access the file by using the conventional eight-plus-three filename contained in the folder entry for the file.
Figure 4-3 below shows all of the folder entries for the file Thequi~1.fox, which has a long name of The quick brown.fox. The long name is in Unicode, so each character in the name uses two bytes in the folder entry. The attribute field for the long name entries has the value 0x0F. The attribute field for the short name is 0x20.
Figure 4-3 Long File Name Folder Entry Example
The following topics describe the FAT32 file system.
FAT32 is a derivative of the File Allocation Table (FAT) file system that supports drives with over 2GB of storage. Because FAT32 drives can contain more than 65,526 clusters, smaller clusters are used than on large FAT16 drives. This method results in more efficient space allocation on the FAT32 drive.
The largest possible file for a FAT32 drive is 4GB minus 2 bytes.
The FAT32 file system includes four bytes per cluster within the file allocation table. Note that the high 4 bits of the 32-bit values in the FAT32 file allocation table are reserved and are not part of the cluster number.
Table 4-4 Modifications to Boot Sector
Modifications |
Description |
---|---|
Reserved Sectors |
FAT32 drives contain more reserved sectors than FAT16 or FAT12 drives. The number of reserved sectors is usually 32, but can vary. |
Boot Sector Modifications |
Because a FAT32 BIOS Parameter Block (BPB), represented by the structure, is larger than a standard BPB, the boot record on FAT32 drives is greater than 1 sector. In addition, there is a sector in the reserved area on FAT32 drives that contains values for the count of free clusters and the cluster number of the most recently allocated cluster. These values are members of the structure which is contained within this sector. These additional fields allow the system to initialize the values without having to read the entire file allocation table. |
Root Directory |
The root directory on a FAT32 drive is not stored in a fixed location as it is on FAT16 and FAT12 drives. On FAT32 drives, the root directory is an ordinary cluster chain. The A_BF_BPB_RootDirStrtClus member in the BPB structure contains the number of the first cluster in the root directory. This allows the root directory to grow as needed. In addition, the BPB_RootEntries member of BPB is ignored on a FAT32 drive. |
Sectors Per FAT |
The A_BF_BPB_SectorsPerFAT member of is always zero on a FAT32 drive. Additionally, the A_BF_BPB_BigSectorsPerFat and A_BF_BPB_BigSectorsPerFatHi members of the updated BPB provide equivalent information for FAT32 media. |
The BPB for FAT32 drives is an extended version of the FAT16/FAT12 BPB. It contains identical information to a standard BPB, but also includes several extra fields for FAT32 specific information.
This structure is implemented in Windows OEM Service Release 2 and later.
A_BF_BPB STRUC A_BF_BPB_BytesPerSector DW ? A_BF_BPB_SectorsPerCluster DB ? A_BF_BPB_ReservedSectors DW ? A_BF_BPB_NumberOfFATs DB ? A_BF_BPB_RootEntries DW ? A_BF_BPB_TotalSectors DW ? A_BF_BPB_MediaDescriptor DB ? A_BF_BPB_SectorsPerFAT DW ? A_BF_BPB_SectorsPerTrack DW ? A_BF_BPB_Heads DW ? A_BF_BPB_HiddenSectors DW ? A_BF_BPB_HiddenSectorsHigh DW ? A_BF_BPB_BigTotalSectors DW ? A_BF_BPB_BigTotalSectorsHigh DW ? A_BF_BPB_BigSectorsPerFat DW ? A_BF_BPB_BigSectorsPerFatHi DW ? A_BF_BPB_ExtFlags DW ? A_BF_BPB_FS_Version DW ? A_BF_BPB_RootDirStrtClus DW ? A_BF_BPB_RootDirStrtClusHi DW ? A_BF_BPB_FSInfoSec DW ? A_BF_BPB_BkUpBootSec DW ? A_BF_BPB_Reserved DW 6 DUP (?) A_BF_BPB ENDS
Table 4-5 BPB Members
Member Name |
Description |
---|---|
A_BF_BPB_BytesPerSector |
The number of bytes per sector. |
A_BF_BPB_SectorsPerCluster |
The number of sectors per cluster. |
A_BF_BPB_ReservedSectors |
The number of reserved sectors, beginning with sector 0. |
A_BF_BPB_NumberOfFATs |
The number of File Allocation Tables. |
A_BF_BPB_RootEntries |
This member is ignored on FAT32 drives. |
A_BF_BPB_TotalSectors |
The size of the partition, in sectors. |
A_BF_BPB_MediaDescriptor |
The media descriptor. Values in this member are identical to standard BPB. |
A_BF_BPB_SectorsPerFAT |
The number of sectors per FAT. |
Note: This member will always be zero in a FAT32 BPB. Use the values from A_BF_BPB_BigSectorsPerFat and A_BF_BPB_BigSectorsPerFatHi for FAT32 media. | |
A_BF_BPB_SectorsPerTrack |
The number of sectors per track. |
A_BF_BPB_Heads |
The number of read/write heads on the drive. |
A_BF_BPB_HiddenSectors |
The number of hidden sectors on the drive. |
A_BF_BPB_HiddenSectorsHigh |
The high word of the hidden sectors value. |
A_BF_BPB_BigTotalSectors |
The total number of sectors on the FAT32 drive. |
A_BF_BPB_BigTotalSectorsHigh |
The high word of the FAT32 total sectors value. |
A_BF_BPB_BigSectorsPerFat |
The number of sectors per FAT on the FAT32 drive. |
A_BF_BPB_BigSectorsPerFatHi |
The high word of the FAT32 sectors per FAT value. |
A_BF_BPBExtFlags |
Flags describing the drive. Bit 8 of this value indicates whether or not information written to the active FAT will be written to all copies of the FAT. The low 4 bits of this value contain the 0-based FAT number of the Active FAT, but are only meaningful if bit 8 is set. This member can contain a combination of the following values. |
Value |
Description |
BGBPB_F_ActiveFATMsk (000Fh) |
Mask for low four bits. |
BGBPB_F_NoFATMirror (0080h) |
Mask indicating FAT mirroring state. If set, FAT mirroring is disabled. If clear, FAT mirroring is enabled. |
Bits 4-6 and 8-15 are reserved. | |
A_BF_BPB_FS_Version |
The file system version number of the FAT32 drive. The high byte represents the major version, and the low byte represents the minor version. |
A_BF_BPB_RootDirStrtClus |
The cluster number of the first cluster in the FAT32 drive's root directory. |
A_BF_BPB_RootDirStrtClusHi |
The high word of the FAT32 starting cluster number. |
A_BF_BPB_FSInfoSec |
The sector number of the file system information sector. The file system info sector contains a structure. This member is set to 0FFFFh if there is no FSINFO sector. Otherwise, this value must be non-zero and less than the reserved sector count. |
A_BF_BPB_BkUpBootSec |
The sector number of the backup boot sector. This member is set to 0FFFFh if there is no backup boot sector. Otherwise, this value must be non-zero and less than the reserved sector count. |
A_BF_BPB_Reserved |
Reserved member. |
Contains information about the file system on a FAT32 volume. This structure is implemented in Windows OEM Service Release 2 and later.
BIGFATBOOTFSINFO STRUC bfFSInf_Sig DD ? bfFSInf_free_clus_cnt DD ? bfFSInf_next_free_clus DD ? bfFSInf_resvd DD 3 DUP (?) BIGFATBOOTFSINFO ENDS
Table 4-6 BIGFATBOOTFSINFO Members
Member Name |
Description |
---|---|
bfFSInf_Sig |
The signature of the file system information sector. The value in this member is FSINFOSIG (0x61417272L). |
bfFSInf_free_clus_cnt |
The count of free clusters on the drive. Set to -1 when the count is unknown. |
bfFSInf_next_free_clus |
The cluster number of the cluster that was most recently allocated. |
bfFSInf_resvd |
Reserved member. |
On all FAT drives, there may be multiple copies of the FAT. If an error occurs reading the primary copy, the file system will attempt to read from the backup copies. On FAT16 and FAT12 drives, the first FAT is always the primary copy and any modifications will automatically be written to all copies. However, on FAT32 drives, FAT mirroring can be disabled and a FAT other than the first one can be the primary (or "active") copy of the FAT.
Mirroring is enabled by clearing bit 0x0080 in the extdpb_flags member of a FAT32 Drive Parameter Block () structure.
Table 4-7 FAT Mirroring
Mirroring |
Description |
---|---|
When Enabled (bit 0x0080 clear) |
With mirroring enabled, whenever a FAT sector is written, it will also be written to every other FAT. Also, a mirrored FAT sector can be read from any FAT. A FAT32 drive with multiple FATs will behave the same as FAT16 and FAT12 drives with multiple FATs. That is, the multiple FATs are backups of each other. |
When Disabled (bit 0x0080 set) |
With mirroring disabled, only one of the FATs is active. The active FAT is the one specified by bits 0 through 3 of the extdpb_flags member of . The other FATs are ignored. Disabling mirroring allows better handling of a drive with a bad sector in one of the FATs. If a bad sector exists, access to the damaged FAT can be completely disabled. Then, a new FAT can be built in one of the inactive FATs and then made accessible by changing the active FAT value in extdpb_flags. |
The DPB was extended to include FAT32 information. Changes are effective for Windows 95 OEM Service Release 2 and later.
DPB STRUC dpb_drive DB ? dpb_unit DB ? dpb_sector_size DW ? dpb_cluster_mask DB ? dpb_cluster_shift DB ? dpb_first_fat DW ? dpb_fat_count DB ? dpb_root_entries DW ? dpb_first_sector DW ? dpb_max_cluster DW ? dpb_fat_size DW ? dpb_dir_sector DW ? dpb_reserved2 DD ? dpb_media DB ? ifdef NOTFAT32 dpb_first_access DB ? else dpb_reserved DB ? endif dpb_reserved3 DD ? dpb_next_free DW ? dpb_free_cnt DW ? ifndef NOTFAT32 extdpb_free_cnt_hi DW ? extdpb_flags DW ? extdpb_FSInfoSec DW ? extdpb_BkUpBootSec DW ? extdpb_first_sector DD ? extdpb_max_cluster DD ? extdpb_fat_size DD ? extdpb_root_clus DD ? extdpb_next_free DD ? endif DPB ENDS
Table 4-8 DBP Members
Member Name |
Description |
---|---|
dpb_drive |
The drive number (0 = A, 1 = B, and so on). |
dpb_unit |
Specifies the unit number. The device driver uses the unit number to distinguish the specified drive from the other drives it supports. |
dpb_sector_size |
The size of each sector, in bytes. |
dpb_cluster_mask |
The number of sectors per cluster minus 1. |
dpb_cluster_shift |
The number of sectors per cluster, expressed as a power of 2. |
dpb_first_fat |
The sector number of the first sector containing the file allocation table (FAT). |
dpb_fat_count |
The number of FATs on the drive. |
dpb_root_entries |
The number of entries in the root directory. |
dpb_first_sector |
The sector number of the first sector in the first cluster. |
dpb_max_cluster |
The number of clusters on the drive plus 1. This member is undefined for FAT32 drives. |
dpb_fat_size |
The number of sectors occupied by each FAT. The value of zero indicates a FAT32 drive. Use the value in extdpb_fat_size instead. |
dpb_dir_sector |
The sector number of the first sector containing the root directory. This member is undefined for FAT32 drives. |
dpb_reserved2 |
Reserved member. Do not use. |
dpb_media |
Specifies the media descriptor for the medium in the specified drive. |
reserved |
Reserved member. Do not use. |
dpb_first_access |
Indicates whether the medium in the drive has been accessed. This member is initialized to -1 to force a media check the first time this DPB is used. |
dpb_reserved3 |
Reserved member. Do not use. |
dpb_next_free |
The cluster number of the most recently allocated cluster. |
dpb_free_cnt |
The number of free clusters on the medium. This member is 0FFFFh if the number is unknown. |
extdpb_free_cnt_hi |
The high word of free count. |
extdpb_flags |
Flags describing the drive. The low 4 bits of this value contain the 0-based FAT number of the Active FAT. This member can contain a combination of the following values. |
Value |
Description |
BGBPB_F_ActiveFATMsk (000Fh) |
Mask for low four bits. |
BGBPB_F_NoFATMirror (0080h) |
Do not mirror active FAT to inactive FATs. |
Bits 4-6 and 8-15 are reserved. | |
extdpb_FSInfoSec |
The sector number of the file system information sector. This member is set to 0FFFFh if there is no FSINFO sector. Otherwise, this value must be non-zero and less than the reserved sector count. |
extdpb_BkUpBootSec |
The sector number of the backup boot sector. This member is set to 0FFFFh if there is no backup boot sector. Otherwise, this value must be non-zero and less than the reserved sector count. |
extdpb_first_sector |
The first sector of the first cluster. |
extdpb_max_cluster |
The number of clusters on the drive plus 1. |
extdpb_fat_size |
The number of sectors occupied by the FAT. |
extdpb_root_clus |
The cluster number of the first cluster in the root directory. |
extdpb_next_free |
The number of the cluster that was most recently allocated. |
The following table displays all valid partition types and their corresponding values for use in the Part_FileSystem member of the structure.
Table 4-9 Partition Type Values
Value |
Description |
---|---|
PART_UNKNOWN (00h) |
Unknown |
PART_DOS2_FAT (01h) |
12-bit FAT |
PART_DOS3_FAT (04h) |
16-bit FAT. Partitions smaller than 32MB. |
PART_EXTENDED (05h) |
Extended MS-DOS Partition |
PART_DOS4_FAT (06h) |
16-bit FAT. Partitions larger than or equal to 32MB. |
PART_DOS32 (0Bh) |
32-bit FAT. Partitions up to 2047GB. |
PART_DOS32X (0Ch) |
Same as PART_DOS32 (0Bh), but uses Logical Block Address Int 13h extensions. |
PART_DOSX13 (0Eh) |
Same as PART_DOS4_FAT (06h), but uses Logical Block Address Int 13h extensions. |
PART_DOSX13X (0Fh) |
Same as PART_EXTENDED (05h), but uses Logical Block Address Int 13h extensions. |
Note
Values for head and track are 0-based. Sector values are 1-based. This structure is implemented in Windows OEM Service Release 2 and later.
s_partition STRUC Part_BootInd DB ? Part_FirstHead DB ? Part_FirstSector DB ? Part_FirstTrack DB ? Part_FileSystem DB ? Part_LastHead DB ? Part_LastSector DB ? Part_LastTrack DB ? Part_StartSector DD ? Part_NumSectors DD ? s_partition ENDS
Member Name |
Description |
---|---|
Part_BootInd |
Specifies whether the partition is bootable or not. This value could be set to PART_BOOTABLE (80h), or PART_NON_BOOTABLE(00h). The first partition designated as PART_BOOTABLE is the boot partition. All others are not. Setting multiple partitions to PART_BOOTABLE will result in boot errors. |
Part_FirstHead |
The first head of this partition. This is a 0-based number representing the offset from the beginning of the disk. The partition includes this head. |
Part_FirstSector |
The first sector of this partition. This is a 1-based, 6-bit number representing the offset from the beginning of the disk. The partition includes this sector. Bits 0 through 5 specify the 6-bit value; bits 6 and 7 are used with the Part_FirstTrack member. |
Part_FirstTrack |
The first track of this partition. This is an inclusive 0-based, 10-bit number that represents the offset from the beginning of the disk. The high 2 bits of this value are specified by bits 6 and 7 of the Part_FirstSector member. |
PartFileSystem |
Specifies the file system for the partition. The following are acceptable values: |
Value |
Description |
PART_UNKNOWN(00h) |
Unknown. |
PART_DOS2_FAT(01h) |
12-bit FAT. |
PART_DOS3_FAT(04h) |
16-bit FAT. Partition smaller than 32MB. |
PART_EXTENDED(05h) |
Extended MS-DOS Partition. |
PART_DOS4_FAT(06h) |
16-bit FAT. Partition larger than or equal to 32MB. |
PART_DOS32(0Bh) |
32-bit FAT. Partition up to 2047GB. |
PART_DOS32X(0Ch) |
Same as PART_DOS32(0Bh), but uses Logical Block Address Int 13h extensions. |
PART_DOSX13(0Eh) |
Same as PART_DOS4_FAT(06h), but uses Logical Block Address Int 13h extensions. |
PART_DOSX13X(0Fh) |
Same as PART_EXTENDED(05h), but uses Logical Block Address Int 13h extensions. |
Part_LastHead |
The last head of the partition. This is a 0-based number that represents the offset from the beginning of the disk. The partition includes the head specified by this member. |
Part_LastSector |
The last sector of this partition. This is a 1-based, 6-bit number representing offset from the beginning of the disk. The partition includes the sector specified by this member. Bits 0 through 5 specify the 6-bit value; bits 6 and 7 are used with the Part_LastTrack member. |
Part_LastTrack |
The last track of this partition. This is a 0-based, 10-bit number that represents offset from the beginning of the disk. The partition includes this track. The high 2 bits of this value are specified by bits 6 and 7 of the Part_LastSector member. |
Part_StartSector |
Specifies the 1-based number of the first sector on the disk. This value may not be accurate for extended partitions. Use the Part_FirstSector value for extended partitions. |
Part_NumSectors |
The 1-based number of sectors in the partition. |