From 5bfb9f0463ba7053aa8f4ababa4cca12d8684f6e Mon Sep 17 00:00:00 2001 From: Victor Vogel Date: Fri, 13 Nov 2026 17:28:54 +0000 Subject: [PATCH] tools: the chroot extractors say why build.prop can't be read When debugfs can't copy the vendor partition's build.prop, tools/extract-vendor-chroot and tools/extract-fingerprint-vendor stop with "build.prop can't be read from vendor.img" and throw debugfs's own message away, so the reader learns that the read failed but not why. As the maintainer suggested on #676, the error now ends with debugfs's last line on stderr, its reason: a missing file, a full work directory, an image cut short, a damaged inode. The line is kept in a variable rather than a file in the work directory, which may be the thing that is full; debugfs's stdout still goes to the terminal, and a failed copy where debugfs printed only its banner gets no reason. Nothing else changes, exit statuses included. Tested: tests/chroot-extractors, extended with the reason from a stand-in debugfs, the banner-only case, and real debugfs on made-up ext4 images without build.prop and cut short, whose expected reason is read from debugfs itself, byte for byte, so another wording still passes (6 of its 8 checks fail with main's tools; it also passes with e2fsprogs 1.47.2 and 1.47.4); tests/extract-vendor-firmware; tests/all; tools/pr-check origin/main. Both tools run by hand on made-up images for five causes, before and after. Not tested: a real factory image. Co-Authored-By: Claude Opus 5.5 --- tests/chroot-extractors | 87 +++++++++++++++++++++++--------- tools/extract-fingerprint-vendor | 8 ++- tools/extract-vendor-chroot | 8 ++- 3 files changed, 76 insertions(+), 27 deletions(-) diff --git a/tests/chroot-extractors b/tests/chroot-extractors index 628819495..42ec93c9c 100755 --- a/tests/chroot-extractors +++ b/tests/chroot-extractors @@ -6,8 +6,12 @@ # stand-in unzip reads it with Python's zipfile, and a stand-in debugfs # fails the copy of build.prop as real debugfs does on a full work # directory (an error message, an empty file, exit 0). Checked: each tool -# then says build.prop can't be read, not that the image has none. -# XVC=path and XFP=path run other copies of the tools (a negative control). +# then says build.prop can't be read, not that the image has none, and +# passes on debugfs's own last line, the reason; a failed copy where +# debugfs said nothing but its banner gets no reason. With mkfs.ext4 and +# debugfs on the host, the same on real ext4 images: one without +# build.prop, and one cut short. XVC=path and XFP=path run other copies of +# the tools (a negative control). set -euo pipefail cd -- "$(dirname -- "${BASH_SOURCE[0]}")/.." XVC=$(realpath -- "${XVC:-tools/extract-vendor-chroot}") @@ -18,7 +22,7 @@ pass() { printf 'ok - %s\n' "$1"; } t=$(mktemp -d) trap 'rm -rf "$t"' EXIT -mkdir -p "$t/bin" +mkdir -p "$t/bin" "$t/fake" cat > "$t/bin/unzip" <<'EOF' #!/bin/bash # unzip -Z1 ZIP (list) or unzip -p ZIP MEMBER (to stdout) @@ -31,38 +35,75 @@ with zipfile.ZipFile(sys.argv[2]) as z: sys.stdout.buffer.write(z.read(sys.argv[3])) ' "$@" EOF -cat > "$t/bin/debugfs" <<'EOF' +cat > "$t/fake/debugfs" <<'EOF' #!/bin/bash # debugfs -R "dump /build.prop OUT" IMG on a full disk: real debugfs's -# messages, an empty OUT, exit 0 +# messages, an empty OUT, exit 0; DFS_REASON="" prints only the banner read -r _ _ out <<<"$2" out=${out#\"}; out=${out%\"}; out=${out//\"\"/\"} # debugfs's quoting : > "$out" echo "debugfs 1.47.2 (stand-in)" >&2 -echo "dump: No space left on device while writing file" >&2 +[[ -z ${DFS_REASON-x} ]] || echo "${DFS_REASON-dump: No space left on device while writing file}" >&2 exit 0 EOF -chmod +x "$t/bin/unzip" "$t/bin/debugfs" +chmod +x "$t/bin/unzip" "$t/fake/debugfs" head -c 4096 /dev/zero > "$t/ext4.img" printf '\x53\xef' | dd of="$t/ext4.img" bs=1 seek=1080 conv=notrunc status=none -python3 -I -c ' +# zipimg ZIP VENDOR SYSTEM: an image zip with those two images in it +zipimg() { + python3 -I -c ' import sys, zipfile with zipfile.ZipFile(sys.argv[1], "w") as z: - for p in ("vendor.img", "system.img"): - z.write(sys.argv[2], p) -' "$t/image-cheetah-fictional.zip" "$t/ext4.img" + z.write(sys.argv[2], "vendor.img") + z.write(sys.argv[3], "system.img") +' "$@" +} +zipimg "$t/image-cheetah-fictional.zip" "$t/ext4.img" "$t/ext4.img" + +# refused NAME ZIP LINE: both tools refuse ZIP, and their error line is LINE +# Compare the error bytes, including any trailing blanks from debugfs. +refused() { + local tool name args + for tool in "$XVC" "$XFP"; do + name=${tool##*/} + args=() + [[ $tool != "$XVC" ]] || args=(-p gnss) + rm -rf "$t/work" "$t/out" + if PATH=$t/bin:$PATH "$tool" "${args[@]}" -w "$t/work" -o "$t/out" "$2" > "$t/log" 2>&1; then + fail "$name: $1: refused" + elif [[ $(sed -n '/^error: /p' "$t/log") != "$3" ]]; then + cat "$t/log"; fail "$name: $1: says $3" + else + pass "$name: $1: refused, says $3" + fi + done +} +msg="error: build.prop can't be read from vendor.img" +PATH=$t/fake:$PATH refused "a build.prop whose copy fails" "$t/image-cheetah-fictional.zip" \ + "$msg: dump: No space left on device while writing file" +DFS_REASON="" PATH=$t/fake:$PATH refused "a failed copy with only debugfs's banner" \ + "$t/image-cheetah-fictional.zip" "$msg" -for tool in "$XVC" "$XFP"; do - name=${tool##*/} - args=() - [[ $tool != "$XVC" ]] || args=(-p gnss) - if PATH=$t/bin:$PATH "$tool" "${args[@]}" -w "$t/work" -o "$t/out" "$t/image-cheetah-fictional.zip" > "$t/log" 2>&1; then - fail "$name: a build.prop whose copy fails is refused" - elif ! grep -qF "error: build.prop can't be read from vendor.img" "$t/log"; then - cat "$t/log"; fail "$name: a build.prop whose copy fails: says it can't be read" - else - pass "$name: a build.prop whose copy fails: refused, says it can't be read" - fi -done +# --- Real ext4 images (made-up files), when the host can make them ------------ +mkdir -p "$t/v" "$t/s/system" +printf 'ro.product.vendor.device=cheetah\n' > "$t/v/build.prop" +if command -v debugfs >/dev/null && mkfs.ext4 -q -F -d "$t/s" "$t/system.img" 4M >/dev/null 2>&1 && + mkfs.ext4 -q -F -d "$t/v" "$t/vendor.img" 8M >/dev/null 2>&1 && + mkfs.ext4 -q -F -d "$t/s" "$t/noprop.img" 8M >/dev/null 2>&1; then + cp "$t/vendor.img" "$t/short.img"; truncate -s 1M "$t/short.img" + zipimg "$t/image-noprop.zip" "$t/noprop.img" "$t/system.img" + zipimg "$t/image-short.zip" "$t/short.img" "$t/system.img" + for image in noprop short; do + err=$(debugfs -R "dump /build.prop \"$t/probe.prop\"" "$t/$image.img" 2>&1 >/dev/null) + reason=${err##*$'\n'} + if [[ -z $reason || $reason == "debugfs "[0-9]* || -s $t/probe.prop ]]; then + fail "real ext4 $image: direct debugfs must fail to copy with a reason" + continue + fi + refused "real ext4 $image" "$t/image-$image.zip" "$msg: $reason" + done +else + echo "ok - # skip: no mkfs.ext4 -d and debugfs for the real ext4 checks" +fi ((failed == 0)) || { echo "$failed check(s) failed" >&2; exit 1; } diff --git a/tools/extract-fingerprint-vendor b/tools/extract-fingerprint-vendor index 09f498e99..a71862ec4 100755 --- a/tools/extract-fingerprint-vendor +++ b/tools/extract-fingerprint-vendor @@ -199,8 +199,12 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" -debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null -[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img" +# debugfs exits 0 when the copy fails, and the last line it writes to stderr +# says why: kept in a variable, not a file in $WORK, which may be full +{ err=$(debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>&1 >&3); } 3>&1 +reason=${err##*$'\n'} +[[ $reason != "debugfs "[0-9]* ]] || reason="" # only its banner: no reason +[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img${reason:+: $reason}" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override" diff --git a/tools/extract-vendor-chroot b/tools/extract-vendor-chroot index 89f5d4695..b2b3f777d 100755 --- a/tools/extract-vendor-chroot +++ b/tools/extract-vendor-chroot @@ -295,8 +295,12 @@ done # The vendor partition says which device it was built for. mkdir -p "$WORK/v" -debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>/dev/null -[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img" +# debugfs exits 0 when the copy fails, and the last line it writes to stderr +# says why: kept in a variable, not a file in $WORK, which may be full +{ err=$(debugfs -R "dump /build.prop $(dq "$WORK/v/build.prop")" "$WORK/vendor.img" 2>&1 >&3); } 3>&1 +reason=${err##*$'\n'} +[[ $reason != "debugfs "[0-9]* ]] || reason="" # only its banner: no reason +[[ -s "$WORK/v/build.prop" ]] || die "build.prop can't be read from vendor.img${reason:+: $reason}" dev=$(sed -n 's/^ro.product.vendor.device=//p' "$WORK/v/build.prop" | head -1) [[ "$dev" == "$DEVICE" || -n "$FORCE" ]] || die "vendor partition is for '${dev:-unknown}', not $DEVICE; use -f to override"