1 From 6c4419d997d4431bb62e73475cd6b084e83efbd1 Mon Sep 17 00:00:00 2001
2 From: Phillip Lougher <phillip@lougher.demon.co.uk>
3 Date: Tue, 22 Sep 2009 19:25:24 +0100
4 Subject: [PATCH] Squashfs: move zlib decompression wrapper code into a separate file
6 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
8 fs/squashfs/Makefile | 2 +-
9 fs/squashfs/block.c | 74 ++----------------------------
10 fs/squashfs/squashfs.h | 4 ++
11 fs/squashfs/zlib_wrapper.c | 109 ++++++++++++++++++++++++++++++++++++++++++++
12 4 files changed, 118 insertions(+), 71 deletions(-)
13 create mode 100644 fs/squashfs/zlib_wrapper.c
15 --- a/fs/squashfs/Makefile
16 +++ b/fs/squashfs/Makefile
19 obj-$(CONFIG_SQUASHFS) += squashfs.o
20 squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
21 -squashfs-y += namei.o super.o symlink.o
22 +squashfs-y += namei.o super.o symlink.o zlib_wrapper.o
23 --- a/fs/squashfs/block.c
24 +++ b/fs/squashfs/block.c
27 #include <linux/vfs.h>
28 #include <linux/slab.h>
29 -#include <linux/mutex.h>
30 #include <linux/string.h>
31 #include <linux/buffer_head.h>
32 #include <linux/zlib.h>
33 @@ -153,72 +152,10 @@ int squashfs_read_data(struct super_bloc
37 - int zlib_err = 0, zlib_init = 0;
43 - mutex_lock(&msblk->read_data_mutex);
45 - msblk->stream.avail_out = 0;
46 - msblk->stream.avail_in = 0;
50 - if (msblk->stream.avail_in == 0 && k < b) {
51 - avail = min(bytes, msblk->devblksize - offset);
53 - wait_on_buffer(bh[k]);
54 - if (!buffer_uptodate(bh[k]))
63 - msblk->stream.next_in = bh[k]->b_data + offset;
64 - msblk->stream.avail_in = avail;
68 - if (msblk->stream.avail_out == 0 && page < pages) {
69 - msblk->stream.next_out = buffer[page++];
70 - msblk->stream.avail_out = PAGE_CACHE_SIZE;
74 - zlib_err = zlib_inflateInit(&msblk->stream);
75 - if (zlib_err != Z_OK) {
76 - ERROR("zlib_inflateInit returned"
77 - " unexpected result 0x%x,"
78 - " srclength %d\n", zlib_err,
85 - zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
87 - if (msblk->stream.avail_in == 0 && k < b)
89 - } while (zlib_err == Z_OK);
91 - if (zlib_err != Z_STREAM_END) {
92 - ERROR("zlib_inflate error, data probably corrupt\n");
96 - zlib_err = zlib_inflateEnd(&msblk->stream);
97 - if (zlib_err != Z_OK) {
98 - ERROR("zlib_inflate error, data probably corrupt\n");
101 - length = msblk->stream.total_out;
102 - mutex_unlock(&msblk->read_data_mutex);
103 + length = zlib_uncompress(msblk, buffer, bh, b, offset, length,
109 * Block is uncompressed.
110 @@ -255,9 +192,6 @@ int squashfs_read_data(struct super_bloc
115 - mutex_unlock(&msblk->read_data_mutex);
120 --- a/fs/squashfs/squashfs.h
121 +++ b/fs/squashfs/squashfs.h
122 @@ -70,6 +70,10 @@ extern struct inode *squashfs_iget(struc
124 extern int squashfs_read_inode(struct inode *, long long);
126 +/* zlib_wrapper.c */
127 +extern int zlib_uncompress(struct squashfs_sb_info *, void **,
128 + struct buffer_head **, int, int, int, int, int);
131 * Inodes and files operations
134 +++ b/fs/squashfs/zlib_wrapper.c
137 + * Squashfs - a compressed read only filesystem for Linux
139 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
140 + * Phillip Lougher <phillip@lougher.demon.co.uk>
142 + * This program is free software; you can redistribute it and/or
143 + * modify it under the terms of the GNU General Public License
144 + * as published by the Free Software Foundation; either version 2,
145 + * or (at your option) any later version.
147 + * This program is distributed in the hope that it will be useful,
148 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
149 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
150 + * GNU General Public License for more details.
152 + * You should have received a copy of the GNU General Public License
153 + * along with this program; if not, write to the Free Software
154 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
160 +#include <linux/mutex.h>
161 +#include <linux/buffer_head.h>
162 +#include <linux/zlib.h>
164 +#include "squashfs_fs.h"
165 +#include "squashfs_fs_sb.h"
166 +#include "squashfs_fs_i.h"
167 +#include "squashfs.h"
169 +int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
170 + struct buffer_head **bh, int b, int offset, int length, int srclength,
173 + int zlib_err = 0, zlib_init = 0;
174 + int avail, bytes, k = 0, page = 0;
176 + mutex_lock(&msblk->read_data_mutex);
178 + msblk->stream.avail_out = 0;
179 + msblk->stream.avail_in = 0;
183 + if (msblk->stream.avail_in == 0 && k < b) {
184 + avail = min(bytes, msblk->devblksize - offset);
186 + wait_on_buffer(bh[k]);
187 + if (!buffer_uptodate(bh[k]))
188 + goto release_mutex;
196 + msblk->stream.next_in = bh[k]->b_data + offset;
197 + msblk->stream.avail_in = avail;
201 + if (msblk->stream.avail_out == 0 && page < pages) {
202 + msblk->stream.next_out = buffer[page++];
203 + msblk->stream.avail_out = PAGE_CACHE_SIZE;
207 + zlib_err = zlib_inflateInit(&msblk->stream);
208 + if (zlib_err != Z_OK) {
209 + ERROR("zlib_inflateInit returned unexpected "
210 + "result 0x%x, srclength %d\n",
211 + zlib_err, srclength);
212 + goto release_mutex;
217 + zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
219 + if (msblk->stream.avail_in == 0 && k < b)
221 + } while (zlib_err == Z_OK);
223 + if (zlib_err != Z_STREAM_END) {
224 + ERROR("zlib_inflate error, data probably corrupt\n");
225 + goto release_mutex;
228 + zlib_err = zlib_inflateEnd(&msblk->stream);
229 + if (zlib_err != Z_OK) {
230 + ERROR("zlib_inflate error, data probably corrupt\n");
231 + goto release_mutex;
234 + mutex_unlock(&msblk->read_data_mutex);
235 + return msblk->stream.total_out;
238 + mutex_unlock(&msblk->read_data_mutex);