[parted-devel] [PATCH 2/2] tests: t2420: New test confirming updating msdos doesn't add boot code
Mike Fleetwood
mike.fleetwood at googlemail.com
Fri Oct 24 14:03:03 BST 2025
Signed-off-by: Mike Fleetwood <mike.fleetwood at googlemail.com>
---
tests/Makefile.am | 1 +
tests/t-lib-helpers.sh | 5 ++
tests/t2420-msdos-no-boot-code.sh | 85 +++++++++++++++++++++++++++++++
3 files changed, 91 insertions(+)
create mode 100755 tests/t2420-msdos-no-boot-code.sh
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 5eeab08..dae1d56 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -57,6 +57,7 @@ TESTS = \
t2320-dos-extended-noclobber.sh \
t2400-dos-hfs-partition-type.sh \
t2410-dos-udf-partition-type.sh \
+ t2420-msdos-no-boot-code.sh \
t2500-probe-corrupt-hfs.sh \
t3000-resize-fs.sh \
t3200-resize-partition.sh \
diff --git a/tests/t-lib-helpers.sh b/tests/t-lib-helpers.sh
index a1d3c30..272a925 100644
--- a/tests/t-lib-helpers.sh
+++ b/tests/t-lib-helpers.sh
@@ -428,3 +428,8 @@ require_filesystem_()
grep $1 /proc/filesystems >/dev/null && return 0
modprobe --quiet --dry-run $1 || skip_ "this test requires kernel support for $1"
}
+
+require_hexdump_()
+{
+ hexdump -V || skip_ "hexdump: command not found"
+}
diff --git a/tests/t2420-msdos-no-boot-code.sh b/tests/t2420-msdos-no-boot-code.sh
new file mode 100755
index 0000000..caa50ff
--- /dev/null
+++ b/tests/t2420-msdos-no-boot-code.sh
@@ -0,0 +1,85 @@
+#!/bin/sh
+# Test updating msdos table doesn't replace MBR boot code
+
+# Copyright (C) 2025 Free Software Foundation, Inc.
+
+# This program is free software; 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 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+. "${srcdir=.}/init.sh"; path_prepend_ ../parted
+require_hexdump_
+
+dev=loop-file
+
+# create device
+truncate --size 10MiB "$dev" || fail=1
+
+write_fixed_msdos_disk_id ()
+{
+ case $# in
+ 1) local dev=$1;;
+ *) echo "usage: write_fixed_msdos_disk_id DEVICE" 1>&2; return 1;;
+ esac
+ echo -e '\x12\x34\x56\x78' | dd bs=1 seek=440 count=4 of=$dev status=none conv=notrunc
+}
+
+write_byte_pattern ()
+{
+ case $# in
+ 2) local len=$1; local dev=$2;;
+ *) echo "usage: write_byte_pattern LENGTH DEVICE" 1>&2; return 1;;
+ esac
+ case $len in
+ *[^0-9]*) echo "write_byte_pattern: invalid length: $len" 1>&2; return 1;;
+ esac
+ perl -e '
+ $len='"$len"';
+ $str = "\xde\xad\xbe\xef" x int(($len + 4) / 4);
+ printf("%.*s", $len, $str);' | \
+ dd bs=$len count=1 of=$dev status=none conv=notrunc
+}
+
+echo '#1: Fill first sector with byte pattern and create new msdos table.'
+echo '#1: Expect zero filled boot code and new msdos table.'
+cat << 'EOF' > exp
+00000000 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+*
+000001b0 00 00 00 00 00 00 00 00 12 34 56 78 00 00 00 00 |.........4Vx....|
+000001c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................|
+*
+000001f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 55 aa |..............U.|
+00000200
+EOF
+write_byte_pattern 512 $dev || fail=1
+parted --script $dev mklabel msdos || fail=1
+write_fixed_msdos_disk_id $dev || fail=1
+dd if=$dev bs=512 count=1 status=none | hexdump -C > out 2>&1
+compare exp out || fail=1
+
+echo '#2: Update msdos table.'
+echo '#2: Expect zeroed boot code maintained.'
+dd if=/dev/zero bs=440 count=1 of=$dev status=none conv=notrunc || fail=1
+dd if=$dev bs=440 count=1 status=none | hexdump -C > exp 2>&1
+parted --script $dev mkpart primary ext2 2048s 4095s || fail=1
+dd if=$dev bs=440 count=1 status=none | hexdump -C > out 2>&1
+compare exp out || fail=1
+
+echo '#3: Fill boot code with byte pattern and update msdos table.'
+echo '#3: Expect boot code maintained.'
+write_byte_pattern 440 $dev || fail=1
+dd if=$dev bs=440 count=1 status=none | hexdump -C > exp 2>&1
+parted --script $dev mkpart primary ext2 4096s 6143s || fail=1
+dd if=$dev bs=440 count=1 status=none | hexdump -C > out 2>&1
+compare exp out || fail=1
+
+Exit $fail
--
2.43.7
More information about the parted-devel
mailing list