Skip to content

Init disk only follows one extended partition, even if both type 5 and type 15 present #209

@ecm-pushbx

Description

@ecm-pushbx

It seems that the kernel will only follow one extended partition chain per HDD unit. This is true even if the extended partitions have different types, ie one is type 5 (old DOS / CHS) and the other is type 15 (new DOS or MSW / LBA). The code that finds extended partitions is in:

kernel/kernel/initdisk.c

Lines 1142 to 1168 in 032523a

/* scan for extended partitions now */
PartitionsToIgnore = 0;
for (iPart = 0; iPart < 4; iPart++)
{
if (IsExtPartition(PTable[iPart].FileSystem))
{
RelSectorOffset = ExtendedPartitionOffset + PTable[iPart].RelSect;
if (ExtendedPartitionOffset == 0) /* first extended in chain? */
{
ExtendedPartitionOffset = PTable[iPart].RelSect;
/* grand parent LBA -> all children and grandchildren LBA */
ExtLBAForce = (PTable[iPart].FileSystem == EXTENDED_LBA);
}
num_extended_found++;
if (num_extended_found > 30)
{
printf("found more then 30 extended partitions, terminated\n");
return 0;
}
goto ReadNextPartitionTable;
}
}

Here's how to test this. Uses the bootimg.asm and partdisk.asm scripts (needs NASM and lmacros) to create two dosemu2-format disk images with multiple partitions. Then runs dosemu2 with the additional images, which will log in the additional drive letters beyond the drives C: and D: used by dosemu2.

Preparation, creating small file system images:

for label in hdb1 hdb4 hdb5 hdb6 hda1_ccc hda2_ddd hda5_fff hda4_eee hda6_ggg hda7_hhh
do
  echo "$label" > "$label.id"
  nasm -I ../lmacros/ bootimg.asm \
  -D_PAYLOADFILE=::empty,::label,"'${label^^}'","$label.id",::rename,"$label.id",part.id \
  -D_SPC=1 -D_BPE=16 -D_SPI=38000 -D_SPF=148 -D_ALIGNDATA -D_NUMROOT=512 \
  -D_CHS_HEADS=255 -D_CHS_SECTORS=63 -D_UNIT=80h -D_MEDIAID=0F8h \
  -D_DEFAULT_LABEL="'${label^^}'" -o "$label.prt" -D_FULL=0
done

Create first HDD image: bootimg$ nasm -I ../lmacros/ partdisk.asm -o partdisk.img -D_CHS_HEADS=16 -D_PAYLOAD=::primary,80h,20M,fat16_chs,hda1_ccc.prt,::primary,0,20M,fat16_chs,hda2_ddd.prt,::extended,41M,extended_chs,::logical,20M,fat16_chs,hda5_fff.prt,::extended,max,extended_chs,::logical,20M,fat16_chs,hda6_ggg.prt,::up,::up,::primary,0,20M,fat16_chs,hda4_eee.prt -D_MBR_DOSEMU_IMAGE_HEADER && file partdisk.img

Create second HDD image: bootimg$ nasm -I ../lmacros/ partdisk.asm -o partdis2.img -D_CHS_HEADS=16 -D_PAYLOAD=::slot,4,::primary,1,20M,fat16_chs,hdb4.prt,::primary,0,20M,fat16_chs,hdb1.prt,::extended,21M,extended_chs,::logical,20M,fat16_chs,hdb5.prt,::up,::extended,21M,extended,::logical,20M,fat16_chs,hdb6.prt,::up -D_MBR_DOSEMU_IMAGE_HEADER && file partdis2.img

Run dosemu2 with both HDD images: (Part of the pathnames redacted here.)

~/local.new/bin/dosemu -I "serial { com 2 device /tmp/vptty-dos }" \
  -I "floppy { device disktest.img }" -dumb -td -kt -D+9d+9x \
  -I "umb_a0 off" -I "disk { hdimage [...]/proj/bootimg/partdisk.img }" \
  -I "disk { hdimage [...]/proj/bootimg/partdis2.img }"; stty sane

Test output, depicting that only a single logical partition of partdis2.img is accessible. That's "hdb5", so the kernel preferred the first extended partition (here type 5) and did not log in the second extended partition (here type 15) with "hdb6".

&; Welcome to lDebug!
Press any key to enter debugger terminal!
Timer stopped
V0=000000A9 V1=00000000 V2=00000000 V3=00000000  DCO=00000000 DCS=00000000
V4=00000000 V5=00000000 V6=00000000 V7=00000000  DAO=0000F007 DAS=0000F007
V8=00000000 V9=00000000 VA=00000000 VB=00000000  DIF=0180F008 DPI=0000:0000
VC=00000000 VD=00000000 VE=00000000 VF=00000000  DPR=7681     DPP=0000
Current mode: Virtual 86 Mode
-fred
-q
123
FreeDOS kernel - GIT (build 2043 OEM:0xfd) [compiled Mar 17 2025]
Kernel compatibility 7.10 - GNUC - 808x compatible - FAT32 support

(C) Copyright 1995-2023 Pasquale J. Villani and The FreeDOS Project.
All Rights Reserved. This is free software and comes with ABSOLUTELY NO
WARRANTY; you can redistribute it and/or modify it under the terms of the
GNU General Public License as published by the Free Software Foundation;
either version 2, or (at your option) any later version.
C: HD1, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=  2000 MB
D: HD2, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=  2000 MB
E: HD3, Pri[ 1], CHS=    0-1-1, start=     0 MB, size=    19 MB
F: HD3, Ext[ 1], CHS=   78-1-1, start=    38 MB, size=    19 MB
G: HD3, Ext[ 2], CHS=  117-1-1, start=    57 MB, size=    19 MB
H: HD3, Pri[ 2], CHS=   39-0-1, start=    19 MB, size=    19 MB
I: HD3, Pri[ 4], CHS=  158-0-1, start=    77 MB, size=    19 MB
J: HD4, Pri[ 4], CHS=    0-1-1, start=     0 MB, size=    19 MB
K: HD4, Ext[ 1], CHS=   78-1-1, start=    38 MB, size=    19 MB
L: HD4, Pri[ 1], CHS=   39-0-1, start=    19 MB, size=    19 MB
dosemu XMS 3.0 & UMB support enabled
EMUFS host file and print access available
dosemu EMS driver rev 0.9 installed.
dosemu CDROM driver installed (V0.2)
Kernel: allocated 32 Diskbuffers = 17024 Bytes in HMA
emufs: redirector enabled

FreeCom version 0.87 - GNUC - XMS_Swap [Feb 21 2025 23:30:19]
SEEKEXT 1.22: high loaded using 432 byte, on multiplex 00h.
emufs: redirector enabled
Welcome to dosemu2!
    Build 2.0pre9-dev-20240420-1892-g6a2f4f527
C:\>dir k:
 Volume in drive K is HDB5
 Volume Serial Number is 0000-0000
 Directory of K:\

HDB5     ID              5  00-00-80 12:00a
PART     ID              5  00-00-80 12:00a
         2 file(s)             10 bytes
         0 dir(s)      19,282,944 bytes free
C:\>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions