How MS-DOS 6.22 Calculates FAT16 Allocation Blocks
In MS-DOS 6.22, the allocation block (cluster) count for a FAT16 logical volume is calculated by parsing the volume's BIOS Parameter Block (BPB), subtracting all reserved and system overhead sectors from the total volume sector count, and dividing the remaining data sectors by the sectors-per-cluster value. This mathematical process establishes the exact number of usable data clusters, maps them to entries within the File Allocation Table, and determines whether the file system qualifies strictly as FAT16.
1. Extracting BIOS Parameter Block (BPB) Values
MS-DOS reads the volume's Boot Sector (logical sector 0) to retrieve specific fields from the BPB:
- Bytes Per Sector (
BPB_BytsPerSec): Typically 512 bytes. - Sectors Per Cluster (
BPB_SecPerClus): Must be a power of 2 (1, 2, 4, 8, 16, 32, or 64). - Reserved Sector Count
(
BPB_RsvdSecCnt): Sectors preceding the first FAT (typically 1 for FAT16). - Number of FATs (
BPB_NumFATs): Number of File Allocation Tables (standard is 2). - Root Directory Entry Count
(
BPB_RootEntCnt): Fixed count of 32-byte directory entries (standard is 512 on hard drives). - Total Sectors 16 (
BPB_TotSec16): Total sectors if the volume size is under 32 MB. - Total Sectors 32 (
BPB_TotSec32): Total sectors if the volume size is 32 MB or larger. - FAT Size 16 (
BPB_FATSz16): Size of a single FAT in sectors.
2. Determining Total Volume Sectors
MS-DOS selects the volume size based on the 16-bit and 32-bit total sector fields:
\[\text{TotalSectors} = \begin{cases} \text{BPB\_TotSec16}, & \text{if } \text{BPB\_TotSec16} \neq 0 \\ \text{BPB\_TotSec32}, & \text{otherwise} \end{cases}\]
3. Calculating System Overhead Sectors
Before calculating data storage capacity, MS-DOS computes the space consumed by system structures that precede the data area.
First, it calculates the space required by the fixed root directory:
\[\text{RootDirSectors} = \left\lfloor \frac{(\text{BPB\_RootEntCnt} \times 32) + (\text{BPB\_BytsPerSec} - 1)}{\text{BPB\_BytsPerSec}} \right\rfloor\]
For standard hard disks with 512 root entries and 512 bytes per sector: \[\text{RootDirSectors} = \frac{512 \times 32}{512} = 32 \text{ sectors}\]
Next, it calculates the total non-data overhead:
\[\text{OverheadSectors} = \text{BPB\_RsvdSecCnt} + (\text{BPB\_NumFATs} \times \text{BPB\_FATSz16}) + \text{RootDirSectors}\]
4. Computing the Usable Data Sectors
The space available for user data begins immediately after the root directory table:
\[\text{DataSectors} = \text{TotalSectors} - \text{OverheadSectors}\]
5. Calculating Total Allocation Blocks (Clusters)
MS-DOS divides the data sector pool by the cluster size, truncating any remainder:
\[\text{CountOfClusters} = \left\lfloor \frac{\text{DataSectors}}{\text{BPB\_SecPerClus}} \right\rfloor\]
Any fractional cluster left over at the end of the volume cannot be addressed and is discarded.
6. FAT16 Validation
MS-DOS 6.22 uses the calculated CountOfClusters to
verify the volume format. According to the FAT specification used by
MS-DOS:
- If \(\text{CountOfClusters} < 4,085\), the volume is mounted as FAT12.
- If \(4,085 \le \text{CountOfClusters} < 65,525\), the volume is mounted as FAT16.
- Any higher count is invalid in MS-DOS 6.22, as FAT32 support was not introduced until MS-DOS 7.10 (Windows 95 OSR2).
Usable clusters are indexed sequentially starting at Cluster 2 through \(\text{CountOfClusters} + 1\), because FAT entries 0 and 1 are reserved for media descriptors and end-of-chain markers.