@@ -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
@@ -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;
+}
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@gmail.com> Cc: Ard Biesheuvel <ardb@kernel.org> Cc: kexec@lists.infradead.org To: linux-kernel@vger.kernel.org --- include/linux/decompress/generic.h | 2 ++ lib/decompress.c | 14 +++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-)