====== MBR partitioning week ====== **2025-08-10** This week was all about working on MBR partitioning. ===== bootimg ===== The bootimg.asm script gained a companion, partdisk.asm. This script allows to create a hard disk image, either raw or with a dosemu image header. (The dosemu image header makes the CHS geometry explicit, avoiding misdetection by the application to access it.) The script's use of its _PAYLOAD define is described in a documentation comment at the top of the source text file. There are a number of example commands, all of which can be run by copying them and pasting into a bash shell. A number of alignment choices are currently hardcoded into the script: Logical and primary partitions start on a head boundary (ie CHS sector = 1) while extended partitions start on a cylinder boundary (ie CHS head = 0 and CHS sector = 1). All partitions end on a cylinder boundary (ie CHS head = maximum and CHS sector = maximum). The only absolutely needed alignment is extended partitions of type 5 accessible by MS-DOS (both v5 and v7) must start on a cylinder boundary. This includes nested extended partitions. As described once [[blog/pushbx/2024/0509_early_may_work_on_ms-dos_ldebug_etc#chs_tool_extension_for_ldebug|in the blog post introducing the chstool.eld]], the LBA start sector of a logical partition is based on the innermost extended partition in which it is found. MS-DOS adds the extended partition base as a cylinder number, after calculating a CHS tuple, requiring the EPBR be aligned on a cylinder boundary. (Of course, I changed lMS-DOS to not need that even when using CHS to access a disk.) The specific changesets: * [[https://hg.pushbx.org/ecm/bootimg/rev/069927dd6540|Add a ::label keyword]] to bootimg.asm, to allow placing a volume label in the root directory. This is needed for lMS-DOS to display a label. * [[https://hg.pushbx.org/ecm/bootimg/rev/d2f2804ed421|Initial commit]] of partdisk.asm * [[https://hg.pushbx.org/ecm/bootimg/rev/1dbc23703125|Add most examples]] to partdisk.asm * [[https://hg.pushbx.org/ecm/bootimg/rev/b140d5b920c5|Fix a command's indentation]] in the examples. * [[https://hg.pushbx.org/ecm/bootimg/rev/708fd9e7617a|Document bootimg.asm ::label keyword]]. * [[https://hg.pushbx.org/ecm/bootimg/rev/aa569fa10e4e|Add another example]] to partdisk.asm * [[https://hg.pushbx.org/ecm/bootimg/rev/cc6b362e2573|Comment more on the payload specification]] for partdisk.asm ===== scanptab ===== The scanptab and chstool.eld changes mostly concern adding modes to the partition table scan code. This is intended to eventually replace the partition table scan in lMS-DOS's msbio/msinit.nas, including the [[https://hg.pushbx.org/ecm/msdos4/file/8ab91deb67db/src/BIOS/msinit.nas#l3034|Do Mini]] and [[https://hg.pushbx.org/ecm/msdos4/file/8ab91deb67db/src/BIOS/msinit.nas#l3129|Find Mini Partition]] handlers. The following are the individual changes to scanptab. Note that each of the changes may require a matching revision of the chstool.eld be used. * Pass along to ELD table read function [[https://hg.pushbx.org/ecm/scanptab/rev/b2c2a3e340bd|whether the read is a first read or a reload read]]. (This is complicated later on by the multi-pass nature of the scanner.) * [[https://hg.pushbx.org/ecm/scanptab/rev/029b64c61486|Add declaration of most of the mode flags]], not used yet. * Implement the six mode flags that determine [[https://hg.pushbx.org/ecm/scanptab/rev/26bd3a42b617|whether an outermost extended partition is scanned]]. These are 2 bits per type, with the recognised types being 5 (old DOS / CHS), 15 (new DOS or MSW / LBA), and 85h (Linux / LBA). * Fix [[https://hg.pushbx.org/ecm/scanptab/rev/972079dae683|to skip ignored extended partitions properly]], do not treat them as logical partitions. * Implement the mode [[https://hg.pushbx.org/ecm/scanptab/rev/329f234a5660|to ignore subsequent nested extended partitions]]. Only a single chain of extended partitions per outermost extended partition is followed in this mode. * Add mode flag [[https://hg.pushbx.org/ecm/scanptab/rev/44dd0e13564f|to disable FAT32 support]]. (This must be mainly done by the callbacks of the main application that are called by the scanner. The same is true for the flag to disable LBA support.) * Implement mode [[https://hg.pushbx.org/ecm/scanptab/rev/a2463e6b86ba|to ignore subsequent logical partitions]]. This means that per EPBR at most one logical partition is processed. (This requires the application to set a certain flag once it recognises a logical partition.) * Fix [[https://hg.pushbx.org/ecm/scanptab/rev/7381b3baa1dd|to reset the subsequent logical partition flag]] when running the .replace code of the scanner. * Implement the mode [[https://hg.pushbx.org/ecm/scanptab/rev/5ce213cb8abd|to ignore subsequent primary partitions]]. (This again requires the application to set the flag indicating recognised partitions.) * Implement mode [[https://hg.pushbx.org/ecm/scanptab/rev/e7738c999e90|to do the traditional ordering of logical partitions]]. In this mode, an EPBR is scanned only for logical partitions in a first pass, and then only for nested extended partitions in a second pass. This is unlike the default for lDebug, chstool.eld, and [[https://hg.pushbx.org/ecm/ldosmbr/file/998133cbf221/altmbr.asm|lDOS altmbr]] which will process partition entries in an EPBR strictly according to their order. The difference is masked if all logical partitions occur in EPBR entries before any nested extended partitions, which seems to be the usual setup. * Implement the mode [[https://hg.pushbx.org/ecm/scanptab/rev/d33538af2fd6|to prioritise the first active primary partition]] (detected by piBoot != 0, as done by FreeDOS as well). It will be processed first. This change requires the application to provide the %load_is_known callback to determine whether a partition is a known logical or primary partition type to the application. This changeset prepares the multi-pass scanner by scanning for the active primary partition again to determine which partition to skip in the usual primary partition scan pass. * Implement the mode [[https://hg.pushbx.org/ecm/scanptab/rev/a647457d7908|to handle subsequent primary partitions]] (if at all) after the logical partitions. This again prepares the scanner for multi-pass operation, as in scan_subsequent_primary it re-detects either the first active primary partition or else the first primary partition, period. This also requires the %load_is_known extension. * [[https://hg.pushbx.org/ecm/scanptab/rev/6d941047e121|Add forgotten conditional assembly construct]] for a _MODE related part. (Without the _MODE define enabled, the scanner doesn't change at all from what it was before the changes.) * [[https://hg.pushbx.org/ecm/scanptab/rev/7cadc244bb00|Re-initialise load_scan_flags in multiple spots]], avoiding the need for the application to reset it at any point. * [[https://hg.pushbx.org/ecm/scanptab/rev/6d752b5d7b99|Add define option to create a multi-pass scanner]]. * [[https://hg.pushbx.org/ecm/scanptab/rev/aa7777d60dd5|Update attribution year]] and add the E. to the name initials. ==== Multi pass scanner ==== Instead of the single scan_partitions entry, four entries are used for the multi-pass scanner: scan_priority_primary (only takes effect if active primary first mode is on), scan_early_primary, scan_logical, and scan_subsequent_primary. These four entries correspond to the non-DLA-sort modes of FreeDOS, MS-DOS, or Enhanced DR-DOS. (DLA stands for "Drive Letter Assignment". DLA sort is a FreeDOS term; if enabled then all drives from one unit are processed together (like the single-pass scanner).) If DLA sort is not used, then the first pass should be used to process all HDD units first. Then the unit variable must be reset, and the second pass be used to process all HDD units again. Likewise for the third and fourth pass. The result is that different types of partitions are processed in stages. This mimics the traditional MS-DOS and DR-DOS orders of processing HDD partitions. ===== lDebug chstool.eld ===== These changes include the application-side support for scanptab modes and multi-pass non-DLA-sort operation. * [[https://hg.pushbx.org/ecm/ldebug/rev/e4dc89d6b25e|Add DUMP keyword]]. If not specified, the WALK mode will not dump raw partition table entries as it walks. * [[https://hg.pushbx.org/ecm/ldebug/rev/bd6b4ba204b3|Add DUMPRELOAD keyword]]. If not specified, partition tables being reloaded will not be dumped in raw form. * [[https://hg.pushbx.org/ecm/ldebug/rev/348149dd58e2|Parse the walk keywords]] (as yet EXTENDED, DUMP, DUMPRELOAD) using a table. * [[https://hg.pushbx.org/ecm/ldebug/rev/2b9d5a2e3562|Add parsing of scan modes]]. This changeset includes most of the definitions of named modes. * [[https://hg.pushbx.org/ecm/ldebug/rev/1da01488afd0|Add the label load_mode and the variable called load_scan_flags]]. Needed to use the mode support of scanptab. * [[https://hg.pushbx.org/ecm/ldebug/rev/91750d5d9a8a|Add LABEL keyword]] to display BPB new label of logical and primary partitions with FAT FS. * [[https://hg.pushbx.org/ecm/ldebug/rev/1e4e993af498|Also display the FAT FS ID]] if the LABEL keyword is included. * [[https://hg.pushbx.org/ecm/ldebug/rev/28f69356ef11|Harden label display by replacing bytes]] that are not printable ASCII text. * [[https://hg.pushbx.org/ecm/ldebug/rev/0a1c423bfa47|Support the modes to disable LBA and FAT32 partitions recognition]], and set the scan flag 32 on recognised partitions. * [[https://hg.pushbx.org/ecm/ldebug/rev/fc91cc6d5228|Split the load_is_known function from the main callback]] to support re-detecting the first active or first period primary partitions. * Adjust [[https://hg.pushbx.org/ecm/ldebug/rev/29482f8c3312|to allow working with multi-pass scanner]]. This as yet just runs all the passes one after another, which is the same as running the single-pass scanner once. * [[https://hg.pushbx.org/ecm/ldebug/rev/5367f21f2771|Add UPTO keyword]] to allow processing multiple (consecutive) units. In this case, the multi-pass scanner will actually be used in a way that cannot be emulated using the single-pass scanner, if the DLA sort disable flag is set. * [[https://hg.pushbx.org/ecm/ldebug/rev/312eb1a48aa7|Enable the multi-pass scanner by default]]. (Note that at run time this still defaults to DLA sort, which emulates the single-pass scanner's behaviour by way of calling the multi-pass scanner.) * [[https://hg.pushbx.org/ecm/ldebug/rev/4cbfd554ce05|Add QUIET keyword]] to hide the CHS lines for every processed partition. * [[https://hg.pushbx.org/ecm/ldebug/rev/4b9afaac970a|Add SKIPEXT keyword]] to explicitly skip extended partitions. It is expected that the callback is called for any outermost extended partition. Added later: * Add [[https://hg.pushbx.org/ecm/ldebug/rev/32aa8f3a1610|display of unit number and partition number]] to LABEL display. * Fix [[https://hg.pushbx.org/ecm/ldebug/rev/d9d23cd98ae7|to allow overwriting sectors]] for CHS encoded tuple decode command. * Allow UNIT= [[https://hg.pushbx.org/ecm/ldebug/rev/422e28dfabd7|before SECTORS= or HEADS=]] for CHS encoded tuple decode command. * Fix, [[https://hg.pushbx.org/ecm/ldebug/rev/85f6d9f302f2|do not overwrite both geometry items]] (CHS heads and CHS sectors) if one of them is forced but the other is not. * [[https://hg.pushbx.org/ecm/ldebug/rev/4e4d8d782786|Document most of chstool.eld]] in [[https://pushbx.org/ecm/doc/ldebug.htm#eld-chstool|the manual]]. This does not include the numeric values for the MODE= keyword. * Explictly [[https://hg.pushbx.org/ecm/ldebug/rev/099937a3a81e|block Protected Mode operation]] instead of assuming it won't be attempted. * [[https://hg.pushbx.org/ecm/ldebug/rev/477233758e22|Document the prior change]]. * Correct a comment and multiple spots in the manual on ELD packed library format 4: * [[https://hg.pushbx.org/ecm/ldebug/rev/70ff93c941a4|Comment on eldltCompressedLength]]. * [[https://hg.pushbx.org/ecm/ldebug/rev/5c2aca285f16|Text describing the compressed formats]]. * [[https://hg.pushbx.org/ecm/ldebug/rev/58a2c26a0644|More text referring to the number of compressed formats]]. * [[https://hg.pushbx.org/ecm/ldebug/rev/5f71c43598e9|Update attribution years]] for manual and eld.mac {{tag>bootimg partdisk scanptab ldebug eld chstool}} ~~DISCUSSION~~