4 * Detect the decompression method based on magic number
7 #include <linux/decompress/generic.h>
9 #include <linux/decompress/bunzip2.h>
10 #include <linux/decompress/unlzma.h>
11 #include <linux/decompress/inflate.h>
13 #include <linux/types.h>
14 #include <linux/string.h>
16 #ifndef CONFIG_DECOMPRESS_GZIP
19 #ifndef CONFIG_DECOMPRESS_BZIP2
22 #ifndef CONFIG_DECOMPRESS_LZMA
26 static const struct compress_format
{
27 unsigned char magic
[2];
29 decompress_fn decompressor
;
30 } compressed_formats
[] = {
31 { {037, 0213}, "gzip", gunzip
},
32 { {037, 0236}, "gzip", gunzip
},
33 { {0x42, 0x5a}, "bzip2", bunzip2
},
34 { {0x5d, 0x00}, "lzma", unlzma
},
35 { {0, 0}, NULL
, NULL
}
38 decompress_fn
decompress_method(const unsigned char *inbuf
, int len
,
41 const struct compress_format
*cf
;
44 return NULL
; /* Need at least this much... */
46 for (cf
= compressed_formats
; cf
->name
; cf
++) {
47 if (!memcmp(inbuf
, cf
->magic
, 2))
53 return cf
->decompressor
;