FreeDOS And Multiple Extended Partitions: A Kernel Limitation
This article explores a specific behavior in the FreeDOS kernel related to how it handles extended partitions. It seems the kernel is designed to follow only one extended partition chain per HDD unit, a behavior that persists even when extended partitions are of different types (specifically type 5 for old DOS/CHS and type 15 for new DOS/MSW/LBA). Let's dive into the details and understand the implications of this behavior.
The Issue: One Extended Partition Chain at a Time
In the FreeDOS kernel, a limitation exists where it only processes one extended partition chain per hard drive. This means that even if you have multiple extended partitions defined with different types (e.g., type 5 and type 15), the kernel will only recognize and follow one of them. This can lead to some partitions being inaccessible, which can be a significant problem if you're trying to manage multiple logical drives across different extended partitions. Understanding this limitation is crucial for anyone working with FreeDOS and complex disk partitioning schemes.
The core of the issue lies in the initdisk.c
file within the FreeDOS kernel source code, specifically in the section responsible for detecting and handling extended partitions. The code appears to be designed to identify and process one chain of extended partitions, but it doesn't account for scenarios where multiple chains might exist. This limitation is not necessarily a bug, but more of a design choice or an oversight given the historical context of DOS and early PC operating systems. These systems often had simpler partitioning needs, and the complexity of handling multiple extended partitions might not have been a priority. However, in modern scenarios where users might want to maximize their disk space and organization by using multiple extended partitions, this limitation can become a significant hurdle. This behavior can lead to unexpected outcomes, especially when dealing with older disk images or configurations that predate the widespread use of LBA and large drives. It is important to consider this limitation when setting up disk images or physical drives for use with FreeDOS, as it can directly impact the visibility and accessibility of your data. For users who need to utilize multiple extended partitions, alternative strategies or workarounds might be necessary, such as using a different operating system or modifying the kernel itself.
How to Test and Verify the Behavior
To demonstrate this behavior, a test case has been developed using bootimg.asm
and partdisk.asm
scripts. These scripts, along with NASM and lmacros
, allow the creation of dosemu2-format disk images with multiple partitions. By running dosemu2 with these images, we can observe how the kernel handles multiple extended partitions. The test setup involves creating two virtual hard drives, each with its own set of partitions, including multiple extended partitions. This allows us to specifically examine how the FreeDOS kernel enumerates and assigns drive letters to these partitions.
The first step in testing this behavior involves creating small file system images for each partition. This is achieved using a loop that generates images with unique labels, which helps in identifying the partitions later. The bootimg.asm
script is used with specific parameters to define the size, layout, and other characteristics of each partition image. These parameters include the number of sectors per cluster, bytes per sector, and other low-level details that define the file system structure. The -D
flags in the nasm
command are used to define various constants and settings, such as the label of the partition, the number of root directory entries, and the CHS (Cylinder, Head, Sector) geometry. This step is crucial in setting up the individual partitions that will later be assembled into larger disk images. Each image is created with a unique label, such as hdb1
, hdb4
, etc., which are then embedded into the file system. This labeling allows us to easily identify each partition when they are mounted in dosemu2. The nasm
command compiles the assembly code in bootimg.asm
and generates a binary image file (.prt
) for each partition. These .prt
files serve as the building blocks for the larger disk images that will be used to test the FreeDOS kernel's extended partition handling.
Creating the HDD Images
Two HDD images are created using the partdisk.asm
script. The first image, partdisk.img
, is created with a combination of primary and extended partitions, including logical drives within the extended partitions. The second image, partdis2.img
, is designed to have two extended partitions, one of type 5 and another of type 15, to specifically test the kernel's behavior when encountering multiple extended partitions of different types. These images are constructed by defining a payload that specifies the layout and characteristics of each partition. The ::primary
, ::extended
, and ::logical
directives in the nasm
command define the types of partitions, their sizes, and their positions on the disk. The _CHS_HEADS
parameter sets the number of heads for the disk geometry, which affects how the disk is addressed. The _PAYLOAD
parameter defines the sequence of partitions that will be created, including their types, sizes, and the .prt
files that will be used as their content. This approach allows for precise control over the disk layout and the types of partitions that are created. The -D_MBR_DOSEMU_IMAGE_HEADER
flag ensures that the images are created in a format that is compatible with dosemu2. Once the images are created, the file
command is used to verify their format and characteristics. This step helps to ensure that the images are correctly created and can be used for testing.
Running dosemu2 with the Images
dosemu2 is then run with both HDD images attached. The command line includes several options to configure dosemu2, such as serial port settings, floppy disk images, and display settings. The -I
options are used to include configuration settings for serial ports, floppy disks, and hard disk images. The -dumb
, -td
, and -kt
options set the terminal type, disable timers, and disable keyboard translation, respectively. The -D+9d+9x
option enables debugging output, which is crucial for observing how the kernel detects and handles the partitions. The umb_a0 off
option disables Upper Memory Block (UMB) usage at address A000h, which can sometimes conflict with other drivers or programs. The disk
options specify the hard disk images to be used, and the pathnames are redacted for brevity. The stty sane
command is used to reset the terminal settings after dosemu2 exits. This command configures dosemu2 to use the created disk images as virtual hard drives. By running dosemu2 with these images, we can observe how the FreeDOS kernel enumerates the partitions and assigns drive letters. The debugging output and the drive letter assignments provide valuable insights into the kernel's behavior when dealing with multiple extended partitions.
Interpreting the Test Output
The test output clearly shows that only one logical partition from partdis2.img
is accessible. Specifically, only