MS-DOS 6.22 Disk Block Allocation for Growing Files
This article explains how MS-DOS 6.22 manages disk storage when an existing file expands past its initial capacity. Utilizing the FAT16 file system, the operating system employs a linked-list structure via the File Allocation Table to dynamically search for free clusters, chain them to existing data, update directory metadata, and accommodate file fragmentation without moving existing data blocks.
The Role of Clusters and the File Allocation Table
MS-DOS 6.22 organizes disk data into allocation units called clusters. A cluster represents a fixed number of contiguous sectors (typically ranging from 512 bytes to 32 KB depending on disk partition size). Storage cannot be allocated in units smaller than a cluster, meaning every file operation reserves at least one full cluster regardless of the actual byte count.
Tracking which clusters belong to which files is handled by the File Allocation Table (FAT), specifically FAT16 on standard hard drives. The FAT is an array of 16-bit entries where each entry corresponds directly to a physical cluster on the disk.
The Dynamic Allocation Process
When an application appends data to a file that exceeds the remaining byte capacity of its current cluster, MS-DOS 6.22 performs the following sequence:
- Scanning the FAT for Free Space: The operating
system searches the FAT sequentially, starting from the beginning of the
table or near the current allocation pointer, looking for an entry with
a value of
0x0000, which designates an unallocated (free) cluster. - Updating the Cluster Chain: Once an available
cluster is identified, MS-DOS links it to the file. It takes the entry
corresponding to the file's current terminating cluster—which previously
held an End-of-File (EOF) marker (typically
0xFFFFor any value between0xFFF8and0xFFFF)—and overwrites it with the index number of the newly acquired cluster. - Marking the New End of File: In the FAT entry
corresponding to the newly allocated cluster, the operating system
writes the EOF marker (
0xFFFF), designating this cluster as the new end of the chain. - Updating the Directory Entry: MS-DOS updates the file’s 32-byte directory entry. While the "starting cluster" field in the directory entry remains pointing to the file's very first cluster, the 4-byte "file size" field is updated to reflect the new total size in bytes.
Fragmentation Handling
MS-DOS 6.22 does not require clusters assigned to a single file to be physically contiguous. If free clusters are scattered across the drive due to prior file deletions, the operating system simply links whatever free cluster it finds next into the FAT chain. This allows files to grow continuously without needing to relocate existing data, though it introduces file fragmentation, which can degrade read and write performance due to mechanical head movement.
Disk Full Conditions
If MS-DOS scans the entire FAT and cannot locate an entry with a
value of 0x0000, the disk is out of space. In this
scenario, the operating system halts the allocation process, leaves the
existing cluster chain intact with its original EOF marker, does not
commit the unwritten data, and returns a write error (such as
"Insufficient disk space") to the running application.