]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
tests: fdisk: add regression test for missing EBR gap between logical partitions
authorMartin Jungblut Schreiner <martinjungblut@gmail.com>
Mon, 29 Dec 2025 23:46:39 +0000 (20:46 -0300)
committerMartin Jungblut Schreiner <martinjungblut@gmail.com>
Mon, 29 Dec 2025 23:46:39 +0000 (20:46 -0300)
Add a DOS/MBR test case where the first logical partition starts at 6145
(extended start 2048). In the regressed behaviour fdisk allows the next
logical partition to start at prev_end+1, which would place its EBR
(start - 2048) inside the previous logical partition.

The expected behaviour is to require the next starting sector to be at least
prev_end + 2048 + 1 (e.g. 790528 in the testcase).

Closes issue #3925.

tests/expected/fdisk/mbr-logical-ebr-gap [new file with mode: 0644]
tests/ts/fdisk/mbr-logical-ebr-gap [new file with mode: 0755]

diff --git a/tests/expected/fdisk/mbr-logical-ebr-gap b/tests/expected/fdisk/mbr-logical-ebr-gap
new file mode 100644 (file)
index 0000000..c25b9be
--- /dev/null
@@ -0,0 +1,15 @@
+
+---layout----------
+Disk <removed>: 1 GiB, 1073741824 bytes, 2097152 sectors
+Units: sectors of 1 * 512 = 512 bytes
+Sector size (logical/physical): 512 bytes / 512 bytes
+I/O size (minimum/optimal): 512 bytes / <removed> bytes
+Disklabel type: dos
+Disk identifier: <removed>
+
+Device     Boot   Start     End Sectors Id Type     Start-C/H/S End-C/H/S Attrs
+<removed>1         2048 2097151 2095104  5 Extended     0/32/33 130/138/8 
+<removed>5         6145  788479  782335 83 Linux        0/97/35  49/20/35 
+<removed>6      2097151 2097151       1 83 Linux      130/138/8 130/138/8 
+-------------------
+
diff --git a/tests/ts/fdisk/mbr-logical-ebr-gap b/tests/ts/fdisk/mbr-logical-ebr-gap
new file mode 100755 (executable)
index 0000000..ffc9f96
--- /dev/null
@@ -0,0 +1,35 @@
+#!/bin/bash
+TS_TOPDIR="${0%/*}/../.."
+TS_DESC="MBR: default start for logical must reserve EBR gap"
+. "$TS_TOPDIR"/functions.sh
+ts_init "$*"
+ts_check_test_command "$TS_CMD_FDISK"
+
+# 1GiB image => 2097152 sectors @ 512B
+TEST_IMAGE_NAME=$(ts_image_init 1024)
+
+# key assertion is in the resulting layout: L2 must not start at 788480,
+# but at 790528 (= 788480 + 2048), leaving room for the EBR.
+echo -e \
+"o
+n
+e
+1
+2048
+2097151
+n
+6145
+788479
+n
+788480
+2097151
+w
+q
+" | $TS_CMD_FDISK --noauto-pt "$TEST_IMAGE_NAME" &> /dev/null
+
+echo -ne "\n---layout----------\n" >> "$TS_OUTPUT"
+$TS_CMD_FDISK -x "$TEST_IMAGE_NAME" >> "$TS_OUTPUT"
+echo -ne "-------------------\n\n" >> "$TS_OUTPUT"
+ts_fdisk_clean "$TEST_IMAGE_NAME"
+
+ts_finalize