[mkinitcpio] lsinitcpio: Add zstd decompression support

Message ID 20190430131935.17426-1-jelle@vdwaa.nl
State New
Headers show
Series [mkinitcpio] lsinitcpio: Add zstd decompression support | expand

Commit Message

Jelle van der Waa April 30, 2019, 1:19 p.m. UTC
Add detection support for zstd compressed initramfs, the magic number of
zstd is defined as 0xFD2FB528.

https://github.com/facebook/zstd/blob/dev/doc/zstd_compression_format.md

Signed-off-by: Jelle van der Waa <jelle@vdwaa.nl>
---
 lsinitcpio | 6 ++++++
 1 file changed, 6 insertions(+)

Patch

diff --git a/lsinitcpio b/lsinitcpio
index bcb4a19..d44a714 100755
--- a/lsinitcpio
+++ b/lsinitcpio
@@ -131,6 +131,12 @@  detect_filetype() {
         return
     fi
 
+    read -rd '' bytes < <(hexdump -n 4 -e '"%x"' "$1")
+    if [[ $bytes = 'fd2fb528' ]]; then
+        echo 'zstd'
+        return
+    fi
+
     # still nothing? hrmm, maybe the user goofed and it's a kernel
     if kver "$1" >/dev/null; then
         die '%s is a kernel image, not an initramfs image!' "$1"