How MS-DOS 6.22 Marks Bad Sectors in the FAT
MS-DOS 6.22 relies on the File Allocation Table (FAT) file system—typically FAT12 for floppy disks and FAT16 for hard drives—to track disk storage and handle media defects. When the operating system identifies physically damaged or unreadable sectors, it flags the entire parent cluster containing those sectors directly within the allocation table using a reserved hexadecimal value. This article explains how MS-DOS 6.22 detects bad sectors, writes the corresponding values to both copies of the FAT, updates file chains, and prevents future read and write operations on unreliable media areas.
The Allocation Unit and Cluster-Level Tagging
In MS-DOS 6.22, disk storage is divided into clusters, which are fixed groups of contiguous sectors (typically ranging from 512 bytes to 32 kilobytes). The operating system does not allocate or isolate individual 512-byte sectors within the file system; instead, it tracks media health at the cluster level. If even a single sector within a cluster fails a Cyclic Redundancy Check (CRC) or read verification test, MS-DOS marks the entire cluster as unusable.
The Bad Cluster Marker Values
Each entry in the File Allocation Table maps directly to a specific cluster number on the drive. To prevent the DOS kernel from writing data to damaged media, a reserved marker is written directly into that cluster's entry:
- FAT12: The value
0xFF7is written to the 12-bit entry. - FAT16: The value
0xFFF7is written to the 16-bit entry.
When the MS-DOS input/output system searches the FAT for available
storage (represented by 0x0000), it interprets the
0xFFF7 code as a defective cluster and immediately skips it
during the allocation sequence.
Detection and Marking by Utilities
MS-DOS 6.22 primarily relies on two disk utilities to discover defects and update the FAT:
- FORMAT: During a standard format, the utility
attempts to read and verify every sector on the partition. When a read
error occurs,
FORMATflags the corresponding cluster entry in the FAT as0xFFF7. These entries are preserved so that subsequent operations know to avoid them from the moment the file system is created. - SCANDISK: MS-DOS 6.22 introduced
SCANDISKas the default diagnostic utility, replacing the older surface-scan capabilities ofCHKDSK. WhenSCANDISKperforms a surface scan and encounters an unreadable sector:- If the cluster is unallocated, it simply writes
0xFFF7into the FAT. - If the cluster is currently occupied by a file,
SCANDISKreads whatever data can still be salvaged, copies that data to a newly allocated healthy cluster, adjusts the file's allocation chain in the FAT to point to the new cluster, and then marks the original defective cluster with0xFFF7.
- If the cluster is unallocated, it simply writes
Synchronization of Primary and Secondary FATs
To safeguard against file system corruption, FAT file systems
maintain two identical copies of the table: FAT1 (primary) and FAT2
(backup), located consecutively near the start of the partition.
Whenever a utility marks a bad cluster with 0xFFF7, the
change is mirrored immediately across both FAT tables. This ensures that
if the operating system or a repair utility references FAT2, the bad
cluster remains flagged and out of circulation.
Persistence of Bad Sector Flags
Once a cluster is marked as 0xFFF7, MS-DOS treats the
mark as permanent. Standard file operations (copying, moving, or
deleting) will not overwrite or clear this entry. The cluster remains
removed from the total pool of available disk space reported by commands
such as DIR and CHKDSK until a low-level
format is performed or a specialized disk utility explicitly tests and
clears the cluster marker.