From: Flos Lonicerae Date: Sat, 11 Oct 2025 17:45:47 +0000 (+0800) Subject: feat(skipcpio): output additional CPIO information X-Git-Tag: 109~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=3841274d3b63ed52bd6900dba3beb24ec2953bea;p=thirdparty%2Fdracut-ng.git feat(skipcpio): output additional CPIO information Provides additional CPIO information to skipcpio, allowing users to better understand the composition of the split file. To display the results we'll use an environment variable 'DEBUG_SKIPCPIO' as a switch. --- diff --git a/src/skipcpio/skipcpio.c b/src/skipcpio/skipcpio.c index f66c18694..afdb1658c 100644 --- a/src/skipcpio/skipcpio.c +++ b/src/skipcpio/skipcpio.c @@ -80,6 +80,13 @@ int main(int argc, char **argv) int ret = EXIT_FAILURE; unsigned long filesize; unsigned long filename_length; + int debug_output = 0; + + if (getenv("DEBUG_SKIPCPIO")) { + if (strcmp(getenv("DEBUG_SKIPCPIO"), "1") == 0) { + debug_output = 1; + } + } if (argc != 2) { fprintf(stderr, "Usage: %s \n", argv[0]); @@ -106,6 +113,9 @@ int main(int argc, char **argv) /* check, if this is a cpio archive */ if (memcmp(buf.cpio.h.c_magic, CPIO_MAGIC, CPIO_MAGIC_LEN)) { + if (debug_output) { + fprintf(stderr, "No CPIO header found.\n"); + } goto cat_rest; } @@ -172,6 +182,9 @@ int main(int argc, char **argv) pr_err("fseek\n"); goto end; } + if (debug_output) { + fprintf(stderr, "CPIO data and any trailing zeros end at position %ld.\n", (pos-1)); + } break; } diff --git a/test/TEST-81-SKIPCPIO/test.sh b/test/TEST-81-SKIPCPIO/test.sh index 9e458e0f6..fea7572dd 100755 --- a/test/TEST-81-SKIPCPIO/test.sh +++ b/test/TEST-81-SKIPCPIO/test.sh @@ -75,6 +75,29 @@ EOF 11 12 EOF + + DEBUG_SKIPCPIO=1 "$skipcpio_path"/skipcpio "$CPIO_TESTDIR/skipcpio_simple.cpio" \ + > /dev/null 2> "$CPIO_TESTDIR/debug.log" + if [ ! -s "$CPIO_TESTDIR/debug.log" ]; then + echo "Debug log file is missing or empty." + return 1 + fi + if ! grep -q "CPIO data and any trailing zeros end at position" "$CPIO_TESTDIR/debug.log"; then + echo "Expected debug message not found in log." + return 1 + fi + + truncate -s 1K "$CPIO_TESTDIR/empty.img" + DEBUG_SKIPCPIO=1 "$skipcpio_path"/skipcpio "$CPIO_TESTDIR/empty.img" > /dev/null \ + 2> "$CPIO_TESTDIR/debug.log" + if [ ! -s "$CPIO_TESTDIR/debug.log" ]; then + echo "Debug log file is missing or empty." + return 1 + fi + if ! grep -q "No CPIO header found." "$CPIO_TESTDIR/debug.log"; then + echo "Expected debug message not found in log." + return 1 + fi } test_run() {