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
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
10 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
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(-)
28 --- a/fs/squashfs/block.c
29 +++ b/fs/squashfs/block.c
31 #include <linux/slab.h>
32 #include <linux/string.h>
33 #include <linux/buffer_head.h>
34 -#include <linux/zlib.h>
36 #include "squashfs_fs.h"
37 #include "squashfs_fs_sb.h"
38 --- a/fs/squashfs/cache.c
39 +++ b/fs/squashfs/cache.c
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>
47 #include "squashfs_fs.h"
48 --- a/fs/squashfs/dir.c
49 +++ b/fs/squashfs/dir.c
52 #include <linux/vfs.h>
53 #include <linux/slab.h>
54 -#include <linux/zlib.h>
56 #include "squashfs_fs.h"
57 #include "squashfs_fs_sb.h"
58 --- a/fs/squashfs/export.c
59 +++ b/fs/squashfs/export.c
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>
67 #include "squashfs_fs.h"
68 --- a/fs/squashfs/file.c
69 +++ b/fs/squashfs/file.c
71 #include <linux/string.h>
72 #include <linux/pagemap.h>
73 #include <linux/mutex.h>
74 -#include <linux/zlib.h>
76 #include "squashfs_fs.h"
77 #include "squashfs_fs_sb.h"
78 --- a/fs/squashfs/fragment.c
79 +++ b/fs/squashfs/fragment.c
82 #include <linux/vfs.h>
83 #include <linux/slab.h>
84 -#include <linux/zlib.h>
86 #include "squashfs_fs.h"
87 #include "squashfs_fs_sb.h"
88 --- a/fs/squashfs/id.c
89 +++ b/fs/squashfs/id.c
92 #include <linux/vfs.h>
93 #include <linux/slab.h>
94 -#include <linux/zlib.h>
96 #include "squashfs_fs.h"
97 #include "squashfs_fs_sb.h"
98 --- a/fs/squashfs/inode.c
99 +++ b/fs/squashfs/inode.c
102 #include <linux/fs.h>
103 #include <linux/vfs.h>
104 -#include <linux/zlib.h>
106 #include "squashfs_fs.h"
107 #include "squashfs_fs_sb.h"
108 --- a/fs/squashfs/namei.c
109 +++ b/fs/squashfs/namei.c
111 #include <linux/slab.h>
112 #include <linux/string.h>
113 #include <linux/dcache.h>
114 -#include <linux/zlib.h>
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);
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);
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;
137 __le64 *inode_lookup_table;
140 --- a/fs/squashfs/super.c
141 +++ b/fs/squashfs/super.c
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>
149 #include "squashfs_fs.h"
150 @@ -86,12 +85,9 @@ static int squashfs_fill_super(struct su
152 msblk = sb->s_fs_info;
154 - msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
156 - if (msblk->stream.workspace == NULL) {
157 - ERROR("Failed to allocate zlib workspace\n");
158 + msblk->stream = zlib_init();
159 + if (msblk->stream == NULL)
163 sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
165 @@ -291,17 +287,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;
180 - kfree(msblk->stream.workspace);
181 + zlib_free(msblk->stream);
182 kfree(sb->s_fs_info);
183 sb->s_fs_info = NULL;
185 @@ -343,10 +339,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;
197 --- a/fs/squashfs/symlink.c
198 +++ b/fs/squashfs/symlink.c
200 #include <linux/slab.h>
201 #include <linux/string.h>
202 #include <linux/pagemap.h>
203 -#include <linux/zlib.h>
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
210 #include "squashfs_fs_i.h"
211 #include "squashfs.h"
215 + z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
216 + if (stream == NULL)
218 + stream->workspace = kmalloc(zlib_inflate_workspacesize(),
220 + if (stream->workspace == NULL)
226 + ERROR("Failed to allocate zlib workspace\n");
232 +void zlib_free(void *strm)
234 + z_stream *stream = strm;
237 + kfree(stream->workspace);
242 int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
243 struct buffer_head **bh, int b, int offset, int length, int srclength,
246 int zlib_err = 0, zlib_init = 0;
247 int avail, bytes, k = 0, page = 0;
248 + z_stream *stream = msblk->stream;
250 mutex_lock(&msblk->read_data_mutex);
252 - msblk->stream.avail_out = 0;
253 - msblk->stream.avail_in = 0;
254 + stream->avail_out = 0;
255 + stream->avail_in = 0;
259 - if (msblk->stream.avail_in == 0 && k < b) {
260 + if (stream->avail_in == 0 && k < b) {
261 avail = min(bytes, msblk->devblksize - offset);
263 wait_on_buffer(bh[k]);
264 @@ -58,18 +88,18 @@ int zlib_uncompress(struct squashfs_sb_i
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;
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;
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
293 - zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
294 + zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH);
296 - if (msblk->stream.avail_in == 0 && k < b)
297 + if (stream->avail_in == 0 && k < b)
299 } while (zlib_err == Z_OK);
301 @@ -90,14 +120,14 @@ int zlib_uncompress(struct squashfs_sb_i
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");
312 mutex_unlock(&msblk->read_data_mutex);
313 - return msblk->stream.total_out;
314 + return stream->total_out;
317 mutex_unlock(&msblk->read_data_mutex);