A logical drive has the following general format:
Data area | Description |
Hidden sectors | Although any logical drive can have hidden sectors, these sectors are usually associated with disks that can be divided into partitions. If a disk has partitions, its first hidden sector contains a table of PARTENTRY structures, each specifying the size and location of the physical sectors in a single partition. The table is placed at the end of the sector. For a full description of the PARTENTRY structure, see Section 3.9, “Structures.” |
Reserved sectors | A logical drive can have any number of reserved sectors but usually has only one, called the startup sector. The startup sector contains the MS-DOS startup program and information that defines the size and format of the disk. The sector ends with the startup-sector signature, 0AA55h, stored in the last 2 bytes. |
File allocation table | The file allocation table (FAT) is an array used by MS-DOS to keep track of which clusters on a drive have been allocated for each file or directory. As a program creates a new file or adds to an existing one, the system allocates sectors for that file, writes the data to the given sectors, and keeps track of the allocated sectors by recording them in the FAT. To conserve space and speed up record-keeping, each record in the FAT corresponds to two or more consecutive sectors (called a cluster). The number of sectors in a cluster depends on the type and capacity of the drive but is always a power of 2. |
Every logical drive has at least one FAT, and most drives have two, one serving as a backup should sectors containing the other fail. The FAT immediately follows the startup sector and any other reserved sectors. | |
Root directory | Every volume has a root directory with entries that specify the volume's name, files, and other directories. |
File and directory space | All remaining space in the volume is reserved for files and additional directories. |
Depending on the number of clusters on the drive, the FAT consists of an array of either 12-bit or 16-bit entries. Drives with more than 4086 clusters have a 16-bit FAT; those with 4086 or fewer clusters have a 12-bit FAT.
The first two entries in a FAT (3 bytes for a 12-bit FAT and 4 bytes for a 16-bit FAT) are reserved. In most versions of MS-DOS, the first byte contains the media descriptor (the same descriptor provided in the DEVICEPARAMS structure) and the additional reserved bytes are set to 0FFh.
Each FAT entry represents a corresponding cluster on the drive. If the cluster is part of a file or directory, the entry contains either a marker specifying the cluster as the last in that file or directory, or an index pointing to the next cluster in the file or directory. If a cluster is not part of a file or directory, the entry contains a value indicating the cluster's status. The following table shows possible FAT entry values. The digit in parentheses represents the additional 4 bits of a 16-bit entry.
Value | Meaning |
(0)000h | Available cluster. |
(0)002h-(F)FEFh | Index of entry for the next cluster in the file or directory. Note that (0)001h does not appear in a FAT, since that value corresponds to the FAT's second reserved entry. Index numbering is based on the beginning of the FAT. |
(F)FF0h-(F)FF6h | Reserved; do not use. |
(F)FF7h | Bad sector in cluster; do not use cluster. |
(F)FF8h-(F)FFFh | Last cluster of file or directory. |
Each file and directory consists of one or more clusters, each cluster represented by a single entry in the FAT. The deStartCluster field in the DIRENTRY structure corresponding to the file or directory specifies the index of the first FAT entry for the file or directory. (For a full description of the DIRENTRY structure, see Section 3.9, “Structures.”) This entry contains 0(F)FFFh if there are no further FAT entries for that file or directory, or it contains the index of the next FAT entry for the file or directory. For example, the following segment of a 16-bit FAT shows the FAT entries for a file consisting of four clusters:
.
.
.
dw 0003h ; Cluster 2 points to cluster 3
dw 0005h ; Cluster 3 points to cluster 5
dw 0FFF7h ; Cluster 4 contains a bad sector
dw 0006h ; Cluster 5 points to cluster 6
dw 0FFFFh ; Cluster 6 is the last cluster for the file
dw 0 ; Clusters 7,8 and 9 are available
dw 0
dw 0
.
.
.