generic/patches-2.6.32: finalize jffs2/lzma support on 2.6.32.x
[openwrt.git] / target / linux / generic / patches-2.6.33 / 002-squashfs_factor_out_remaining_zlib.patch
1 From 37c44e85fd49676ec15ccaeea065662c1fbcda7d Mon Sep 17 00:00:00 2001
2 From: Phillip Lougher <phillip@lougher.demon.co.uk>
3 Date: Wed, 23 Sep 2009 19:04:49 +0100
4 Subject: [PATCH] Squashfs: Factor out remaining zlib dependencies into separate wrapper file
5
6 Move zlib buffer init/destroy code into separate wrapper file. Also
7 make zlib z_stream field a void * removing the need to include zlib.h
8 for most files.
9
10 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
11 ---
12 fs/squashfs/block.c | 1 -
13 fs/squashfs/cache.c | 1 -
14 fs/squashfs/dir.c | 1 -
15 fs/squashfs/export.c | 1 -
16 fs/squashfs/file.c | 1 -
17 fs/squashfs/fragment.c | 1 -
18 fs/squashfs/id.c | 1 -
19 fs/squashfs/inode.c | 1 -
20 fs/squashfs/namei.c | 1 -
21 fs/squashfs/squashfs.h | 2 +
22 fs/squashfs/squashfs_fs_sb.h | 2 +-
23 fs/squashfs/super.c | 14 +++------
24 fs/squashfs/symlink.c | 1 -
25 fs/squashfs/zlib_wrapper.c | 56 ++++++++++++++++++++++++++++++++---------
26 14 files changed, 51 insertions(+), 33 deletions(-)
27
28 --- a/fs/squashfs/block.c
29 +++ b/fs/squashfs/block.c
30 @@ -31,7 +31,6 @@
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/buffer_head.h>
34 -#include <linux/zlib.h>
35
36 #include "squashfs_fs.h"
37 #include "squashfs_fs_sb.h"
38 --- a/fs/squashfs/cache.c
39 +++ b/fs/squashfs/cache.c
40 @@ -51,7 +51,6 @@
41 #include <linux/sched.h>
42 #include <linux/spinlock.h>
43 #include <linux/wait.h>
44 -#include <linux/zlib.h>
45 #include <linux/pagemap.h>
46
47 #include "squashfs_fs.h"
48 --- a/fs/squashfs/dir.c
49 +++ b/fs/squashfs/dir.c
50 @@ -30,7 +30,6 @@
51 #include <linux/fs.h>
52 #include <linux/vfs.h>
53 #include <linux/slab.h>
54 -#include <linux/zlib.h>
55
56 #include "squashfs_fs.h"
57 #include "squashfs_fs_sb.h"
58 --- a/fs/squashfs/export.c
59 +++ b/fs/squashfs/export.c
60 @@ -39,7 +39,6 @@
61 #include <linux/vfs.h>
62 #include <linux/dcache.h>
63 #include <linux/exportfs.h>
64 -#include <linux/zlib.h>
65 #include <linux/slab.h>
66
67 #include "squashfs_fs.h"
68 --- a/fs/squashfs/file.c
69 +++ b/fs/squashfs/file.c
70 @@ -47,7 +47,6 @@
71 #include <linux/string.h>
72 #include <linux/pagemap.h>
73 #include <linux/mutex.h>
74 -#include <linux/zlib.h>
75
76 #include "squashfs_fs.h"
77 #include "squashfs_fs_sb.h"
78 --- a/fs/squashfs/fragment.c
79 +++ b/fs/squashfs/fragment.c
80 @@ -36,7 +36,6 @@
81 #include <linux/fs.h>
82 #include <linux/vfs.h>
83 #include <linux/slab.h>
84 -#include <linux/zlib.h>
85
86 #include "squashfs_fs.h"
87 #include "squashfs_fs_sb.h"
88 --- a/fs/squashfs/id.c
89 +++ b/fs/squashfs/id.c
90 @@ -34,7 +34,6 @@
91 #include <linux/fs.h>
92 #include <linux/vfs.h>
93 #include <linux/slab.h>
94 -#include <linux/zlib.h>
95
96 #include "squashfs_fs.h"
97 #include "squashfs_fs_sb.h"
98 --- a/fs/squashfs/inode.c
99 +++ b/fs/squashfs/inode.c
100 @@ -40,7 +40,6 @@
101
102 #include <linux/fs.h>
103 #include <linux/vfs.h>
104 -#include <linux/zlib.h>
105
106 #include "squashfs_fs.h"
107 #include "squashfs_fs_sb.h"
108 --- a/fs/squashfs/namei.c
109 +++ b/fs/squashfs/namei.c
110 @@ -57,7 +57,6 @@
111 #include <linux/slab.h>
112 #include <linux/string.h>
113 #include <linux/dcache.h>
114 -#include <linux/zlib.h>
115
116 #include "squashfs_fs.h"
117 #include "squashfs_fs_sb.h"
118 --- a/fs/squashfs/squashfs.h
119 +++ b/fs/squashfs/squashfs.h
120 @@ -71,6 +71,8 @@ extern struct inode *squashfs_iget(struc
121 extern int squashfs_read_inode(struct inode *, long long);
122
123 /* zlib_wrapper.c */
124 +extern void *zlib_init(void);
125 +extern void zlib_free(void *);
126 extern int zlib_uncompress(struct squashfs_sb_info *, void **,
127 struct buffer_head **, int, int, int, int, int);
128
129 --- a/fs/squashfs/squashfs_fs_sb.h
130 +++ b/fs/squashfs/squashfs_fs_sb.h
131 @@ -64,7 +64,7 @@ struct squashfs_sb_info {
132 struct mutex read_data_mutex;
133 struct mutex meta_index_mutex;
134 struct meta_index *meta_index;
135 - z_stream stream;
136 + void *stream;
137 __le64 *inode_lookup_table;
138 u64 inode_table;
139 u64 directory_table;
140 --- a/fs/squashfs/super.c
141 +++ b/fs/squashfs/super.c
142 @@ -35,7 +35,6 @@
143 #include <linux/pagemap.h>
144 #include <linux/init.h>
145 #include <linux/module.h>
146 -#include <linux/zlib.h>
147 #include <linux/magic.h>
148
149 #include "squashfs_fs.h"
150 @@ -87,12 +86,9 @@ static int squashfs_fill_super(struct su
151 }
152 msblk = sb->s_fs_info;
153
154 - msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
155 - GFP_KERNEL);
156 - if (msblk->stream.workspace == NULL) {
157 - ERROR("Failed to allocate zlib workspace\n");
158 + msblk->stream = zlib_init();
159 + if (msblk->stream == NULL)
160 goto failure;
161 - }
162
163 sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
164 if (sblk == NULL) {
165 @@ -292,17 +288,17 @@ failed_mount:
166 squashfs_cache_delete(msblk->block_cache);
167 squashfs_cache_delete(msblk->fragment_cache);
168 squashfs_cache_delete(msblk->read_page);
169 + zlib_free(msblk->stream);
170 kfree(msblk->inode_lookup_table);
171 kfree(msblk->fragment_index);
172 kfree(msblk->id_table);
173 - kfree(msblk->stream.workspace);
174 kfree(sb->s_fs_info);
175 sb->s_fs_info = NULL;
176 kfree(sblk);
177 return err;
178
179 failure:
180 - kfree(msblk->stream.workspace);
181 + zlib_free(msblk->stream);
182 kfree(sb->s_fs_info);
183 sb->s_fs_info = NULL;
184 return -ENOMEM;
185 @@ -346,10 +342,10 @@ static void squashfs_put_super(struct su
186 squashfs_cache_delete(sbi->block_cache);
187 squashfs_cache_delete(sbi->fragment_cache);
188 squashfs_cache_delete(sbi->read_page);
189 + zlib_free(sbi->stream);
190 kfree(sbi->id_table);
191 kfree(sbi->fragment_index);
192 kfree(sbi->meta_index);
193 - kfree(sbi->stream.workspace);
194 kfree(sb->s_fs_info);
195 sb->s_fs_info = NULL;
196 }
197 --- a/fs/squashfs/symlink.c
198 +++ b/fs/squashfs/symlink.c
199 @@ -36,7 +36,6 @@
200 #include <linux/slab.h>
201 #include <linux/string.h>
202 #include <linux/pagemap.h>
203 -#include <linux/zlib.h>
204
205 #include "squashfs_fs.h"
206 #include "squashfs_fs_sb.h"
207 --- a/fs/squashfs/zlib_wrapper.c
208 +++ b/fs/squashfs/zlib_wrapper.c
209 @@ -31,21 +31,51 @@
210 #include "squashfs_fs_i.h"
211 #include "squashfs.h"
212
213 +void *zlib_init()
214 +{
215 + z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
216 + if (stream == NULL)
217 + goto failed;
218 + stream->workspace = kmalloc(zlib_inflate_workspacesize(),
219 + GFP_KERNEL);
220 + if (stream->workspace == NULL)
221 + goto failed;
222 +
223 + return stream;
224 +
225 +failed:
226 + ERROR("Failed to allocate zlib workspace\n");
227 + kfree(stream);
228 + return NULL;
229 +}
230 +
231 +
232 +void zlib_free(void *strm)
233 +{
234 + z_stream *stream = strm;
235 +
236 + if (stream)
237 + kfree(stream->workspace);
238 + kfree(stream);
239 +}
240 +
241 +
242 int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
243 struct buffer_head **bh, int b, int offset, int length, int srclength,
244 int pages)
245 {
246 int zlib_err = 0, zlib_init = 0;
247 int avail, bytes, k = 0, page = 0;
248 + z_stream *stream = msblk->stream;
249
250 mutex_lock(&msblk->read_data_mutex);
251
252 - msblk->stream.avail_out = 0;
253 - msblk->stream.avail_in = 0;
254 + stream->avail_out = 0;
255 + stream->avail_in = 0;
256
257 bytes = length;
258 do {
259 - if (msblk->stream.avail_in == 0 && k < b) {
260 + if (stream->avail_in == 0 && k < b) {
261 avail = min(bytes, msblk->devblksize - offset);
262 bytes -= avail;
263 wait_on_buffer(bh[k]);
264 @@ -58,18 +88,18 @@ int zlib_uncompress(struct squashfs_sb_i
265 continue;
266 }
267
268 - msblk->stream.next_in = bh[k]->b_data + offset;
269 - msblk->stream.avail_in = avail;
270 + stream->next_in = bh[k]->b_data + offset;
271 + stream->avail_in = avail;
272 offset = 0;
273 }
274
275 - if (msblk->stream.avail_out == 0 && page < pages) {
276 - msblk->stream.next_out = buffer[page++];
277 - msblk->stream.avail_out = PAGE_CACHE_SIZE;
278 + if (stream->avail_out == 0 && page < pages) {
279 + stream->next_out = buffer[page++];
280 + stream->avail_out = PAGE_CACHE_SIZE;
281 }
282
283 if (!zlib_init) {
284 - zlib_err = zlib_inflateInit(&msblk->stream);
285 + zlib_err = zlib_inflateInit(stream);
286 if (zlib_err != Z_OK) {
287 ERROR("zlib_inflateInit returned unexpected "
288 "result 0x%x, srclength %d\n",
289 @@ -79,9 +109,9 @@ int zlib_uncompress(struct squashfs_sb_i
290 zlib_init = 1;
291 }
292
293 - zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
294 + zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH);
295
296 - if (msblk->stream.avail_in == 0 && k < b)
297 + if (stream->avail_in == 0 && k < b)
298 put_bh(bh[k++]);
299 } while (zlib_err == Z_OK);
300
301 @@ -90,14 +120,14 @@ int zlib_uncompress(struct squashfs_sb_i
302 goto release_mutex;
303 }
304
305 - zlib_err = zlib_inflateEnd(&msblk->stream);
306 + zlib_err = zlib_inflateEnd(stream);
307 if (zlib_err != Z_OK) {
308 ERROR("zlib_inflate error, data probably corrupt\n");
309 goto release_mutex;
310 }
311
312 mutex_unlock(&msblk->read_data_mutex);
313 - return msblk->stream.total_out;
314 + return stream->total_out;
315
316 release_mutex:
317 mutex_unlock(&msblk->read_data_mutex);
This page took 0.059954 seconds and 5 git commands to generate.