aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fs/squashfs/Makefile2
-rw-r--r--fs/squashfs/block.c74
-rw-r--r--fs/squashfs/squashfs.h4
-rw-r--r--fs/squashfs/zlib_wrapper.c109
4 files changed, 118 insertions, 71 deletions
diff --git a/fs/squashfs/Makefile b/fs/squashfs/Makefile
index 70e3244fa30f..a397e6f12ab5 100644
--- a/fs/squashfs/Makefile
+++ b/fs/squashfs/Makefile
@@ -4,4 +4,4 @@
4 4
5obj-$(CONFIG_SQUASHFS) += squashfs.o 5obj-$(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 7squashfs-y += namei.o super.o symlink.o zlib_wrapper.o
diff --git a/fs/squashfs/block.c b/fs/squashfs/block.c
index 2a7960310349..b8addfdc6094 100644
--- a/fs/squashfs/block.c
+++ b/fs/squashfs/block.c
@@ -29,7 +29,6 @@
29#include <linux/fs.h> 29#include <linux/fs.h>
30#include <linux/vfs.h> 30#include <linux/vfs.h>
31#include <linux/slab.h> 31#include <linux/slab.h>
32#include <linux/mutex.h>
33#include <linux/string.h> 32#include <linux/string.h>
34#include <linux/buffer_head.h> 33#include <linux/buffer_head.h>
35#include <linux/zlib.h> 34#include <linux/zlib.h>
@@ -153,72 +152,10 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
153 } 152 }
154 153
155 if (compressed) { 154 if (compressed) {
156 int zlib_err = 0, zlib_init = 0; 155 length = squashfs_zlib_uncompress(msblk, buffer, bh, b, offset,
157 156 length, srclength, pages);
158 /* 157 if (length < 0)
159 * Uncompress block. 158 goto read_failure;
160 */
161
162 mutex_lock(&msblk->read_data_mutex);
163
164 msblk->stream.avail_out = 0;
165 msblk->stream.avail_in = 0;
166
167 bytes = length;
168 do {
169 if (msblk->stream.avail_in == 0 && k < b) {
170 avail = min(bytes, msblk->devblksize - offset);
171 bytes -= avail;
172 wait_on_buffer(bh[k]);
173 if (!buffer_uptodate(bh[k]))
174 goto release_mutex;
175
176 if (avail == 0) {
177 offset = 0;
178 put_bh(bh[k++]);
179 continue;
180 }
181
182 msblk->stream.next_in = bh[k]->b_data + offset;
183 msblk->stream.avail_in = avail;
184 offset = 0;
185 }
186
187 if (msblk->stream.avail_out == 0 && page < pages) {
188 msblk->stream.next_out = buffer[page++];
189 msblk->stream.avail_out = PAGE_CACHE_SIZE;
190 }
191
192 if (!zlib_init) {
193 zlib_err = zlib_inflateInit(&msblk->stream);
194 if (zlib_err != Z_OK) {
195 ERROR("zlib_inflateInit returned"
196 " unexpected result 0x%x,"
197 " srclength %d\n", zlib_err,
198 srclength);
199 goto release_mutex;
200 }
201 zlib_init = 1;
202 }
203
204 zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
205
206 if (msblk->stream.avail_in == 0 && k < b)
207 put_bh(bh[k++]);
208 } while (zlib_err == Z_OK);
209
210 if (zlib_err != Z_STREAM_END) {
211 ERROR("zlib_inflate error, data probably corrupt\n");
212 goto release_mutex;
213 }
214
215 zlib_err = zlib_inflateEnd(&msblk->stream);
216 if (zlib_err != Z_OK) {
217 ERROR("zlib_inflate error, data probably corrupt\n");
218 goto release_mutex;
219 }
220 length = msblk->stream.total_out;
221 mutex_unlock(&msblk->read_data_mutex);
222 } else { 159 } else {
223 /* 160 /*
224 * Block is uncompressed. 161 * Block is uncompressed.
@@ -255,9 +192,6 @@ int squashfs_read_data(struct super_block *sb, void **buffer, u64 index,
255 kfree(bh); 192 kfree(bh);
256 return length; 193 return length;
257 194
258release_mutex:
259 mutex_unlock(&msblk->read_data_mutex);
260
261block_release: 195block_release:
262 for (; k < b; k++) 196 for (; k < b; k++)
263 put_bh(bh[k]); 197 put_bh(bh[k]);
diff --git a/fs/squashfs/squashfs.h b/fs/squashfs/squashfs.h
index 0e9feb6adf7e..ba87db693651 100644
--- a/fs/squashfs/squashfs.h
+++ b/fs/squashfs/squashfs.h
@@ -70,6 +70,10 @@ extern struct inode *squashfs_iget(struct super_block *, long long,
70 unsigned int); 70 unsigned int);
71extern int squashfs_read_inode(struct inode *, long long); 71extern int squashfs_read_inode(struct inode *, long long);
72 72
73/* zlib_wrapper.c */
74extern int squashfs_zlib_uncompress(struct squashfs_sb_info *, void **,
75 struct buffer_head **, int, int, int, int, int);
76
73/* 77/*
74 * Inodes and files operations 78 * Inodes and files operations
75 */ 79 */
diff --git a/fs/squashfs/zlib_wrapper.c b/fs/squashfs/zlib_wrapper.c
new file mode 100644
index 000000000000..3be99642d6af
--- /dev/null
+++ b/fs/squashfs/zlib_wrapper.c
@@ -0,0 +1,109 @@
1/*
2 * Squashfs - a compressed read only filesystem for Linux
3 *
4 * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 * Phillip Lougher <phillip@lougher.demon.co.uk>
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 * zlib_wrapper.c
22 */
23
24
25#include <linux/mutex.h>
26#include <linux/buffer_head.h>
27#include <linux/zlib.h>
28
29#include "squashfs_fs.h"
30#include "squashfs_fs_sb.h"
31#include "squashfs_fs_i.h"
32#include "squashfs.h"
33
34int squashfs_zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
35 struct buffer_head **bh, int b, int offset, int length, int srclength,
36 int pages)
37{
38 int zlib_err = 0, zlib_init = 0;
39 int avail, bytes, k = 0, page = 0;
40
41 mutex_lock(&msblk->read_data_mutex);
42
43 msblk->stream.avail_out = 0;
44 msblk->stream.avail_in = 0;
45
46 bytes = length;
47 do {
48 if (msblk->stream.avail_in == 0 && k < b) {
49 avail = min(bytes, msblk->devblksize - offset);
50 bytes -= avail;
51 wait_on_buffer(bh[k]);
52 if (!buffer_uptodate(bh[k]))
53 goto release_mutex;
54
55 if (avail == 0) {
56 offset = 0;
57 put_bh(bh[k++]);
58 continue;
59 }
60
61 msblk->stream.next_in = bh[k]->b_data + offset;
62 msblk->stream.avail_in = avail;
63 offset = 0;
64 }
65
66 if (msblk->stream.avail_out == 0 && page < pages) {
67 msblk->stream.next_out = buffer[page++];
68 msblk->stream.avail_out = PAGE_CACHE_SIZE;
69 }
70
71 if (!zlib_init) {
72 zlib_err = zlib_inflateInit(&msblk->stream);
73 if (zlib_err != Z_OK) {
74 ERROR("zlib_inflateInit returned unexpected "
75 "result 0x%x, srclength %d\n",
76 zlib_err, srclength);
77 goto release_mutex;
78 }
79 zlib_init = 1;
80 }
81
82 zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
83
84 if (msblk->stream.avail_in == 0 && k < b)
85 put_bh(bh[k++]);
86 } while (zlib_err == Z_OK);
87
88 if (zlib_err != Z_STREAM_END) {
89 ERROR("zlib_inflate error, data probably corrupt\n");
90 goto release_mutex;
91 }
92
93 zlib_err = zlib_inflateEnd(&msblk->stream);
94 if (zlib_err != Z_OK) {
95 ERROR("zlib_inflate error, data probably corrupt\n");
96 goto release_mutex;
97 }
98
99 mutex_unlock(&msblk->read_data_mutex);
100 return msblk->stream.total_out;
101
102release_mutex:
103 mutex_unlock(&msblk->read_data_mutex);
104
105 for (; k < b; k++)
106 put_bh(bh[k]);
107
108 return -EIO;
109}