How MS-DOS 6.22 SUBST Creates Virtual Drives
The MS-DOS 6.22 SUBST command creates virtual drive
letters by associating an unused drive letter with a local directory
path. Instead of creating physical partitions or mounting disk images,
MS-DOS achieves this redirection entirely in memory by modifying an
internal kernel table called the Current Directory Structure (CDS). This
article explains the internal mechanics of how MS-DOS registers a
substituted drive, resolves file operations directed at it, and handles
the limitations of virtual drives.
The Role of the Current Directory Structure (CDS)
At boot time, MS-DOS allocates an internal array of structures known
as the Current Directory Structure (CDS). By default, this array
contains enough slots for drives up to the limit specified by the
LASTDRIVE directive in CONFIG.SYS (defaulting
to drive E: if unspecified).
Each entry in the CDS table corresponds to a specific drive letter and contains critical metadata:
- Current Path: A null-terminated ASCII string (up to 67 characters in MS-DOS 6.22) representing the absolute current working path for that drive.
- Flags Word: A 16-bit bitmask defining the
properties of the drive. Key bits include whether the drive is a
physical drive, a network redirection, or a local
SUBSTdrive. - DPB Pointer: A 32-bit pointer to the Drive Parameter Block (DPB) for the underlying physical device, or a null pointer if unassigned.
- Redirection Offsets: Internal offsets used to split path resolution between virtual and physical references.
Execution and Kernel Registration
When a user executes a command such as
SUBST X: C:\PROJECTS, the SUBST.EXE utility
performs the following sequence:
- Parameter Validation: The utility verifies that the
target drive letter (X:) is within the range defined by
LASTDRIVEand is not already in use. It also verifies that the target source path (C:\PROJECTS) exists. - Accessing DOS Internals:
SUBSTretrieves the base address of the CDS table, traditionally found via the DOS "List of Lists" pointer retrieved viaINT 21h, AH=52h. - Modifying the Target CDS Entry: Once the CDS slot
for the virtual drive is located, the command:
- Copies the full, qualified path of the target directory into the drive's path buffer.
- Sets bit 14 (the
SUBSTflag,0x4000) and clears incompatible flags (such as network or physical drive bits) in the entry's flags word. - Sets the root path offset, pointing to the end of the base directory path so MS-DOS knows where relative subdirectories begin.
Path Resolution During File I/O
When a program requests a file operation (such as OPEN,
READ, or WRITE via INT 21h)
referencing the virtual drive:
- CDS Inspection: The MS-DOS kernel looks up the entry for the requested drive letter in the CDS array.
- Flag Detection: The kernel checks the flags word. If bit 14 is set, the kernel recognizes that the drive is a substitution.
- Path Translation: The kernel concatenates the base
path stored in the virtual drive's CDS entry with the relative path
requested by the application. For example, if
X:points toC:\PROJECTS, a request forX:\DATA\FILE.TXTis rewritten internally toC:\PROJECTS\DATA\FILE.TXT. - Physical Dispatch: The request is then processed through the physical drive's Drive Parameter Block (DPB) and standard block device drivers.
Deletion and System Safeguards
Running SUBST X: /D clears the virtual drive. The
utility resets the CDS entry's flags word, removes the path string, and
marks the slot as invalid or unassigned, freeing the letter for future
use.
Because SUBST drives do not possess their own file
allocation tables or BIOS parameter blocks, low-level disk utilities
(such as FORMAT, CHKDSK, FDISK,
and DEFRAG) inspect the CDS flags before execution. If the
SUBST bit is detected, these utilities abort the operation
to prevent file system corruption on the underlying physical drive.