diff options
| author | Ingo Molnar <mingo@elte.hu> | 2009-04-08 11:25:42 -0400 |
|---|---|---|
| committer | Ingo Molnar <mingo@elte.hu> | 2009-04-08 11:26:00 -0400 |
| commit | 5af8c4e0fac9838428bd718040b664043a05f37c (patch) | |
| tree | 75a01d98ed244db45fe3c734c4a81c1a3d92ac37 /lib/decompress.c | |
| parent | 46e0bb9c12f4bab539736f1714cbf16600f681ec (diff) | |
| parent | 577c9c456f0e1371cbade38eaf91ae8e8a308555 (diff) | |
Merge commit 'v2.6.30-rc1' into sched/urgent
Merge reason: update to latest upstream to queue up fix
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'lib/decompress.c')
| -rw-r--r-- | lib/decompress.c | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/lib/decompress.c b/lib/decompress.c new file mode 100644 index 000000000000..d2842f571674 --- /dev/null +++ b/lib/decompress.c | |||
| @@ -0,0 +1,54 @@ | |||
| 1 | /* | ||
| 2 | * decompress.c | ||
| 3 | * | ||
| 4 | * Detect the decompression method based on magic number | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <linux/decompress/generic.h> | ||
| 8 | |||
| 9 | #include <linux/decompress/bunzip2.h> | ||
| 10 | #include <linux/decompress/unlzma.h> | ||
| 11 | #include <linux/decompress/inflate.h> | ||
| 12 | |||
| 13 | #include <linux/types.h> | ||
| 14 | #include <linux/string.h> | ||
| 15 | |||
| 16 | #ifndef CONFIG_DECOMPRESS_GZIP | ||
| 17 | # define gunzip NULL | ||
| 18 | #endif | ||
| 19 | #ifndef CONFIG_DECOMPRESS_BZIP2 | ||
| 20 | # define bunzip2 NULL | ||
| 21 | #endif | ||
| 22 | #ifndef CONFIG_DECOMPRESS_LZMA | ||
| 23 | # define unlzma NULL | ||
| 24 | #endif | ||
| 25 | |||
| 26 | static const struct compress_format { | ||
| 27 | unsigned char magic[2]; | ||
| 28 | const char *name; | ||
| 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 } | ||
| 36 | }; | ||
| 37 | |||
| 38 | decompress_fn decompress_method(const unsigned char *inbuf, int len, | ||
| 39 | const char **name) | ||
| 40 | { | ||
| 41 | const struct compress_format *cf; | ||
| 42 | |||
| 43 | if (len < 2) | ||
| 44 | return NULL; /* Need at least this much... */ | ||
| 45 | |||
| 46 | for (cf = compressed_formats; cf->name; cf++) { | ||
| 47 | if (!memcmp(inbuf, cf->magic, 2)) | ||
| 48 | break; | ||
| 49 | |||
| 50 | } | ||
| 51 | if (name) | ||
| 52 | *name = cf->name; | ||
| 53 | return cf->decompressor; | ||
| 54 | } | ||
