]> git.ipfire.org Git - thirdparty/dracut-ng.git/commitdiff
feat(skipcpio): output additional CPIO information
authorFlos Lonicerae <lonicerae@gmail.com>
Sat, 11 Oct 2025 17:45:47 +0000 (01:45 +0800)
committerNeal Gompa (ニール・ゴンパ) <ngompa13@gmail.com>
Thu, 30 Oct 2025 10:11:24 +0000 (06:11 -0400)
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.

src/skipcpio/skipcpio.c
test/TEST-81-SKIPCPIO/test.sh

index f66c1869430ae340f8f65e1b9e67daa29651ba7a..afdb1658c0fa3a0e97b155ac80cb35f647180c10 100644 (file)
@@ -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 <file>\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;
                         }
 
index 9e458e0f6448d113923223ebf28dc3c514240524..fea7572dd72af4381c653957f0617fb8e85958a1 100755 (executable)
@@ -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() {