aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/squashfs/Kconfig5
-rw-r--r--fs/squashfs/Makefile2
-rw-r--r--fs/squashfs/decompressor.c6
-rw-r--r--fs/squashfs/lzo_wrapper.c134
-rw-r--r--fs/squashfs/squashfs.h3
5 files changed, 149 insertions, 1 deletions
diff --git a/fs/squashfs/Kconfig b/fs/squashfs/Kconfig
index 3e9ee95ef37d..3da01108c44e 100644
--- a/fs/squashfs/Kconfig
+++ b/fs/squashfs/Kconfig
@@ -37,6 +37,11 @@ config SQUASHFS_XATTR
37 37
38 If unsure, say N. 38 If unsure, say N.
39 39
40config SQUASHFS_LZO
41 bool "Include support for LZO compressed file systems"
42 depends on SQUASHFS
43 select LZO_DECOMPRESS
44
40config SQUASHFS_EMBEDDED 45config SQUASHFS_EMBEDDED
41 46
42 bool "Additional option for memory-constrained systems" 47 bool "Additional option for memory-constrained systems"
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 6fa6b9deecd3..7672bac8d328 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -6,4 +6,4 @@ obj-$(CONFIG_SQUASHFS) += squashfs.o
6squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o 6squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
7squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o 7squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
8squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o 8squashfs-$(CONFIG_SQUASHFS_XATTR) += xattr.o xattr_id.o
9 9squashfs-$(CONFIG_SQUASHFS_LZO) += lzo_wrapper.o
diff --git a/fs/squashfs/decompressor.c b/fs/squashfs/decompressor.c
index 157478da6ac9..24af9ce9722f 100644
--- a/fs/squashfs/decompressor.c
+++ b/fs/squashfs/decompressor.c
@@ -40,9 +40,11 @@ static const struct squashfs_decompressor squashfs_lzma_unsupported_comp_ops = {
40 NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0 40 NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0
41}; 41};
42 42
43#ifndef CONFIG_SQUASHFS_LZO
43static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = { 44static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = {
44 NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0 45 NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0
45}; 46};
47#endif
46 48
47static const struct squashfs_decompressor squashfs_unknown_comp_ops = { 49static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
48 NULL, NULL, NULL, 0, "unknown", 0 50 NULL, NULL, NULL, 0, "unknown", 0
@@ -51,7 +53,11 @@ static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
51static const struct squashfs_decompressor *decompressor[] = { 53static const struct squashfs_decompressor *decompressor[] = {
52 &squashfs_zlib_comp_ops, 54 &squashfs_zlib_comp_ops,
53 &squashfs_lzma_unsupported_comp_ops, 55 &squashfs_lzma_unsupported_comp_ops,
56#ifdef CONFIG_SQUASHFS_LZO
57 &squashfs_lzo_comp_ops,
58#else
54 &squashfs_lzo_unsupported_comp_ops, 59 &squashfs_lzo_unsupported_comp_ops,
60#endif
55 &squashfs_unknown_comp_ops 61 &squashfs_unknown_comp_ops
56}; 62};
57 63
diff --git a/fs/squashfs/lzo_wrapper.c b/fs/squashfs/lzo_wrapper.c
new file mode 100644
index 000000000000..e1f86ded0ee5
--- /dev/null
+++ b/fs/squashfs/lzo_wrapper.c
@@ -0,0 +1,134 @@
1/*
2 * Squashfs - a compressed read only filesystem for Linux
3 *
4 * Copyright (c) 2010 LG Electronics
5 * Chan Jeong <chan.jeong@lge.com>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2,
10 * or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 * lzo_wrapper.c
22 */
23
24#include <linux/mutex.h>
25#include <linux/buffer_head.h>
26#include <linux/slab.h>
27#include <linux/vmalloc.h>
28#include <linux/lzo.h>
29
30#include "squashfs_fs.h"
31#include "squashfs_fs_sb.h"
32#include "squashfs_fs_i.h"
33#include "squashfs.h"
34#include "decompressor.h"
35
36struct squashfs_lzo {
37 void *input;
38 void *output;
39};
40
41static void *lzo_init(struct squashfs_sb_info *msblk)
42{
43 struct squashfs_lzo *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
44 if (stream == NULL)
45 goto failed;
46 stream->input = vmalloc(msblk->block_size);
47 if (stream->input == NULL)
48 goto failed;
49 stream->output = vmalloc(msblk->block_size);
50 if (stream->output == NULL)
51 goto failed2;
52
53 return stream;
54
55failed2:
56 vfree(stream->input);
57failed:
58 ERROR("Failed to allocate lzo workspace\n");
59 kfree(stream);
60 return NULL;
61}
62
63
64static void lzo_free(void *strm)
65{
66 struct squashfs_lzo *stream = strm;
67
68 if (stream) {
69 vfree(stream->input);
70 vfree(stream->output);
71 }
72 kfree(stream);
73}
74
75
76static int lzo_uncompress(struct squashfs_sb_info *msblk, void **buffer,
77 struct buffer_head **bh, int b, int offset, int length, int srclength,
78 int pages)
79{
80 struct squashfs_lzo *stream = msblk->stream;
81 void *buff = stream->input;
82 int avail, i, bytes = length, res;
83 size_t out_len = msblk->block_size;
84
85 mutex_lock(&msblk->read_data_mutex);
86
87 for (i = 0; i < b; i++) {
88 wait_on_buffer(bh[i]);
89 if (!buffer_uptodate(bh[i]))
90 goto block_release;
91
92 avail = min(bytes, msblk->devblksize - offset);
93 memcpy(buff, bh[i]->b_data + offset, avail);
94 buff += avail;
95 bytes -= avail;
96 offset = 0;
97 put_bh(bh[i]);
98 }
99
100 res = lzo1x_decompress_safe(stream->input, (size_t)length,
101 stream->output, &out_len);
102 if (res != LZO_E_OK)
103 goto failed;
104
105 res = bytes = (int)out_len;
106 for (i = 0, buff = stream->output; bytes && i < pages; i++) {
107 avail = min_t(int, bytes, PAGE_CACHE_SIZE);
108 memcpy(buffer[i], buff, avail);
109 buff += avail;
110 bytes -= avail;
111 }
112
113 mutex_unlock(&msblk->read_data_mutex);
114 return res;
115
116block_release:
117 for (; i < b; i++)
118 put_bh(bh[i]);
119
120failed:
121 mutex_unlock(&msblk->read_data_mutex);
122
123 ERROR("lzo decompression failed, data probably corrupt\n");
124 return -EIO;
125}
126
127const struct squashfs_decompressor squashfs_lzo_comp_ops = {
128 .init = lzo_init,
129 .free = lzo_free,
130 .decompress = lzo_uncompress,
131 .id = LZO_COMPRESSION,
132 .name = "lzo",
133 .supported = 1
134};
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 733a17c42945..3a95ea68b00f 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -104,3 +104,6 @@ extern const struct xattr_handler *squashfs_xattr_handlers[];
104 104
105/* zlib_wrapper.c */ 105/* zlib_wrapper.c */
106extern const struct squashfs_decompressor squashfs_zlib_comp_ops; 106extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
107
108/* lzo_wrappers.c */
109extern const struct squashfs_decompressor squashfs_lzo_comp_ops;