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 static const struct compress_format
{
17 unsigned char magic
[2];
19 decompress_fn decompressor
;
20 } compressed_formats
[] = {
21 #ifdef CONFIG_DECOMPRESS_GZIP
22 { {037, 0213}, "gzip", gunzip
},
23 { {037, 0236}, "gzip", gunzip
},
25 #ifdef CONFIG_DECOMPRESS_BZIP2
26 { {0x42, 0x5a}, "bzip2", bunzip2
},
28 #ifdef CONFIG_DECOMPRESS_LZMA
29 { {0x5d, 0x00}, "lzma", unlzma
},
31 { {0, 0}, NULL
, NULL
}
34 decompress_fn
decompress_method(const unsigned char *inbuf
, int len
,
37 const struct compress_format
*cf
;
40 return NULL
; /* Need at least this much... */
42 for (cf
= compressed_formats
; cf
->decompressor
; cf
++) {
43 if (!memcmp(inbuf
, cf
->magic
, 2))
49 return cf
->decompressor
;