diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile | 9 | ||||
-rw-r--r-- | lib/decompress.c | 50 |
2 files changed, 55 insertions, 4 deletions
diff --git a/lib/Makefile b/lib/Makefile index d9ac5a414fa7..790de7c25d0d 100644 --- a/lib/Makefile +++ b/lib/Makefile | |||
@@ -11,7 +11,8 @@ lib-y := ctype.o string.o vsprintf.o cmdline.o \ | |||
11 | rbtree.o radix-tree.o dump_stack.o \ | 11 | rbtree.o radix-tree.o dump_stack.o \ |
12 | idr.o int_sqrt.o extable.o prio_tree.o \ | 12 | idr.o int_sqrt.o extable.o prio_tree.o \ |
13 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ | 13 | sha1.o irq_regs.o reciprocal_div.o argv_split.o \ |
14 | proportions.o prio_heap.o ratelimit.o show_mem.o is_single_threaded.o | 14 | proportions.o prio_heap.o ratelimit.o show_mem.o \ |
15 | is_single_threaded.o decompress.o | ||
15 | 16 | ||
16 | lib-$(CONFIG_MMU) += ioremap.o | 17 | lib-$(CONFIG_MMU) += ioremap.o |
17 | lib-$(CONFIG_SMP) += cpumask.o | 18 | lib-$(CONFIG_SMP) += cpumask.o |
@@ -65,9 +66,9 @@ obj-$(CONFIG_REED_SOLOMON) += reed_solomon/ | |||
65 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ | 66 | obj-$(CONFIG_LZO_COMPRESS) += lzo/ |
66 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ | 67 | obj-$(CONFIG_LZO_DECOMPRESS) += lzo/ |
67 | 68 | ||
68 | obj-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o | 69 | lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o |
69 | obj-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o | 70 | lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o |
70 | obj-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o | 71 | lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o |
71 | 72 | ||
72 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o | 73 | obj-$(CONFIG_TEXTSEARCH) += textsearch.o |
73 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o | 74 | obj-$(CONFIG_TEXTSEARCH_KMP) += ts_kmp.o |
diff --git a/lib/decompress.c b/lib/decompress.c new file mode 100644 index 000000000000..edac55cc7823 --- /dev/null +++ b/lib/decompress.c | |||
@@ -0,0 +1,50 @@ | |||
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 | static const struct compress_format { | ||
17 | unsigned char magic[2]; | ||
18 | const char *name; | ||
19 | decompress_fn decompressor; | ||
20 | } compressed_formats[] = { | ||
21 | #ifdef CONFIG_DECOMPRESS_GZIP | ||
22 | { {037, 0213}, "gzip", gunzip }, | ||
23 | { {037, 0236}, "gzip", gunzip }, | ||
24 | #endif | ||
25 | #ifdef CONFIG_DECOMPRESS_BZIP2 | ||
26 | { {0x42, 0x5a}, "bzip2", bunzip2 }, | ||
27 | #endif | ||
28 | #ifdef CONFIG_DECOMPRESS_LZMA | ||
29 | { {0x5d, 0x00}, "lzma", unlzma }, | ||
30 | #endif | ||
31 | { {0, 0}, NULL, NULL } | ||
32 | }; | ||
33 | |||
34 | decompress_fn decompress_method(const unsigned char *inbuf, int len, | ||
35 | const char **name) | ||
36 | { | ||
37 | const struct compress_format *cf; | ||
38 | |||
39 | if (len < 2) | ||
40 | return NULL; /* Need at least this much... */ | ||
41 | |||
42 | for (cf = compressed_formats; cf->decompressor; cf++) { | ||
43 | if (!memcmp(inbuf, cf->magic, 2)) | ||
44 | break; | ||
45 | |||
46 | } | ||
47 | if (name) | ||
48 | *name = cf->name; | ||
49 | return cf->decompressor; | ||
50 | } | ||