[PATCH 2/6] lib/decompress: Introduce decompress_method_by_name()
Pingfan Liu
kernelfans at gmail.com
Sun Mar 5 19:03:01 PST 2023
The zboot image packs the compressed file in the data section. Instead
of starting with the zip file header. It records the compressing method
name 'gzip','lzma' etc in the zboot image header.
Hence it is easier to decide the decompressing method by the name than
by the magic number.
Signed-off-by: Pingfan Liu <kernelfans at gmail.com>
Cc: Ard Biesheuvel <ardb at kernel.org>
Cc: kexec at lists.infradead.org
To: linux-kernel at vger.kernel.org
---
include/linux/decompress/generic.h | 2 ++
lib/decompress.c | 14 +++++++++++++-
2 files changed, 15 insertions(+), 1 deletion(-)
diff --git a/include/linux/decompress/generic.h b/include/linux/decompress/generic.h
index 207d80138db5..077f15ce77b9 100644
--- a/include/linux/decompress/generic.h
+++ b/include/linux/decompress/generic.h
@@ -37,4 +37,6 @@ typedef int (*decompress_fn) (unsigned char *inbuf, long len,
decompress_fn decompress_method(const unsigned char *inbuf, long len,
const char **name);
+decompress_fn decompress_method_by_name(const unsigned char *name);
+
#endif
diff --git a/lib/decompress.c b/lib/decompress.c
index ab3fc90ffc64..8dd6f87e885f 100644
--- a/lib/decompress.c
+++ b/lib/decompress.c
@@ -2,7 +2,7 @@
/*
* decompress.c
*
- * Detect the decompression method based on magic number
+ * Detect the decompression method based on magic number or name
*/
#include <linux/decompress/generic.h>
@@ -82,3 +82,15 @@ decompress_fn __init decompress_method(const unsigned char *inbuf, long len,
*name = cf->name;
return cf->decompressor;
}
+
+decompress_fn __init decompress_method_by_name(const unsigned char *name)
+{
+ const struct compress_format *cf;
+
+ for (cf = compressed_formats; cf->name; cf++) {
+ if (!strcmp(name, cf->name))
+ break;
+
+ }
+ return cf->decompressor;
+}
--
2.31.1
More information about the kexec
mailing list