kernel: disable CONFIG_LEDS_TRIGGER_HEARTBEAT by default, nothing uses it
[openwrt.git] / target / linux / generic / patches-2.6.37 / 006-squashfs_add_lzma.patch
1 From f49e1efdd179d54e814ff2a8e8f469496583062c Mon Sep 17 00:00:00 2001
2 From: Phillip Lougher <phillip@lougher.demon.co.uk>
3 Date: Tue, 20 Oct 2009 10:54:36 +0100
4 Subject: [PATCH] Squashfs: add LZMA compression
5
6 Add support for LZMA compressed filesystems. This is an initial
7 implementation.
8
9 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
10 ---
11 fs/squashfs/Kconfig | 5 ++
12 fs/squashfs/Makefile | 1 +
13 fs/squashfs/decompressor.c | 4 +
14 fs/squashfs/lzma_wrapper.c | 151 ++++++++++++++++++++++++++++++++++++++++++++
15 fs/squashfs/squashfs.h | 3 +
16 5 files changed, 164 insertions(+), 0 deletions(-)
17 create mode 100644 fs/squashfs/lzma_wrapper.c
18
19 --- a/fs/squashfs/Kconfig
20 +++ b/fs/squashfs/Kconfig
21 @@ -37,6 +37,11 @@ config SQUASHFS_XATTRS
22
23 If unsure, say N.
24
25 +config SQUASHFS_LZMA
26 + bool "Include support for LZMA compressed file systems"
27 + depends on SQUASHFS
28 + select DECOMPRESS_LZMA
29 +
30 config SQUASHFS_EMBEDDED
31
32 bool "Additional option for memory-constrained systems"
33 --- a/fs/squashfs/Makefile
34 +++ b/fs/squashfs/Makefile
35 @@ -5,5 +5,5 @@
36 obj-$(CONFIG_SQUASHFS) += squashfs.o
37 squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
38 squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
39 -squashfs-$(CONFIG_SQUASHFS_XATTRS) += xattr.o xattr_id.o
40 +squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o
41
42 --- a/fs/squashfs/decompressor.c
43 +++ b/fs/squashfs/decompressor.c
44 @@ -50,7 +50,11 @@ static const struct squashfs_decompresso
45
46 static const struct squashfs_decompressor *decompressor[] = {
47 &squashfs_zlib_comp_ops,
48 +#ifdef CONFIG_SQUASHFS_LZMA
49 + &squashfs_lzma_comp_ops,
50 +#else
51 &squashfs_lzma_unsupported_comp_ops,
52 +#endif
53 &squashfs_lzo_unsupported_comp_ops,
54 &squashfs_unknown_comp_ops
55 };
56 --- /dev/null
57 +++ b/fs/squashfs/lzma_wrapper.c
58 @@ -0,0 +1,152 @@
59 +/*
60 + * Squashfs - a compressed read only filesystem for Linux
61 + *
62 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
63 + * Phillip Lougher <phillip@lougher.demon.co.uk>
64 + *
65 + * This program is free software; you can redistribute it and/or
66 + * modify it under the terms of the GNU General Public License
67 + * as published by the Free Software Foundation; either version 2,
68 + * or (at your option) any later version.
69 + *
70 + * This program is distributed in the hope that it will be useful,
71 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
72 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
73 + * GNU General Public License for more details.
74 + *
75 + * You should have received a copy of the GNU General Public License
76 + * along with this program; if not, write to the Free Software
77 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
78 + *
79 + * lzma_wrapper.c
80 + */
81 +
82 +#include <asm/unaligned.h>
83 +#include <linux/buffer_head.h>
84 +#include <linux/mutex.h>
85 +#include <linux/vmalloc.h>
86 +#include <linux/decompress/unlzma.h>
87 +#include <linux/slab.h>
88 +
89 +#include "squashfs_fs.h"
90 +#include "squashfs_fs_sb.h"
91 +#include "squashfs_fs_i.h"
92 +#include "squashfs.h"
93 +#include "decompressor.h"
94 +
95 +struct squashfs_lzma {
96 + void *input;
97 + void *output;
98 +};
99 +
100 +/* decompress_unlzma.c is currently non re-entrant... */
101 +DEFINE_MUTEX(lzma_mutex);
102 +
103 +/* decompress_unlzma.c doesn't provide any context in its callbacks... */
104 +static int lzma_error;
105 +
106 +static void error(char *m)
107 +{
108 + ERROR("unlzma error: %s\n", m);
109 + lzma_error = 1;
110 +}
111 +
112 +
113 +static void *lzma_init(struct squashfs_sb_info *msblk)
114 +{
115 + struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
116 + if (stream == NULL)
117 + goto failed;
118 + stream->input = vmalloc(msblk->block_size);
119 + if (stream->input == NULL)
120 + goto failed;
121 + stream->output = vmalloc(msblk->block_size);
122 + if (stream->output == NULL)
123 + goto failed2;
124 +
125 + return stream;
126 +
127 +failed2:
128 + vfree(stream->input);
129 +failed:
130 + ERROR("failed to allocate lzma workspace\n");
131 + kfree(stream);
132 + return NULL;
133 +}
134 +
135 +
136 +static void lzma_free(void *strm)
137 +{
138 + struct squashfs_lzma *stream = strm;
139 +
140 + if (stream) {
141 + vfree(stream->input);
142 + vfree(stream->output);
143 + }
144 + kfree(stream);
145 +}
146 +
147 +
148 +static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,
149 + struct buffer_head **bh, int b, int offset, int length, int srclength,
150 + int pages)
151 +{
152 + struct squashfs_lzma *stream = msblk->stream;
153 + void *buff = stream->input;
154 + int avail, i, bytes = length, res;
155 +
156 + mutex_lock(&lzma_mutex);
157 +
158 + for (i = 0; i < b; i++) {
159 + wait_on_buffer(bh[i]);
160 + if (!buffer_uptodate(bh[i]))
161 + goto block_release;
162 +
163 + avail = min(bytes, msblk->devblksize - offset);
164 + memcpy(buff, bh[i]->b_data + offset, avail);
165 + buff += avail;
166 + bytes -= avail;
167 + offset = 0;
168 + put_bh(bh[i]);
169 + }
170 +
171 + lzma_error = 0;
172 + res = unlzma(stream->input, length, NULL, NULL, stream->output, NULL,
173 + error);
174 + if (res || lzma_error)
175 + goto failed;
176 +
177 + /* uncompressed size is stored in the LZMA header (5 byte offset) */
178 + res = bytes = get_unaligned_le32(stream->input + 5);
179 + for (i = 0, buff = stream->output; bytes && i < pages; i++) {
180 + avail = min_t(int, bytes, PAGE_CACHE_SIZE);
181 + memcpy(buffer[i], buff, avail);
182 + buff += avail;
183 + bytes -= avail;
184 + }
185 + if (bytes)
186 + goto failed;
187 +
188 + mutex_unlock(&lzma_mutex);
189 + return res;
190 +
191 +block_release:
192 + for (; i < b; i++)
193 + put_bh(bh[i]);
194 +
195 +failed:
196 + mutex_unlock(&lzma_mutex);
197 +
198 + ERROR("lzma decompression failed, data probably corrupt\n");
199 + return -EIO;
200 +}
201 +
202 +const struct squashfs_decompressor squashfs_lzma_comp_ops = {
203 + .init = lzma_init,
204 + .free = lzma_free,
205 + .decompress = lzma_uncompress,
206 + .id = LZMA_COMPRESSION,
207 + .name = "lzma",
208 + .supported = 1
209 +};
210 +
211 --- a/fs/squashfs/squashfs.h
212 +++ b/fs/squashfs/squashfs.h
213 @@ -104,3 +104,6 @@ extern const struct xattr_handler *squas
214
215 /* zlib_wrapper.c */
216 extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
217 +
218 +/* lzma wrapper.c */
219 +extern const struct squashfs_decompressor squashfs_lzma_comp_ops;
This page took 0.050233 seconds and 5 git commands to generate.