How MS-DOS 6.22 Calculates Free Disk Space

When you run the DIR command in MS-DOS 6.22, the operating system does not read a single stored "free space" metadata value from the disk. Instead, it queries the underlying FAT (File Allocation Table) file system structure via a specific MS-DOS system interrupt, determines how many allocation units (clusters) are currently marked as unused, and multiplies that count by the cluster's byte size to display the final available space.

The System Call: INT 21h, Function 36h

At the software level, the internal DIR routine inside COMMAND.COM requests drive metrics by invoking Interrupt 21h, Function 36h (Get Free Disk Space). The command loads the target drive number into the DL register and issues the interrupt.

The DOS kernel processes this call and returns four critical values in the CPU registers:

  • AX: Sectors per cluster
  • BX: Number of available (free) clusters
  • CX: Bytes per sector (standardly 512 bytes)
  • DX: Total number of clusters on the drive

If the drive designation is invalid, AX returns 0FFFFh. Otherwise, MS-DOS performs 32-bit arithmetic to calculate the final byte count:

\[\text{Free Bytes} = \text{Free Clusters (BX)} \times \text{Sectors Per Cluster (AX)} \times \text{Bytes Per Sector (CX)}\]

How the DOS Kernel Finds Free Clusters

MS-DOS 6.22 relies on FAT12 (for floppy disks and partitions smaller than 16 MB) and FAT16 (for larger hard disk partitions up to 2 GB).

Unlike modern file systems or FAT32 (which was introduced later in Windows 95 OSR2 with an FSInfo sector), standard FAT12 and FAT16 do not permanently store a dedicated counter of free clusters on disk. To obtain the value for the BX register, the kernel does the following:

  1. Reading the Drive Parameter Block (DPB): When a disk is mounted, MS-DOS reads the disk's Boot Sector (specifically the BIOS Parameter Block, or BPB) to construct an in-memory structure called the Drive Parameter Block. The DPB tracks geometry, cluster sizes, and FAT locations.
  2. Scanning the Allocation Table: To determine free space initially, MS-DOS traverses the File Allocation Table itself. The FAT is an array of entries where each entry corresponds to a physical cluster on the drive.
    • An entry containing 0000h signifies an unallocated (free) cluster.
    • Any other value represents a pointer to the next cluster in a file, a bad sector marker (FFF7h), or an end-of-file marker (FFF8h–FFFFh).
  3. In-Memory Tracking: To avoid reading the entire FAT off the physical disk every time DIR is executed, MS-DOS caches FAT sectors and maintains a running counter of free clusters inside the internal DPB structure in RAM. When files are written, extended, or deleted, MS-DOS updates this internal counter dynamically.

Output Formatting

Once COMMAND.COM receives the raw values from INT 21h Function 36h, it formats the calculated free byte figure using the active locale settings (adding thousands separators, such as commas in US versions) and prints the familiar summary line at the bottom of the directory listing:

       x file(s)        xxx,xxx bytes
       x dir(s)   xx,xxx,xxx bytes free