MS-DOS 6.22 Directory Listing on Empty FAT Partitions
When MS-DOS 6.22 processes a directory listing request on an empty
FAT12 or FAT16 partition, it queries the drive's Drive Parameter Block
(DPB), reads the root directory table from a fixed disk sector, scans
the initial 32-byte directory entries, and calculates remaining capacity
from the File Allocation Table. Because an empty partition marks the
very first file entry with an end-of-directory marker
(0x00), the operating system aborts file traversal almost
immediately, reporting zero files while computing total available disk
space.
Command Execution and the Interrupt 21h Interface
When a user executes the DIR command, the internal
command processor COMMAND.COM issues system calls to the
MS-DOS kernel via INT 21h. To gather the entries, it
utilizes:
- AH = 4Eh (Find First File): Initiates a search
matching the standard
*.*wildcard mask. - AH = 4Fh (Find Next File): Continues the search until all entries are exhausted.
- AH = 36h (Get Free Disk Space): Retrieves allocation unit geometry to report free bytes.
Locating the Root Directory via the Drive Parameter Block
Unlike subdirectories, which are dynamic cluster chains, the root directory on FAT12 and FAT16 partitions resides at a fixed physical location immediately following the File Allocation Tables.
MS-DOS 6.22 references the Drive Parameter Block (DPB) stored in low memory, which was initialized during system boot from the partition's BIOS Parameter Block (BPB). The DPB dictates:
- The logical sector number where the root directory starts.
- The fixed number of 32-byte directory entries allocated (typically 512 entries on standard FAT16 hard disks).
Sector Buffering and Entry Evaluation
MS-DOS reads the first sector of the root directory into one of its
internal disk buffers (configured via BUFFERS= in
CONFIG.SYS). It then reads the 32-byte structures
sequentially:
- Volume Label Inspection: The operating system
checks for an entry flagged with the Volume Label attribute
(
0x08). If the disk was formatted with a label, this entry occupies the first slot. MS-DOS extracts the string for the header output (Volume in drive X is ...) and advances to the next entry. - End-of-Directory Evaluation: On an empty formatted
partition, the first non-label entry begins with a null byte
(
0x00). In the FAT filesystem specification, a leading0x00indicates that the entry is unused and that no populated entries exist beyond it. - Search Termination: Because the byte is
0x00, the MS-DOS kernel immediately terminates the search. It does not read any remaining sectors reserved for the root directory, saving I/O cycles.INT 21h, AH=4Ehreturns an error code (typically Error02hor12h, "No more files").
Computing Free Space via the FAT
After COMMAND.COM determines that no file records match
the query, it calculates free storage:
- The DOS kernel reads the File Allocation Table (FAT).
- It counts the number of clusters containing the value
0x000(FAT12) or0x0000(FAT16), representing unallocated disk blocks. - This cluster count is multiplied by the sectors per cluster and bytes per sector values retrieved from the DPB.
Final Screen Output Formatting
With the scan terminated and disk capacity verified,
COMMAND.COM formats the output stream sent to standard
output (CON):
- Prints the volume label and volume serial number.
- Prints the directory path string
(
Directory of X:\). - Depending on whether flags like
/Wor standard layout are used, it outputsFile not foundor lists0 file(s) 0 bytes. - Appends the final summary footer indicating the total free byte count on the partition.