# parted part 3 -- the FILESYSTEM-PROBE path, plus the negative controls for # the whole port. See 97-parted.test for why this is split and why the fixtures # are small. # # libparted's filesystem probes are a DIFFERENT code path from every label # parser in parts 1 and 2: they read a superblock out of a partition and name # the filesystem in print's "File system" column. They are also the code this # port had to patch -- all eleven heap-allocated buffers live in these probes -- # so parted/fs-probe-ext4 is the regression guard for that patch specifically. A # use-after-free or a short buffer shows up here and nowhere else in this suite. . "$BST_LIB" require parted parted/probe-present T=${TMPDIR:-/tmp}/bst-partedp.$$ mkdir -p "$T" || exit 0 trap 'rm -rf "$T"' EXIT JUNK=$T/junk.img snap() { parted -m -s "$1" print 2>/dev/null | sed 's/;$//'; } # assert on OUTPUT ALONE: parted signals an unreadable label with rc 1 while # still printing the diagnostic, so check_out (which also demands rc 0) would # conflate "wrong message" with "expected failure". msg() { _i=$1; _n=$2; shift 2; _o=$("$@" 2>&1) case "$_o" in *"$_n"*) bst_ok "$_i" ;; *) bst_notok "$_i" "want:'$_n' got:'$(_bst_1line "$_o")'" ;; esac; } # mke2fs comes from e2fsprogs (BRINTOS-229) on this same image; if a future # image drops it this reports skip rather than ending the file, so the controls # below still run. if command -v mke2fs >/dev/null 2>&1; then FSI=$T/fsprobe.img INNER=$T/inner.img dd if=/dev/zero of="$FSI" bs=1M count=8 2>/dev/null parted -s "$FSI" mklabel gpt >/dev/null 2>&1 parted -s "$FSI" mkpart primary ext4 1MiB 7MiB >/dev/null 2>&1 dd if=/dev/zero of="$INNER" bs=1M count=6 2>/dev/null # -O and -b are NOT decoration. parted reads "ext4" only when the # superblock carries has_journal AND an ext4-only feature (here extent); # at mke2fs' default 4 KiB block size a 6 MiB filesystem is "too small # for a journal", so plain `-t ext4` silently produces a superblock that # probes as ext2 and this case fails for a reason with nothing to do with # parted. Naming the features and a 1 KiB block makes the fixture # deterministic instead of dependent on how big /tmp let it be. mke2fs -q -F -t ext4 -O has_journal,extent -b 1024 "$INNER" >/dev/null 2>&1 dd if="$INNER" of="$FSI" bs=1M seek=1 conv=notrunc 2>/dev/null rm -f "$INNER" check_eq parted/fs-probe-ext4 "ext4" "$(snap "$FSI" | awk -F: '/^1:/{print $5}')" rm -f "$FSI" else bst_skip parted/fs-probe-ext4 "mke2fs not installed on this image" fi # ----------------------------------------------------------------- controls # Without these, a parted that reported a plausible empty table for ANY input # would score a clean sweep across all three files. # # The fixture is zeroes, not /dev/urandom: no other suite on this image depends # on urandom, and an absent one would silently leave a 0-byte file that fails # for the wrong reason. All-zero is just as unlabelled, and /dev/zero is already # proven present by every dd above. 1 MiB, not 64 KiB, because parted rejects a # device below its own minimum with a DIFFERENT message ("so small that it # cannot possibly store a file system") -- which would satisfy a sloppier # assertion for entirely the wrong reason. dd if=/dev/zero of="$JUNK" bs=1M count=1 2>/dev/null msg parted/junk-unrecognised "unrecognised disk label" parted -s "$JUNK" print check_rc parted/junk-rc 1 parted -s "$JUNK" print msg parted/missing-file "Could not stat device" parted -s "$T/nope.img" print