ar71xx: enable the IP17xx driver for the nand subtarget
[openwrt.git] / target / linux / generic-2.6 / patches-2.6.31 / 001-squashfs_move_zlib_decomp.patch
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
5
6 Signed-off-by: Phillip Lougher <phillip@lougher.demon.co.uk>
7 ---
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
14
15 --- a/fs/squashfs/Makefile
16 +++ b/fs/squashfs/Makefile
17 @@ -4,4 +4,4 @@
18
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
25 @@ -29,7 +29,6 @@
26 #include <linux/fs.h>
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
34 }
35
36 if (compressed) {
37 - int zlib_err = 0, zlib_init = 0;
38 -
39 - /*
40 - * Uncompress block.
41 - */
42 -
43 - mutex_lock(&msblk->read_data_mutex);
44 -
45 - msblk->stream.avail_out = 0;
46 - msblk->stream.avail_in = 0;
47 -
48 - bytes = length;
49 - do {
50 - if (msblk->stream.avail_in == 0 && k < b) {
51 - avail = min(bytes, msblk->devblksize - offset);
52 - bytes -= avail;
53 - wait_on_buffer(bh[k]);
54 - if (!buffer_uptodate(bh[k]))
55 - goto release_mutex;
56 -
57 - if (avail == 0) {
58 - offset = 0;
59 - put_bh(bh[k++]);
60 - continue;
61 - }
62 -
63 - msblk->stream.next_in = bh[k]->b_data + offset;
64 - msblk->stream.avail_in = avail;
65 - offset = 0;
66 - }
67 -
68 - if (msblk->stream.avail_out == 0 && page < pages) {
69 - msblk->stream.next_out = buffer[page++];
70 - msblk->stream.avail_out = PAGE_CACHE_SIZE;
71 - }
72 -
73 - if (!zlib_init) {
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,
79 - srclength);
80 - goto release_mutex;
81 - }
82 - zlib_init = 1;
83 - }
84 -
85 - zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
86 -
87 - if (msblk->stream.avail_in == 0 && k < b)
88 - put_bh(bh[k++]);
89 - } while (zlib_err == Z_OK);
90 -
91 - if (zlib_err != Z_STREAM_END) {
92 - ERROR("zlib_inflate error, data probably corrupt\n");
93 - goto release_mutex;
94 - }
95 -
96 - zlib_err = zlib_inflateEnd(&msblk->stream);
97 - if (zlib_err != Z_OK) {
98 - ERROR("zlib_inflate error, data probably corrupt\n");
99 - goto release_mutex;
100 - }
101 - length = msblk->stream.total_out;
102 - mutex_unlock(&msblk->read_data_mutex);
103 + length = zlib_uncompress(msblk, buffer, bh, b, offset, length,
104 + srclength, pages);
105 + if (length < 0)
106 + goto read_failure;
107 } else {
108 /*
109 * Block is uncompressed.
110 @@ -255,9 +192,6 @@ int squashfs_read_data(struct super_bloc
111 kfree(bh);
112 return length;
113
114 -release_mutex:
115 - mutex_unlock(&msblk->read_data_mutex);
116 -
117 block_release:
118 for (; k < b; k++)
119 put_bh(bh[k]);
120 --- a/fs/squashfs/squashfs.h
121 +++ b/fs/squashfs/squashfs.h
122 @@ -70,6 +70,10 @@ extern struct inode *squashfs_iget(struc
123 unsigned int);
124 extern int squashfs_read_inode(struct inode *, long long);
125
126 +/* zlib_wrapper.c */
127 +extern int zlib_uncompress(struct squashfs_sb_info *, void **,
128 + struct buffer_head **, int, int, int, int, int);
129 +
130 /*
131 * Inodes and files operations
132 */
133 --- /dev/null
134 +++ b/fs/squashfs/zlib_wrapper.c
135 @@ -0,0 +1,109 @@
136 +/*
137 + * Squashfs - a compressed read only filesystem for Linux
138 + *
139 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
140 + * Phillip Lougher <phillip@lougher.demon.co.uk>
141 + *
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.
146 + *
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.
151 + *
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.
155 + *
156 + * zlib_wrapper.c
157 + */
158 +
159 +
160 +#include <linux/mutex.h>
161 +#include <linux/buffer_head.h>
162 +#include <linux/zlib.h>
163 +
164 +#include "squashfs_fs.h"
165 +#include "squashfs_fs_sb.h"
166 +#include "squashfs_fs_i.h"
167 +#include "squashfs.h"
168 +
169 +int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
170 + struct buffer_head **bh, int b, int offset, int length, int srclength,
171 + int pages)
172 +{
173 + int zlib_err = 0, zlib_init = 0;
174 + int avail, bytes, k = 0, page = 0;
175 +
176 + mutex_lock(&msblk->read_data_mutex);
177 +
178 + msblk->stream.avail_out = 0;
179 + msblk->stream.avail_in = 0;
180 +
181 + bytes = length;
182 + do {
183 + if (msblk->stream.avail_in == 0 && k < b) {
184 + avail = min(bytes, msblk->devblksize - offset);
185 + bytes -= avail;
186 + wait_on_buffer(bh[k]);
187 + if (!buffer_uptodate(bh[k]))
188 + goto release_mutex;
189 +
190 + if (avail == 0) {
191 + offset = 0;
192 + put_bh(bh[k++]);
193 + continue;
194 + }
195 +
196 + msblk->stream.next_in = bh[k]->b_data + offset;
197 + msblk->stream.avail_in = avail;
198 + offset = 0;
199 + }
200 +
201 + if (msblk->stream.avail_out == 0 && page < pages) {
202 + msblk->stream.next_out = buffer[page++];
203 + msblk->stream.avail_out = PAGE_CACHE_SIZE;
204 + }
205 +
206 + if (!zlib_init) {
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;
213 + }
214 + zlib_init = 1;
215 + }
216 +
217 + zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
218 +
219 + if (msblk->stream.avail_in == 0 && k < b)
220 + put_bh(bh[k++]);
221 + } while (zlib_err == Z_OK);
222 +
223 + if (zlib_err != Z_STREAM_END) {
224 + ERROR("zlib_inflate error, data probably corrupt\n");
225 + goto release_mutex;
226 + }
227 +
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;
232 + }
233 +
234 + mutex_unlock(&msblk->read_data_mutex);
235 + return msblk->stream.total_out;
236 +
237 +release_mutex:
238 + mutex_unlock(&msblk->read_data_mutex);
239 +
240 + for (; k < b; k++)
241 + put_bh(bh[k]);
242 +
243 + return -EIO;
244 +}
This page took 0.056264 seconds and 5 git commands to generate.