wok-stable diff linux/stuff/linux-squashfs-lzma-2.6.34.u @ rev 5640

Up: linux (2.6.34) Add new drivers, clean-up receipt and stuff, fix linux-video build
author Christophe Lincoln <pankso@slitaz.org>
date Fri May 28 21:08:44 2010 +0200 (2010-05-28)
parents
children 0c80e5eb512d
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linux/stuff/linux-squashfs-lzma-2.6.34.u	Fri May 28 21:08:44 2010 +0200
     1.3 @@ -0,0 +1,1624 @@
     1.4 +--- linux-2.6.30.6/fs/squashfs/Kconfig
     1.5 ++++ linux-2.6.30.6/fs/squashfs/Kconfig
     1.6 +@@ -26,6 +26,12 @@
     1.7 + 
     1.8 + 	  If unsure, say N.
     1.9 + 
    1.10 ++config SQUASHFS_LZMA
    1.11 ++	bool "Include support for LZMA compressed file systems"
    1.12 ++	depends on SQUASHFS
    1.13 ++	select DECOMPRESS_LZMA
    1.14 ++	select DECOMPRESS_LZMA_NEEDED
    1.15 ++
    1.16 + config SQUASHFS_EMBEDDED
    1.17 + 
    1.18 + 	bool "Additional option for memory-constrained systems" 
    1.19 +
    1.20 +--- linux-2.6.30.6/fs/squashfs/Makefile
    1.21 ++++ linux-2.6.30.6/fs/squashfs/Makefile
    1.22 +@@ -4,4 +4,5 @@
    1.23 + 
    1.24 + obj-$(CONFIG_SQUASHFS) += squashfs.o
    1.25 + squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
    1.26 +-squashfs-y += namei.o super.o symlink.o
    1.27 ++squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
    1.28 ++squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o
    1.29 +
    1.30 +--- linux-2.6.30.6/fs/squashfs/block.c
    1.31 ++++ linux-2.6.30.6/fs/squashfs/block.c
    1.32 +@@ -29,15 +29,14 @@
    1.33 + #include <linux/fs.h>
    1.34 + #include <linux/vfs.h>
    1.35 + #include <linux/slab.h>
    1.36 +-#include <linux/mutex.h>
    1.37 + #include <linux/string.h>
    1.38 + #include <linux/buffer_head.h>
    1.39 +-#include <linux/zlib.h>
    1.40 + 
    1.41 + #include "squashfs_fs.h"
    1.42 + #include "squashfs_fs_sb.h"
    1.43 + #include "squashfs_fs_i.h"
    1.44 + #include "squashfs.h"
    1.45 ++#include "decompressor.h"
    1.46 + 
    1.47 + /*
    1.48 +  * Read the metadata block length, this is stored in the first two
    1.49 +@@ -153,72 +152,10 @@
    1.50 + 	}
    1.51 + 
    1.52 + 	if (compressed) {
    1.53 +-		int zlib_err = 0, zlib_init = 0;
    1.54 +-
    1.55 +-		/*
    1.56 +-		 * Uncompress block.
    1.57 +-		 */
    1.58 +-
    1.59 +-		mutex_lock(&msblk->read_data_mutex);
    1.60 +-
    1.61 +-		msblk->stream.avail_out = 0;
    1.62 +-		msblk->stream.avail_in = 0;
    1.63 +-
    1.64 +-		bytes = length;
    1.65 +-		do {
    1.66 +-			if (msblk->stream.avail_in == 0 && k < b) {
    1.67 +-				avail = min(bytes, msblk->devblksize - offset);
    1.68 +-				bytes -= avail;
    1.69 +-				wait_on_buffer(bh[k]);
    1.70 +-				if (!buffer_uptodate(bh[k]))
    1.71 +-					goto release_mutex;
    1.72 +-
    1.73 +-				if (avail == 0) {
    1.74 +-					offset = 0;
    1.75 +-					put_bh(bh[k++]);
    1.76 +-					continue;
    1.77 +-				}
    1.78 +-
    1.79 +-				msblk->stream.next_in = bh[k]->b_data + offset;
    1.80 +-				msblk->stream.avail_in = avail;
    1.81 +-				offset = 0;
    1.82 +-			}
    1.83 +-
    1.84 +-			if (msblk->stream.avail_out == 0 && page < pages) {
    1.85 +-				msblk->stream.next_out = buffer[page++];
    1.86 +-				msblk->stream.avail_out = PAGE_CACHE_SIZE;
    1.87 +-			}
    1.88 +-
    1.89 +-			if (!zlib_init) {
    1.90 +-				zlib_err = zlib_inflateInit(&msblk->stream);
    1.91 +-				if (zlib_err != Z_OK) {
    1.92 +-					ERROR("zlib_inflateInit returned"
    1.93 +-						" unexpected result 0x%x,"
    1.94 +-						" srclength %d\n", zlib_err,
    1.95 +-						srclength);
    1.96 +-					goto release_mutex;
    1.97 +-				}
    1.98 +-				zlib_init = 1;
    1.99 +-			}
   1.100 +-
   1.101 +-			zlib_err = zlib_inflate(&msblk->stream, Z_SYNC_FLUSH);
   1.102 +-
   1.103 +-			if (msblk->stream.avail_in == 0 && k < b)
   1.104 +-				put_bh(bh[k++]);
   1.105 +-		} while (zlib_err == Z_OK);
   1.106 +-
   1.107 +-		if (zlib_err != Z_STREAM_END) {
   1.108 +-			ERROR("zlib_inflate error, data probably corrupt\n");
   1.109 +-			goto release_mutex;
   1.110 +-		}
   1.111 +-
   1.112 +-		zlib_err = zlib_inflateEnd(&msblk->stream);
   1.113 +-		if (zlib_err != Z_OK) {
   1.114 +-			ERROR("zlib_inflate error, data probably corrupt\n");
   1.115 +-			goto release_mutex;
   1.116 +-		}
   1.117 +-		length = msblk->stream.total_out;
   1.118 +-		mutex_unlock(&msblk->read_data_mutex);
   1.119 ++		length = squashfs_decompress(msblk, buffer, bh, b, offset,
   1.120 ++			 length, srclength, pages);
   1.121 ++		if (length < 0)
   1.122 ++			goto read_failure;
   1.123 + 	} else {
   1.124 + 		/*
   1.125 + 		 * Block is uncompressed.
   1.126 +@@ -254,9 +191,6 @@
   1.127 + 
   1.128 + 	kfree(bh);
   1.129 + 	return length;
   1.130 +-
   1.131 +-release_mutex:
   1.132 +-	mutex_unlock(&msblk->read_data_mutex);
   1.133 + 
   1.134 + block_release:
   1.135 + 	for (; k < b; k++)
   1.136 +
   1.137 +--- linux-2.6.30.6/fs/squashfs/cache.c
   1.138 ++++ linux-2.6.30.6/fs/squashfs/cache.c
   1.139 +@@ -51,7 +51,6 @@
   1.140 + #include <linux/sched.h>
   1.141 + #include <linux/spinlock.h>
   1.142 + #include <linux/wait.h>
   1.143 +-#include <linux/zlib.h>
   1.144 + #include <linux/pagemap.h>
   1.145 + 
   1.146 + #include "squashfs_fs.h"
   1.147 +
   1.148 +--- linux-2.6.30.6/fs/squashfs/decompressor.c
   1.149 ++++ linux-2.6.30.6/fs/squashfs/decompressor.c
   1.150 +@@ -0,0 +1,72 @@
   1.151 ++/*
   1.152 ++ * Squashfs - a compressed read only filesystem for Linux
   1.153 ++ *
   1.154 ++ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
   1.155 ++ * Phillip Lougher <phillip@lougher.demon.co.uk>
   1.156 ++ *
   1.157 ++ * This program is free software; you can redistribute it and/or
   1.158 ++ * modify it under the terms of the GNU General Public License
   1.159 ++ * as published by the Free Software Foundation; either version 2,
   1.160 ++ * or (at your option) any later version.
   1.161 ++ *
   1.162 ++ * This program is distributed in the hope that it will be useful,
   1.163 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.164 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.165 ++ * GNU General Public License for more details.
   1.166 ++ *
   1.167 ++ * You should have received a copy of the GNU General Public License
   1.168 ++ * along with this program; if not, write to the Free Software
   1.169 ++ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   1.170 ++ *
   1.171 ++ * decompressor.c
   1.172 ++ */
   1.173 ++
   1.174 ++#include <linux/types.h>
   1.175 ++#include <linux/mutex.h>
   1.176 ++#include <linux/buffer_head.h>
   1.177 ++
   1.178 ++#include "squashfs_fs.h"
   1.179 ++#include "squashfs_fs_sb.h"
   1.180 ++#include "squashfs_fs_i.h"
   1.181 ++#include "decompressor.h"
   1.182 ++#include "squashfs.h"
   1.183 ++
   1.184 ++/*
   1.185 ++ * This file (and decompressor.h) implements a decompressor framework for
   1.186 ++ * Squashfs, allowing multiple decompressors to be easily supported
   1.187 ++ */
   1.188 ++
   1.189 ++static const struct squashfs_decompressor squashfs_lzma_unsupported_comp_ops = {
   1.190 ++	NULL, NULL, NULL, LZMA_COMPRESSION, "lzma", 0
   1.191 ++};
   1.192 ++
   1.193 ++static const struct squashfs_decompressor squashfs_lzo_unsupported_comp_ops = {
   1.194 ++	NULL, NULL, NULL, LZO_COMPRESSION, "lzo", 0
   1.195 ++};
   1.196 ++
   1.197 ++static const struct squashfs_decompressor squashfs_unknown_comp_ops = {
   1.198 ++	NULL, NULL, NULL, 0, "unknown", 0
   1.199 ++};
   1.200 ++
   1.201 ++static const struct squashfs_decompressor *decompressor[] = {
   1.202 ++	&squashfs_zlib_comp_ops,
   1.203 ++#ifdef CONFIG_SQUASHFS_LZMA
   1.204 ++	&squashfs_lzma_comp_ops,
   1.205 ++#else
   1.206 ++	&squashfs_lzma_unsupported_comp_ops,
   1.207 ++#endif
   1.208 ++	&squashfs_lzo_unsupported_comp_ops,
   1.209 ++	&squashfs_unknown_comp_ops
   1.210 ++};
   1.211 ++
   1.212 ++
   1.213 ++const struct squashfs_decompressor *squashfs_lookup_decompressor(int id)
   1.214 ++{
   1.215 ++	int i;
   1.216 ++
   1.217 ++	for (i = 0; decompressor[i]->id; i++)
   1.218 ++		if (id == decompressor[i]->id)
   1.219 ++			break;
   1.220 ++
   1.221 ++	return decompressor[i];
   1.222 ++}
   1.223 +
   1.224 +--- linux-2.6.30.6/fs/squashfs/decompressor.h
   1.225 ++++ linux-2.6.30.6/fs/squashfs/decompressor.h
   1.226 +@@ -0,0 +1,55 @@
   1.227 ++#ifndef DECOMPRESSOR_H
   1.228 ++#define DECOMPRESSOR_H
   1.229 ++/*
   1.230 ++ * Squashfs - a compressed read only filesystem for Linux
   1.231 ++ *
   1.232 ++ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
   1.233 ++ * Phillip Lougher <phillip@lougher.demon.co.uk>
   1.234 ++ *
   1.235 ++ * This program is free software; you can redistribute it and/or
   1.236 ++ * modify it under the terms of the GNU General Public License
   1.237 ++ * as published by the Free Software Foundation; either version 2,
   1.238 ++ * or (at your option) any later version.
   1.239 ++ *
   1.240 ++ * This program is distributed in the hope that it will be useful,
   1.241 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.242 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.243 ++ * GNU General Public License for more details.
   1.244 ++ *
   1.245 ++ * You should have received a copy of the GNU General Public License
   1.246 ++ * along with this program; if not, write to the Free Software
   1.247 ++ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   1.248 ++ *
   1.249 ++ * decompressor.h
   1.250 ++ */
   1.251 ++
   1.252 ++struct squashfs_decompressor {
   1.253 ++	void	*(*init)(struct squashfs_sb_info *);
   1.254 ++	void	(*free)(void *);
   1.255 ++	int	(*decompress)(struct squashfs_sb_info *, void **,
   1.256 ++		struct buffer_head **, int, int, int, int, int);
   1.257 ++	int	id;
   1.258 ++	char	*name;
   1.259 ++	int	supported;
   1.260 ++};
   1.261 ++
   1.262 ++static inline void *squashfs_decompressor_init(struct squashfs_sb_info *msblk)
   1.263 ++{
   1.264 ++	return msblk->decompressor->init(msblk);
   1.265 ++}
   1.266 ++
   1.267 ++static inline void squashfs_decompressor_free(struct squashfs_sb_info *msblk,
   1.268 ++	void *s)
   1.269 ++{
   1.270 ++	if (msblk->decompressor)
   1.271 ++		msblk->decompressor->free(s);
   1.272 ++}
   1.273 ++
   1.274 ++static inline int squashfs_decompress(struct squashfs_sb_info *msblk,
   1.275 ++	void **buffer, struct buffer_head **bh, int b, int offset, int length,
   1.276 ++	int srclength, int pages)
   1.277 ++{
   1.278 ++	return msblk->decompressor->decompress(msblk, buffer, bh, b, offset,
   1.279 ++		length, srclength, pages);
   1.280 ++}
   1.281 ++#endif
   1.282 +
   1.283 +--- linux-2.6.30.6/fs/squashfs/dir.c
   1.284 ++++ linux-2.6.30.6/fs/squashfs/dir.c
   1.285 +@@ -30,7 +30,6 @@
   1.286 + #include <linux/fs.h>
   1.287 + #include <linux/vfs.h>
   1.288 + #include <linux/slab.h>
   1.289 +-#include <linux/zlib.h>
   1.290 + 
   1.291 + #include "squashfs_fs.h"
   1.292 + #include "squashfs_fs_sb.h"
   1.293 +
   1.294 +--- linux-2.6.30.6/fs/squashfs/export.c
   1.295 ++++ linux-2.6.30.6/fs/squashfs/export.c
   1.296 +@@ -39,7 +39,6 @@
   1.297 + #include <linux/vfs.h>
   1.298 + #include <linux/dcache.h>
   1.299 + #include <linux/exportfs.h>
   1.300 +-#include <linux/zlib.h>
   1.301 + #include <linux/slab.h>
   1.302 + 
   1.303 + #include "squashfs_fs.h"
   1.304 +
   1.305 +--- linux-2.6.30.6/fs/squashfs/file.c
   1.306 ++++ linux-2.6.30.6/fs/squashfs/file.c
   1.307 +@@ -47,7 +47,6 @@
   1.308 + #include <linux/string.h>
   1.309 + #include <linux/pagemap.h>
   1.310 + #include <linux/mutex.h>
   1.311 +-#include <linux/zlib.h>
   1.312 + 
   1.313 + #include "squashfs_fs.h"
   1.314 + #include "squashfs_fs_sb.h"
   1.315 +
   1.316 +--- linux-2.6.30.6/fs/squashfs/fragment.c
   1.317 ++++ linux-2.6.30.6/fs/squashfs/fragment.c
   1.318 +@@ -36,7 +36,6 @@
   1.319 + #include <linux/fs.h>
   1.320 + #include <linux/vfs.h>
   1.321 + #include <linux/slab.h>
   1.322 +-#include <linux/zlib.h>
   1.323 + 
   1.324 + #include "squashfs_fs.h"
   1.325 + #include "squashfs_fs_sb.h"
   1.326 +
   1.327 +--- linux-2.6.30.6/fs/squashfs/id.c
   1.328 ++++ linux-2.6.30.6/fs/squashfs/id.c
   1.329 +@@ -34,7 +34,6 @@
   1.330 + #include <linux/fs.h>
   1.331 + #include <linux/vfs.h>
   1.332 + #include <linux/slab.h>
   1.333 +-#include <linux/zlib.h>
   1.334 + 
   1.335 + #include "squashfs_fs.h"
   1.336 + #include "squashfs_fs_sb.h"
   1.337 +
   1.338 +--- linux-2.6.30.6/fs/squashfs/inode.c
   1.339 ++++ linux-2.6.30.6/fs/squashfs/inode.c
   1.340 +@@ -40,7 +40,6 @@
   1.341 + 
   1.342 + #include <linux/fs.h>
   1.343 + #include <linux/vfs.h>
   1.344 +-#include <linux/zlib.h>
   1.345 + 
   1.346 + #include "squashfs_fs.h"
   1.347 + #include "squashfs_fs_sb.h"
   1.348 +
   1.349 +--- linux-2.6.30.6/fs/squashfs/lzma_wrapper.c
   1.350 ++++ linux-2.6.30.6/fs/squashfs/lzma_wrapper.c
   1.351 +@@ -0,0 +1,151 @@
   1.352 ++/*
   1.353 ++ * Squashfs - a compressed read only filesystem for Linux
   1.354 ++ *
   1.355 ++ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
   1.356 ++ * Phillip Lougher <phillip@lougher.demon.co.uk>
   1.357 ++ *
   1.358 ++ * This program is free software; you can redistribute it and/or
   1.359 ++ * modify it under the terms of the GNU General Public License
   1.360 ++ * as published by the Free Software Foundation; either version 2,
   1.361 ++ * or (at your option) any later version.
   1.362 ++ *
   1.363 ++ * This program is distributed in the hope that it will be useful,
   1.364 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.365 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.366 ++ * GNU General Public License for more details.
   1.367 ++ *
   1.368 ++ * You should have received a copy of the GNU General Public License
   1.369 ++ * along with this program; if not, write to the Free Software
   1.370 ++ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   1.371 ++ *
   1.372 ++ * lzma_wrapper.c
   1.373 ++ */
   1.374 ++
   1.375 ++#include <asm/unaligned.h>
   1.376 ++#include <linux/buffer_head.h>
   1.377 ++#include <linux/mutex.h>
   1.378 ++#include <linux/vmalloc.h>
   1.379 ++#include <linux/decompress/unlzma.h>
   1.380 ++
   1.381 ++#include "squashfs_fs.h"
   1.382 ++#include "squashfs_fs_sb.h"
   1.383 ++#include "squashfs_fs_i.h"
   1.384 ++#include "squashfs.h"
   1.385 ++#include "decompressor.h"
   1.386 ++
   1.387 ++struct squashfs_lzma {
   1.388 ++	void	*input;
   1.389 ++	void	*output;
   1.390 ++};
   1.391 ++
   1.392 ++/* decompress_unlzma.c is currently non re-entrant... */
   1.393 ++DEFINE_MUTEX(lzma_mutex);
   1.394 ++
   1.395 ++/* decompress_unlzma.c doesn't provide any context in its callbacks... */
   1.396 ++static int lzma_error;
   1.397 ++
   1.398 ++static void error(char *m)
   1.399 ++{
   1.400 ++	ERROR("unlzma error: %s\n", m);
   1.401 ++	lzma_error = 1;
   1.402 ++}
   1.403 ++
   1.404 ++
   1.405 ++static void *lzma_init(struct squashfs_sb_info *msblk)
   1.406 ++{
   1.407 ++	struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
   1.408 ++	if (stream == NULL)
   1.409 ++		goto failed;
   1.410 ++	stream->input = vmalloc(msblk->block_size);
   1.411 ++	if (stream->input == NULL)
   1.412 ++		goto failed;
   1.413 ++	stream->output = vmalloc(msblk->block_size);
   1.414 ++	if (stream->output == NULL)
   1.415 ++		goto failed2;
   1.416 ++
   1.417 ++	return stream;
   1.418 ++
   1.419 ++failed2:
   1.420 ++	vfree(stream->input);
   1.421 ++failed:
   1.422 ++	ERROR("failed to allocate lzma workspace\n");
   1.423 ++	kfree(stream);
   1.424 ++	return NULL;
   1.425 ++}
   1.426 ++
   1.427 ++
   1.428 ++static void lzma_free(void *strm)
   1.429 ++{
   1.430 ++	struct squashfs_lzma *stream = strm;
   1.431 ++
   1.432 ++	if (stream) {
   1.433 ++		vfree(stream->input);
   1.434 ++		vfree(stream->output);
   1.435 ++	}
   1.436 ++	kfree(stream);
   1.437 ++}
   1.438 ++
   1.439 ++
   1.440 ++static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,
   1.441 ++	struct buffer_head **bh, int b, int offset, int length, int srclength,
   1.442 ++	int pages)
   1.443 ++{
   1.444 ++	struct squashfs_lzma *stream = msblk->stream;
   1.445 ++	void *buff = stream->input;
   1.446 ++	int avail, i, bytes = length, res;
   1.447 ++
   1.448 ++	mutex_lock(&lzma_mutex);
   1.449 ++
   1.450 ++	for (i = 0; i < b; i++) {
   1.451 ++		wait_on_buffer(bh[i]);
   1.452 ++		if (!buffer_uptodate(bh[i]))
   1.453 ++			goto block_release;
   1.454 ++
   1.455 ++		avail = min(bytes, msblk->devblksize - offset);
   1.456 ++		memcpy(buff, bh[i]->b_data + offset, avail);
   1.457 ++		buff += avail;
   1.458 ++		bytes -= avail;
   1.459 ++		offset = 0;
   1.460 ++		put_bh(bh[i]);
   1.461 ++	}
   1.462 ++
   1.463 ++	lzma_error = 0;
   1.464 ++	res = unlzma(stream->input, length, NULL, NULL, stream->output, NULL,
   1.465 ++							error);
   1.466 ++	if (res || lzma_error)
   1.467 ++		goto failed;
   1.468 ++
   1.469 ++	/* uncompressed size is stored in the LZMA header (5 byte offset) */
   1.470 ++	res = bytes = get_unaligned_le32(stream->input + 5);
   1.471 ++	for (i = 0, buff = stream->output; bytes && i < pages; i++) {
   1.472 ++		avail = min_t(int, bytes, PAGE_CACHE_SIZE);
   1.473 ++		memcpy(buffer[i], buff, avail);
   1.474 ++		buff += avail;
   1.475 ++		bytes -= avail;
   1.476 ++	}
   1.477 ++	if (bytes)
   1.478 ++		goto failed;
   1.479 ++
   1.480 ++	mutex_unlock(&lzma_mutex);
   1.481 ++	return res;
   1.482 ++
   1.483 ++block_release:
   1.484 ++	for (; i < b; i++)
   1.485 ++		put_bh(bh[i]);
   1.486 ++
   1.487 ++failed:
   1.488 ++	mutex_unlock(&lzma_mutex);
   1.489 ++
   1.490 ++	ERROR("lzma decompression failed, data probably corrupt\n");
   1.491 ++	return -EIO;
   1.492 ++}
   1.493 ++
   1.494 ++const struct squashfs_decompressor squashfs_lzma_comp_ops = {
   1.495 ++	.init = lzma_init,
   1.496 ++	.free = lzma_free,
   1.497 ++	.decompress = lzma_uncompress,
   1.498 ++	.id = LZMA_COMPRESSION,
   1.499 ++	.name = "lzma",
   1.500 ++	.supported = 1
   1.501 ++};
   1.502 ++
   1.503 +
   1.504 +--- linux-2.6.30.6/fs/squashfs/namei.c
   1.505 ++++ linux-2.6.30.6/fs/squashfs/namei.c
   1.506 +@@ -57,7 +57,6 @@
   1.507 + #include <linux/slab.h>
   1.508 + #include <linux/string.h>
   1.509 + #include <linux/dcache.h>
   1.510 +-#include <linux/zlib.h>
   1.511 + 
   1.512 + #include "squashfs_fs.h"
   1.513 + #include "squashfs_fs_sb.h"
   1.514 +
   1.515 +--- linux-2.6.30.6/fs/squashfs/squashfs.h
   1.516 ++++ linux-2.6.30.6/fs/squashfs/squashfs.h
   1.517 +@@ -51,6 +51,9 @@
   1.518 + 				u64, int);
   1.519 + extern int squashfs_read_table(struct super_block *, void *, u64, int);
   1.520 + 
   1.521 ++/* decompressor.c */
   1.522 ++extern const struct squashfs_decompressor *squashfs_lookup_decompressor(int);
   1.523 ++
   1.524 + /* export.c */
   1.525 + extern __le64 *squashfs_read_inode_lookup_table(struct super_block *, u64,
   1.526 + 				unsigned int);
   1.527 +@@ -71,7 +74,7 @@
   1.528 + extern int squashfs_read_inode(struct inode *, long long);
   1.529 + 
   1.530 + /*
   1.531 +- * Inodes and files operations
   1.532 ++ * Inodes, files and decompressor operations
   1.533 +  */
   1.534 + 
   1.535 + /* dir.c */
   1.536 +@@ -88,3 +91,9 @@
   1.537 + 
   1.538 + /* symlink.c */
   1.539 + extern const struct address_space_operations squashfs_symlink_aops;
   1.540 ++
   1.541 ++/* zlib_wrapper.c */
   1.542 ++extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
   1.543 ++
   1.544 ++/* lzma wrapper.c */
   1.545 ++extern const struct squashfs_decompressor squashfs_lzma_comp_ops;
   1.546 +
   1.547 +--- linux-2.6.30.6/fs/squashfs/squashfs_fs.h
   1.548 ++++ linux-2.6.30.6/fs/squashfs/squashfs_fs.h
   1.549 +@@ -211,7 +211,9 @@
   1.550 + /*
   1.551 +  * definitions for structures on disk
   1.552 +  */
   1.553 +-#define ZLIB_COMPRESSION	 1
   1.554 ++#define ZLIB_COMPRESSION	1
   1.555 ++#define LZMA_COMPRESSION	2
   1.556 ++#define LZO_COMPRESSION		3
   1.557 + 
   1.558 + struct squashfs_super_block {
   1.559 + 	__le32			s_magic;
   1.560 +
   1.561 +--- linux-2.6.30.6/fs/squashfs/squashfs_fs_sb.h
   1.562 ++++ linux-2.6.30.6/fs/squashfs/squashfs_fs_sb.h
   1.563 +@@ -52,25 +52,26 @@
   1.564 + };
   1.565 + 
   1.566 + struct squashfs_sb_info {
   1.567 +-	int			devblksize;
   1.568 +-	int			devblksize_log2;
   1.569 +-	struct squashfs_cache	*block_cache;
   1.570 +-	struct squashfs_cache	*fragment_cache;
   1.571 +-	struct squashfs_cache	*read_page;
   1.572 +-	int			next_meta_index;
   1.573 +-	__le64			*id_table;
   1.574 +-	__le64			*fragment_index;
   1.575 +-	unsigned int		*fragment_index_2;
   1.576 +-	struct mutex		read_data_mutex;
   1.577 +-	struct mutex		meta_index_mutex;
   1.578 +-	struct meta_index	*meta_index;
   1.579 +-	z_stream		stream;
   1.580 +-	__le64			*inode_lookup_table;
   1.581 +-	u64			inode_table;
   1.582 +-	u64			directory_table;
   1.583 +-	unsigned int		block_size;
   1.584 +-	unsigned short		block_log;
   1.585 +-	long long		bytes_used;
   1.586 +-	unsigned int		inodes;
   1.587 ++	const struct squashfs_decompressor	*decompressor;
   1.588 ++	int					devblksize;
   1.589 ++	int					devblksize_log2;
   1.590 ++	struct squashfs_cache			*block_cache;
   1.591 ++	struct squashfs_cache			*fragment_cache;
   1.592 ++	struct squashfs_cache			*read_page;
   1.593 ++	int					next_meta_index;
   1.594 ++	__le64					*id_table;
   1.595 ++	__le64					*fragment_index;
   1.596 ++	unsigned int				*fragment_index_2;
   1.597 ++	struct mutex				read_data_mutex;
   1.598 ++	struct mutex				meta_index_mutex;
   1.599 ++	struct meta_index			*meta_index;
   1.600 ++	void					*stream;
   1.601 ++	__le64					*inode_lookup_table;
   1.602 ++	u64					inode_table;
   1.603 ++	u64					directory_table;
   1.604 ++	unsigned int				block_size;
   1.605 ++	unsigned short				block_log;
   1.606 ++	long long				bytes_used;
   1.607 ++	unsigned int				inodes;
   1.608 + };
   1.609 + #endif
   1.610 +
   1.611 +--- linux-2.6.30.6/fs/squashfs/super.c
   1.612 ++++ linux-2.6.30.6/fs/squashfs/super.c
   1.613 +@@ -30,38 +30,46 @@
   1.614 + #include <linux/fs.h>
   1.615 + #include <linux/vfs.h>
   1.616 + #include <linux/slab.h>
   1.617 ++#include <linux/smp_lock.h>
   1.618 + #include <linux/mutex.h>
   1.619 + #include <linux/pagemap.h>
   1.620 + #include <linux/init.h>
   1.621 + #include <linux/module.h>
   1.622 +-#include <linux/zlib.h>
   1.623 + #include <linux/magic.h>
   1.624 + 
   1.625 + #include "squashfs_fs.h"
   1.626 + #include "squashfs_fs_sb.h"
   1.627 + #include "squashfs_fs_i.h"
   1.628 + #include "squashfs.h"
   1.629 ++#include "decompressor.h"
   1.630 + 
   1.631 + static struct file_system_type squashfs_fs_type;
   1.632 +-static struct super_operations squashfs_super_ops;
   1.633 ++static const struct super_operations squashfs_super_ops;
   1.634 + 
   1.635 +-static int supported_squashfs_filesystem(short major, short minor, short comp)
   1.636 ++static const struct squashfs_decompressor *supported_squashfs_filesystem(short
   1.637 ++	major, short minor, short id)
   1.638 + {
   1.639 ++	const struct squashfs_decompressor *decompressor;
   1.640 ++
   1.641 + 	if (major < SQUASHFS_MAJOR) {
   1.642 + 		ERROR("Major/Minor mismatch, older Squashfs %d.%d "
   1.643 + 			"filesystems are unsupported\n", major, minor);
   1.644 +-		return -EINVAL;
   1.645 ++		return NULL;
   1.646 + 	} else if (major > SQUASHFS_MAJOR || minor > SQUASHFS_MINOR) {
   1.647 + 		ERROR("Major/Minor mismatch, trying to mount newer "
   1.648 + 			"%d.%d filesystem\n", major, minor);
   1.649 + 		ERROR("Please update your kernel\n");
   1.650 +-		return -EINVAL;
   1.651 ++		return NULL;
   1.652 + 	}
   1.653 + 
   1.654 +-	if (comp != ZLIB_COMPRESSION)
   1.655 +-		return -EINVAL;
   1.656 ++	decompressor = squashfs_lookup_decompressor(id);
   1.657 ++	if (!decompressor->supported) {
   1.658 ++		ERROR("Filesystem uses \"%s\" compression. This is not "
   1.659 ++			"supported\n", decompressor->name);
   1.660 ++		return NULL;
   1.661 ++	}
   1.662 + 
   1.663 +-	return 0;
   1.664 ++	return decompressor;
   1.665 + }
   1.666 + 
   1.667 + 
   1.668 +@@ -86,13 +94,6 @@
   1.669 + 	}
   1.670 + 	msblk = sb->s_fs_info;
   1.671 + 
   1.672 +-	msblk->stream.workspace = kmalloc(zlib_inflate_workspacesize(),
   1.673 +-		GFP_KERNEL);
   1.674 +-	if (msblk->stream.workspace == NULL) {
   1.675 +-		ERROR("Failed to allocate zlib workspace\n");
   1.676 +-		goto failure;
   1.677 +-	}
   1.678 +-
   1.679 + 	sblk = kzalloc(sizeof(*sblk), GFP_KERNEL);
   1.680 + 	if (sblk == NULL) {
   1.681 + 		ERROR("Failed to allocate squashfs_super_block\n");
   1.682 +@@ -119,25 +120,25 @@
   1.683 + 		goto failed_mount;
   1.684 + 	}
   1.685 + 
   1.686 ++	err = -EINVAL;
   1.687 ++
   1.688 + 	/* Check it is a SQUASHFS superblock */
   1.689 + 	sb->s_magic = le32_to_cpu(sblk->s_magic);
   1.690 + 	if (sb->s_magic != SQUASHFS_MAGIC) {
   1.691 + 		if (!silent)
   1.692 + 			ERROR("Can't find a SQUASHFS superblock on %s\n",
   1.693 + 						bdevname(sb->s_bdev, b));
   1.694 +-		err = -EINVAL;
   1.695 + 		goto failed_mount;
   1.696 + 	}
   1.697 + 
   1.698 +-	/* Check the MAJOR & MINOR versions and compression type */
   1.699 +-	err = supported_squashfs_filesystem(le16_to_cpu(sblk->s_major),
   1.700 ++	/* Check the MAJOR & MINOR versions and lookup compression type */
   1.701 ++	msblk->decompressor = supported_squashfs_filesystem(
   1.702 ++			le16_to_cpu(sblk->s_major),
   1.703 + 			le16_to_cpu(sblk->s_minor),
   1.704 + 			le16_to_cpu(sblk->compression));
   1.705 +-	if (err < 0)
   1.706 ++	if (msblk->decompressor == NULL)
   1.707 + 		goto failed_mount;
   1.708 + 
   1.709 +-	err = -EINVAL;
   1.710 +-
   1.711 + 	/*
   1.712 + 	 * Check if there's xattrs in the filesystem.  These are not
   1.713 + 	 * supported in this version, so warn that they will be ignored.
   1.714 +@@ -204,6 +205,10 @@
   1.715 + 
   1.716 + 	err = -ENOMEM;
   1.717 + 
   1.718 ++	msblk->stream = squashfs_decompressor_init(msblk);
   1.719 ++	if (msblk->stream == NULL)
   1.720 ++		goto failed_mount;
   1.721 ++
   1.722 + 	msblk->block_cache = squashfs_cache_init("metadata",
   1.723 + 			SQUASHFS_CACHED_BLKS, SQUASHFS_METADATA_SIZE);
   1.724 + 	if (msblk->block_cache == NULL)
   1.725 +@@ -291,17 +296,16 @@
   1.726 + 	squashfs_cache_delete(msblk->block_cache);
   1.727 + 	squashfs_cache_delete(msblk->fragment_cache);
   1.728 + 	squashfs_cache_delete(msblk->read_page);
   1.729 ++	squashfs_decompressor_free(msblk, msblk->stream);
   1.730 + 	kfree(msblk->inode_lookup_table);
   1.731 + 	kfree(msblk->fragment_index);
   1.732 + 	kfree(msblk->id_table);
   1.733 +-	kfree(msblk->stream.workspace);
   1.734 + 	kfree(sb->s_fs_info);
   1.735 + 	sb->s_fs_info = NULL;
   1.736 + 	kfree(sblk);
   1.737 + 	return err;
   1.738 + 
   1.739 + failure:
   1.740 +-	kfree(msblk->stream.workspace);
   1.741 + 	kfree(sb->s_fs_info);
   1.742 + 	sb->s_fs_info = NULL;
   1.743 + 	return -ENOMEM;
   1.744 +@@ -338,18 +342,22 @@
   1.745 + 
   1.746 + static void squashfs_put_super(struct super_block *sb)
   1.747 + {
   1.748 ++	lock_kernel();
   1.749 ++
   1.750 + 	if (sb->s_fs_info) {
   1.751 + 		struct squashfs_sb_info *sbi = sb->s_fs_info;
   1.752 + 		squashfs_cache_delete(sbi->block_cache);
   1.753 + 		squashfs_cache_delete(sbi->fragment_cache);
   1.754 + 		squashfs_cache_delete(sbi->read_page);
   1.755 ++		squashfs_decompressor_free(sbi, sbi->stream);
   1.756 + 		kfree(sbi->id_table);
   1.757 + 		kfree(sbi->fragment_index);
   1.758 + 		kfree(sbi->meta_index);
   1.759 +-		kfree(sbi->stream.workspace);
   1.760 + 		kfree(sb->s_fs_info);
   1.761 + 		sb->s_fs_info = NULL;
   1.762 + 	}
   1.763 ++
   1.764 ++	unlock_kernel();
   1.765 + }
   1.766 + 
   1.767 + 
   1.768 +@@ -439,7 +447,7 @@
   1.769 + 	.fs_flags = FS_REQUIRES_DEV
   1.770 + };
   1.771 + 
   1.772 +-static struct super_operations squashfs_super_ops = {
   1.773 ++static const struct super_operations squashfs_super_ops = {
   1.774 + 	.alloc_inode = squashfs_alloc_inode,
   1.775 + 	.destroy_inode = squashfs_destroy_inode,
   1.776 + 	.statfs = squashfs_statfs,
   1.777 +
   1.778 +--- linux-2.6.30.6/fs/squashfs/symlink.c
   1.779 ++++ linux-2.6.30.6/fs/squashfs/symlink.c
   1.780 +@@ -36,7 +36,6 @@
   1.781 + #include <linux/slab.h>
   1.782 + #include <linux/string.h>
   1.783 + #include <linux/pagemap.h>
   1.784 +-#include <linux/zlib.h>
   1.785 + 
   1.786 + #include "squashfs_fs.h"
   1.787 + #include "squashfs_fs_sb.h"
   1.788 +
   1.789 +--- linux-2.6.30.6/fs/squashfs/zlib_wrapper.c
   1.790 ++++ linux-2.6.30.6/fs/squashfs/zlib_wrapper.c
   1.791 +@@ -0,0 +1,150 @@
   1.792 ++/*
   1.793 ++ * Squashfs - a compressed read only filesystem for Linux
   1.794 ++ *
   1.795 ++ * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
   1.796 ++ * Phillip Lougher <phillip@lougher.demon.co.uk>
   1.797 ++ *
   1.798 ++ * This program is free software; you can redistribute it and/or
   1.799 ++ * modify it under the terms of the GNU General Public License
   1.800 ++ * as published by the Free Software Foundation; either version 2,
   1.801 ++ * or (at your option) any later version.
   1.802 ++ *
   1.803 ++ * This program is distributed in the hope that it will be useful,
   1.804 ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of
   1.805 ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   1.806 ++ * GNU General Public License for more details.
   1.807 ++ *
   1.808 ++ * You should have received a copy of the GNU General Public License
   1.809 ++ * along with this program; if not, write to the Free Software
   1.810 ++ * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
   1.811 ++ *
   1.812 ++ * zlib_wrapper.c
   1.813 ++ */
   1.814 ++
   1.815 ++
   1.816 ++#include <linux/mutex.h>
   1.817 ++#include <linux/buffer_head.h>
   1.818 ++#include <linux/zlib.h>
   1.819 ++
   1.820 ++#include "squashfs_fs.h"
   1.821 ++#include "squashfs_fs_sb.h"
   1.822 ++#include "squashfs_fs_i.h"
   1.823 ++#include "squashfs.h"
   1.824 ++#include "decompressor.h"
   1.825 ++
   1.826 ++static void *zlib_init(struct squashfs_sb_info *dummy)
   1.827 ++{
   1.828 ++	z_stream *stream = kmalloc(sizeof(z_stream), GFP_KERNEL);
   1.829 ++	if (stream == NULL)
   1.830 ++		goto failed;
   1.831 ++	stream->workspace = kmalloc(zlib_inflate_workspacesize(),
   1.832 ++		GFP_KERNEL);
   1.833 ++	if (stream->workspace == NULL)
   1.834 ++		goto failed;
   1.835 ++
   1.836 ++	return stream;
   1.837 ++
   1.838 ++failed:
   1.839 ++	ERROR("Failed to allocate zlib workspace\n");
   1.840 ++	kfree(stream);
   1.841 ++	return NULL;
   1.842 ++}
   1.843 ++
   1.844 ++
   1.845 ++static void zlib_free(void *strm)
   1.846 ++{
   1.847 ++	z_stream *stream = strm;
   1.848 ++
   1.849 ++	if (stream)
   1.850 ++		kfree(stream->workspace);
   1.851 ++	kfree(stream);
   1.852 ++}
   1.853 ++
   1.854 ++
   1.855 ++static int zlib_uncompress(struct squashfs_sb_info *msblk, void **buffer,
   1.856 ++	struct buffer_head **bh, int b, int offset, int length, int srclength,
   1.857 ++	int pages)
   1.858 ++{
   1.859 ++	int zlib_err = 0, zlib_init = 0;
   1.860 ++	int avail, bytes, k = 0, page = 0;
   1.861 ++	z_stream *stream = msblk->stream;
   1.862 ++
   1.863 ++	mutex_lock(&msblk->read_data_mutex);
   1.864 ++
   1.865 ++	stream->avail_out = 0;
   1.866 ++	stream->avail_in = 0;
   1.867 ++
   1.868 ++	bytes = length;
   1.869 ++	do {
   1.870 ++		if (stream->avail_in == 0 && k < b) {
   1.871 ++			avail = min(bytes, msblk->devblksize - offset);
   1.872 ++			bytes -= avail;
   1.873 ++			wait_on_buffer(bh[k]);
   1.874 ++			if (!buffer_uptodate(bh[k]))
   1.875 ++				goto release_mutex;
   1.876 ++
   1.877 ++			if (avail == 0) {
   1.878 ++				offset = 0;
   1.879 ++				put_bh(bh[k++]);
   1.880 ++				continue;
   1.881 ++			}
   1.882 ++
   1.883 ++			stream->next_in = bh[k]->b_data + offset;
   1.884 ++			stream->avail_in = avail;
   1.885 ++			offset = 0;
   1.886 ++		}
   1.887 ++
   1.888 ++		if (stream->avail_out == 0 && page < pages) {
   1.889 ++			stream->next_out = buffer[page++];
   1.890 ++			stream->avail_out = PAGE_CACHE_SIZE;
   1.891 ++		}
   1.892 ++
   1.893 ++		if (!zlib_init) {
   1.894 ++			zlib_err = zlib_inflateInit(stream);
   1.895 ++			if (zlib_err != Z_OK) {
   1.896 ++				ERROR("zlib_inflateInit returned unexpected "
   1.897 ++					"result 0x%x, srclength %d\n",
   1.898 ++					zlib_err, srclength);
   1.899 ++				goto release_mutex;
   1.900 ++			}
   1.901 ++			zlib_init = 1;
   1.902 ++		}
   1.903 ++
   1.904 ++		zlib_err = zlib_inflate(stream, Z_SYNC_FLUSH);
   1.905 ++
   1.906 ++		if (stream->avail_in == 0 && k < b)
   1.907 ++			put_bh(bh[k++]);
   1.908 ++	} while (zlib_err == Z_OK);
   1.909 ++
   1.910 ++	if (zlib_err != Z_STREAM_END) {
   1.911 ++		ERROR("zlib_inflate error, data probably corrupt\n");
   1.912 ++		goto release_mutex;
   1.913 ++	}
   1.914 ++
   1.915 ++	zlib_err = zlib_inflateEnd(stream);
   1.916 ++	if (zlib_err != Z_OK) {
   1.917 ++		ERROR("zlib_inflate error, data probably corrupt\n");
   1.918 ++		goto release_mutex;
   1.919 ++	}
   1.920 ++
   1.921 ++	mutex_unlock(&msblk->read_data_mutex);
   1.922 ++	return stream->total_out;
   1.923 ++
   1.924 ++release_mutex:
   1.925 ++	mutex_unlock(&msblk->read_data_mutex);
   1.926 ++
   1.927 ++	for (; k < b; k++)
   1.928 ++		put_bh(bh[k]);
   1.929 ++
   1.930 ++	return -EIO;
   1.931 ++}
   1.932 ++
   1.933 ++const struct squashfs_decompressor squashfs_zlib_comp_ops = {
   1.934 ++	.init = zlib_init,
   1.935 ++	.free = zlib_free,
   1.936 ++	.decompress = zlib_uncompress,
   1.937 ++	.id = ZLIB_COMPRESSION,
   1.938 ++	.name = "zlib",
   1.939 ++	.supported = 1
   1.940 ++};
   1.941 ++
   1.942 +
   1.943 +--- linux-2.6.30.6/include/linux/decompress/bunzip2_mm.h
   1.944 ++++ linux-2.6.30.6/include/linux/decompress/bunzip2_mm.h
   1.945 +@@ -0,0 +1,13 @@
   1.946 ++#ifndef BUNZIP2_MM_H
   1.947 ++#define BUNZIP2_MM_H
   1.948 ++
   1.949 ++#ifdef STATIC
   1.950 ++/* Code active when included from pre-boot environment: */
   1.951 ++#define INIT
   1.952 ++#else
   1.953 ++/* Compile for initramfs/initrd code only */
   1.954 ++#define INIT __init
   1.955 ++static void(*error)(char *m);
   1.956 ++#endif
   1.957 ++
   1.958 ++#endif
   1.959 +
   1.960 +--- linux-2.6.30.6/include/linux/decompress/inflate_mm.h
   1.961 ++++ linux-2.6.30.6/include/linux/decompress/inflate_mm.h
   1.962 +@@ -0,0 +1,13 @@
   1.963 ++#ifndef INFLATE_MM_H
   1.964 ++#define INFLATE_MM_H
   1.965 ++
   1.966 ++#ifdef STATIC
   1.967 ++/* Code active when included from pre-boot environment: */
   1.968 ++#define INIT
   1.969 ++#else
   1.970 ++/* Compile for initramfs/initrd code only */
   1.971 ++#define INIT __init
   1.972 ++static void(*error)(char *m);
   1.973 ++#endif
   1.974 ++
   1.975 ++#endif
   1.976 +
   1.977 +--- linux-2.6.30.6/include/linux/decompress/mm.h
   1.978 ++++ linux-2.6.30.6/include/linux/decompress/mm.h
   1.979 +@@ -25,7 +25,7 @@
   1.980 + 	void *p;
   1.981 + 
   1.982 + 	if (size < 0)
   1.983 +-		error("Malloc error");
   1.984 ++		return NULL;
   1.985 + 	if (!malloc_ptr)
   1.986 + 		malloc_ptr = free_mem_ptr;
   1.987 + 
   1.988 +@@ -35,7 +35,7 @@
   1.989 + 	malloc_ptr += size;
   1.990 + 
   1.991 + 	if (free_mem_end_ptr && malloc_ptr >= free_mem_end_ptr)
   1.992 +-		error("Out of memory");
   1.993 ++		return NULL;
   1.994 + 
   1.995 + 	malloc_count++;
   1.996 + 	return p;
   1.997 +@@ -53,8 +53,6 @@
   1.998 + 
   1.999 + #define set_error_fn(x)
  1.1000 + 
  1.1001 +-#define INIT
  1.1002 +-
  1.1003 + #else /* STATIC */
  1.1004 + 
  1.1005 + /* Code active when compiled standalone for use when loading ramdisk: */
  1.1006 +@@ -74,10 +72,8 @@
  1.1007 + #define large_malloc(a) vmalloc(a)
  1.1008 + #define large_free(a) vfree(a)
  1.1009 + 
  1.1010 +-static void(*error)(char *m);
  1.1011 + #define set_error_fn(x) error = x;
  1.1012 + 
  1.1013 +-#define INIT __init
  1.1014 + #define STATIC
  1.1015 + 
  1.1016 + #include <linux/init.h>
  1.1017 +
  1.1018 +--- linux-2.6.30.6/include/linux/decompress/unlzma_mm.h
  1.1019 ++++ linux-2.6.30.6/include/linux/decompress/unlzma_mm.h
  1.1020 +@@ -0,0 +1,20 @@
  1.1021 ++#ifndef UNLZMA_MM_H
  1.1022 ++#define UNLZMA_MM_H
  1.1023 ++
  1.1024 ++#ifdef STATIC
  1.1025 ++
  1.1026 ++/* Code active when included from pre-boot environment: */
  1.1027 ++#define INIT
  1.1028 ++
  1.1029 ++#elif defined(CONFIG_DECOMPRESS_LZMA_NEEDED)
  1.1030 ++
  1.1031 ++/* Make it available to non initramfs/initrd code */
  1.1032 ++#define INIT
  1.1033 ++#include <linux/module.h>
  1.1034 ++#else
  1.1035 ++
  1.1036 ++/* Compile for initramfs/initrd code only */
  1.1037 ++#define INIT __init
  1.1038 ++#endif
  1.1039 ++
  1.1040 ++#endif
  1.1041 +
  1.1042 +--- linux-2.6.30.6/lib/Kconfig
  1.1043 ++++ linux-2.6.30.6/lib/Kconfig
  1.1044 +@@ -10,6 +10,9 @@
  1.1045 + config BITREVERSE
  1.1046 + 	tristate
  1.1047 + 
  1.1048 ++config RATIONAL
  1.1049 ++	boolean
  1.1050 ++
  1.1051 + config GENERIC_FIND_FIRST_BIT
  1.1052 + 	bool
  1.1053 + 
  1.1054 +@@ -114,6 +117,9 @@
  1.1055 + config DECOMPRESS_LZMA
  1.1056 + 	tristate
  1.1057 + 
  1.1058 ++config DECOMPRESS_LZMA_NEEDED
  1.1059 ++	 boolean
  1.1060 ++
  1.1061 + #
  1.1062 + # Generic allocator support is selected if needed
  1.1063 + #
  1.1064 +@@ -153,6 +159,9 @@
  1.1065 + config TEXTSEARCH_FSM
  1.1066 + 	tristate
  1.1067 + 
  1.1068 ++config BTREE
  1.1069 ++	boolean
  1.1070 ++
  1.1071 + config HAS_IOMEM
  1.1072 + 	boolean
  1.1073 + 	depends on !NO_IOMEM
  1.1074 +@@ -190,5 +199,35 @@
  1.1075 + #
  1.1076 + config NLATTR
  1.1077 + 	bool
  1.1078 ++
  1.1079 ++#
  1.1080 ++# Generic 64-bit atomic support is selected if needed
  1.1081 ++#
  1.1082 ++config GENERIC_ATOMIC64
  1.1083 ++       bool
  1.1084 ++
  1.1085 ++config LRU_CACHE
  1.1086 ++	tristate
  1.1087 ++
  1.1088 ++config SHM_SIGNAL
  1.1089 ++	tristate "SHM Signal - Generic shared-memory signaling mechanism"
  1.1090 ++	default n
  1.1091 ++	help
  1.1092 ++	 Provides a shared-memory based signaling mechanism to indicate
  1.1093 ++         memory-dirty notifications between two end-points.
  1.1094 ++
  1.1095 ++	 If unsure, say N
  1.1096 ++
  1.1097 ++config IOQ
  1.1098 ++	tristate "IO-Queue library - Generic shared-memory queue"
  1.1099 ++	select SHM_SIGNAL
  1.1100 ++	default n
  1.1101 ++	help
  1.1102 ++	 IOQ is a generic shared-memory-queue mechanism that happens to be
  1.1103 ++	 friendly to virtualization boundaries. It can be used in a variety
  1.1104 ++	 of ways, though its intended purpose is to become a low-level
  1.1105 ++	 communication path for paravirtualized drivers.
  1.1106 ++
  1.1107 ++	 If unsure, say N
  1.1108 + 
  1.1109 + endmenu
  1.1110 +
  1.1111 +--- linux-2.6.30.6/lib/decompress_bunzip2.c
  1.1112 ++++ linux-2.6.30.6/lib/decompress_bunzip2.c
  1.1113 +@@ -45,12 +45,15 @@
  1.1114 + */
  1.1115 + 
  1.1116 + 
  1.1117 +-#ifndef STATIC
  1.1118 ++#ifdef STATIC
  1.1119 ++#define PREBOOT
  1.1120 ++#else
  1.1121 + #include <linux/decompress/bunzip2.h>
  1.1122 +-#endif /* !STATIC */
  1.1123 ++#include <linux/slab.h>
  1.1124 ++#endif /* STATIC */
  1.1125 + 
  1.1126 ++#include <linux/decompress/bunzip2_mm.h>
  1.1127 + #include <linux/decompress/mm.h>
  1.1128 +-#include <linux/slab.h>
  1.1129 + 
  1.1130 + #ifndef INT_MAX
  1.1131 + #define INT_MAX 0x7fffffff
  1.1132 +@@ -297,7 +300,7 @@
  1.1133 + 		   again when using them (during symbol decoding).*/
  1.1134 + 		base = hufGroup->base-1;
  1.1135 + 		limit = hufGroup->limit-1;
  1.1136 +-		/* Calculate permute[].  Concurently, initialize
  1.1137 ++		/* Calculate permute[].  Concurrently, initialize
  1.1138 + 		 * temp[] and limit[]. */
  1.1139 + 		pp = 0;
  1.1140 + 		for (i = minLen; i <= maxLen; i++) {
  1.1141 +@@ -635,6 +638,8 @@
  1.1142 + 
  1.1143 + 	/* Allocate bunzip_data.  Most fields initialize to zero. */
  1.1144 + 	bd = *bdp = malloc(i);
  1.1145 ++	if (!bd)
  1.1146 ++		return RETVAL_OUT_OF_MEMORY;
  1.1147 + 	memset(bd, 0, sizeof(struct bunzip_data));
  1.1148 + 	/* Setup input buffer */
  1.1149 + 	bd->inbuf = inbuf;
  1.1150 +@@ -662,6 +667,8 @@
  1.1151 + 	bd->dbufSize = 100000*(i-BZh0);
  1.1152 + 
  1.1153 + 	bd->dbuf = large_malloc(bd->dbufSize * sizeof(int));
  1.1154 ++	if (!bd->dbuf)
  1.1155 ++		return RETVAL_OUT_OF_MEMORY;
  1.1156 + 	return RETVAL_OK;
  1.1157 + }
  1.1158 + 
  1.1159 +@@ -681,12 +688,10 @@
  1.1160 + 	set_error_fn(error_fn);
  1.1161 + 	if (flush)
  1.1162 + 		outbuf = malloc(BZIP2_IOBUF_SIZE);
  1.1163 +-	else
  1.1164 +-		len -= 4; /* Uncompressed size hack active in pre-boot
  1.1165 +-			     environment */
  1.1166 ++
  1.1167 + 	if (!outbuf) {
  1.1168 + 		error("Could not allocate output bufer");
  1.1169 +-		return -1;
  1.1170 ++		return RETVAL_OUT_OF_MEMORY;
  1.1171 + 	}
  1.1172 + 	if (buf)
  1.1173 + 		inbuf = buf;
  1.1174 +@@ -694,6 +699,7 @@
  1.1175 + 		inbuf = malloc(BZIP2_IOBUF_SIZE);
  1.1176 + 	if (!inbuf) {
  1.1177 + 		error("Could not allocate input bufer");
  1.1178 ++		i = RETVAL_OUT_OF_MEMORY;
  1.1179 + 		goto exit_0;
  1.1180 + 	}
  1.1181 + 	i = start_bunzip(&bd, inbuf, len, fill);
  1.1182 +@@ -720,11 +726,14 @@
  1.1183 + 	} else if (i == RETVAL_UNEXPECTED_OUTPUT_EOF) {
  1.1184 + 		error("Compressed file ends unexpectedly");
  1.1185 + 	}
  1.1186 ++	if (!bd)
  1.1187 ++		goto exit_1;
  1.1188 + 	if (bd->dbuf)
  1.1189 + 		large_free(bd->dbuf);
  1.1190 + 	if (pos)
  1.1191 + 		*pos = bd->inbufPos;
  1.1192 + 	free(bd);
  1.1193 ++exit_1:
  1.1194 + 	if (!buf)
  1.1195 + 		free(inbuf);
  1.1196 + exit_0:
  1.1197 +@@ -733,4 +742,14 @@
  1.1198 + 	return i;
  1.1199 + }
  1.1200 + 
  1.1201 +-#define decompress bunzip2
  1.1202 ++#ifdef PREBOOT
  1.1203 ++STATIC int INIT decompress(unsigned char *buf, int len,
  1.1204 ++			int(*fill)(void*, unsigned int),
  1.1205 ++			int(*flush)(void*, unsigned int),
  1.1206 ++			unsigned char *outbuf,
  1.1207 ++			int *pos,
  1.1208 ++			void(*error_fn)(char *x))
  1.1209 ++{
  1.1210 ++	return bunzip2(buf, len - 4, fill, flush, outbuf, pos, error_fn);
  1.1211 ++}
  1.1212 ++#endif
  1.1213 +
  1.1214 +--- linux-2.6.30.6/lib/decompress_inflate.c
  1.1215 ++++ linux-2.6.30.6/lib/decompress_inflate.c
  1.1216 +@@ -19,14 +19,20 @@
  1.1217 + #include "zlib_inflate/inflate.h"
  1.1218 + 
  1.1219 + #include "zlib_inflate/infutil.h"
  1.1220 ++#include <linux/slab.h>
  1.1221 + 
  1.1222 + #endif /* STATIC */
  1.1223 + 
  1.1224 ++#include <linux/decompress/inflate_mm.h>
  1.1225 + #include <linux/decompress/mm.h>
  1.1226 +-#include <linux/slab.h>
  1.1227 + 
  1.1228 +-#define INBUF_LEN (16*1024)
  1.1229 ++#define GZIP_IOBUF_SIZE (16*1024)
  1.1230 + 
  1.1231 ++static int nofill(void *buffer, unsigned int len)
  1.1232 ++{
  1.1233 ++	return -1;
  1.1234 ++}
  1.1235 ++
  1.1236 + /* Included from initramfs et al code */
  1.1237 + STATIC int INIT gunzip(unsigned char *buf, int len,
  1.1238 + 		       int(*fill)(void*, unsigned int),
  1.1239 +@@ -55,7 +61,7 @@
  1.1240 + 	if (buf)
  1.1241 + 		zbuf = buf;
  1.1242 + 	else {
  1.1243 +-		zbuf = malloc(INBUF_LEN);
  1.1244 ++		zbuf = malloc(GZIP_IOBUF_SIZE);
  1.1245 + 		len = 0;
  1.1246 + 	}
  1.1247 + 	if (!zbuf) {
  1.1248 +@@ -76,8 +82,11 @@
  1.1249 + 		goto gunzip_nomem4;
  1.1250 + 	}
  1.1251 + 
  1.1252 ++	if (!fill)
  1.1253 ++		fill = nofill;
  1.1254 ++
  1.1255 + 	if (len == 0)
  1.1256 +-		len = fill(zbuf, INBUF_LEN);
  1.1257 ++		len = fill(zbuf, GZIP_IOBUF_SIZE);
  1.1258 + 
  1.1259 + 	/* verify the gzip header */
  1.1260 + 	if (len < 10 ||
  1.1261 +@@ -113,7 +122,7 @@
  1.1262 + 	while (rc == Z_OK) {
  1.1263 + 		if (strm->avail_in == 0) {
  1.1264 + 			/* TODO: handle case where both pos and fill are set */
  1.1265 +-			len = fill(zbuf, INBUF_LEN);
  1.1266 ++			len = fill(zbuf, GZIP_IOBUF_SIZE);
  1.1267 + 			if (len < 0) {
  1.1268 + 				rc = -1;
  1.1269 + 				error("read error");
  1.1270 +
  1.1271 +--- linux-2.6.30.6/lib/decompress_unlzma.c
  1.1272 ++++ linux-2.6.30.6/lib/decompress_unlzma.c
  1.1273 +@@ -29,12 +29,15 @@
  1.1274 +  *Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  1.1275 +  */
  1.1276 + 
  1.1277 +-#ifndef STATIC
  1.1278 ++#ifdef STATIC
  1.1279 ++#define PREBOOT
  1.1280 ++#else
  1.1281 + #include <linux/decompress/unlzma.h>
  1.1282 ++#include <linux/slab.h>
  1.1283 + #endif /* STATIC */
  1.1284 + 
  1.1285 ++#include <linux/decompress/unlzma_mm.h>
  1.1286 + #include <linux/decompress/mm.h>
  1.1287 +-#include <linux/slab.h>
  1.1288 + 
  1.1289 + #define	MIN(a, b) (((a) < (b)) ? (a) : (b))
  1.1290 + 
  1.1291 +@@ -80,8 +83,13 @@
  1.1292 + #define RC_MODEL_TOTAL_BITS 11
  1.1293 + 
  1.1294 + 
  1.1295 ++static int nofill(void *buffer, unsigned int len)
  1.1296 ++{
  1.1297 ++	return -1;
  1.1298 ++}
  1.1299 ++
  1.1300 + /* Called twice: once at startup and once in rc_normalize() */
  1.1301 +-static void INIT rc_read(struct rc *rc)
  1.1302 ++static void INIT rc_read(struct rc *rc, void(*error)(char *x))
  1.1303 + {
  1.1304 + 	rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
  1.1305 + 	if (rc->buffer_size <= 0)
  1.1306 +@@ -95,7 +103,10 @@
  1.1307 + 				       int (*fill)(void*, unsigned int),
  1.1308 + 				       char *buffer, int buffer_size)
  1.1309 + {
  1.1310 +-	rc->fill = fill;
  1.1311 ++	if (fill)
  1.1312 ++		rc->fill = fill;
  1.1313 ++	else
  1.1314 ++		rc->fill = nofill;
  1.1315 + 	rc->buffer = (uint8_t *)buffer;
  1.1316 + 	rc->buffer_size = buffer_size;
  1.1317 + 	rc->buffer_end = rc->buffer + rc->buffer_size;
  1.1318 +@@ -105,13 +116,13 @@
  1.1319 + 	rc->range = 0xFFFFFFFF;
  1.1320 + }
  1.1321 + 
  1.1322 +-static inline void INIT rc_init_code(struct rc *rc)
  1.1323 ++static inline void INIT rc_init_code(struct rc *rc, void(*error)(char *x))
  1.1324 + {
  1.1325 + 	int i;
  1.1326 + 
  1.1327 + 	for (i = 0; i < 5; i++) {
  1.1328 + 		if (rc->ptr >= rc->buffer_end)
  1.1329 +-			rc_read(rc);
  1.1330 ++			rc_read(rc, error);
  1.1331 + 		rc->code = (rc->code << 8) | *rc->ptr++;
  1.1332 + 	}
  1.1333 + }
  1.1334 +@@ -124,32 +135,33 @@
  1.1335 + }
  1.1336 + 
  1.1337 + /* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
  1.1338 +-static void INIT rc_do_normalize(struct rc *rc)
  1.1339 ++static void INIT rc_do_normalize(struct rc *rc, void(*error)(char *x))
  1.1340 + {
  1.1341 + 	if (rc->ptr >= rc->buffer_end)
  1.1342 +-		rc_read(rc);
  1.1343 ++		rc_read(rc, error);
  1.1344 + 	rc->range <<= 8;
  1.1345 + 	rc->code = (rc->code << 8) | *rc->ptr++;
  1.1346 + }
  1.1347 +-static inline void INIT rc_normalize(struct rc *rc)
  1.1348 ++static inline void INIT rc_normalize(struct rc *rc, void(*error)(char *x))
  1.1349 + {
  1.1350 + 	if (rc->range < (1 << RC_TOP_BITS))
  1.1351 +-		rc_do_normalize(rc);
  1.1352 ++		rc_do_normalize(rc, error);
  1.1353 + }
  1.1354 + 
  1.1355 + /* Called 9 times */
  1.1356 + /* Why rc_is_bit_0_helper exists?
  1.1357 +  *Because we want to always expose (rc->code < rc->bound) to optimizer
  1.1358 +  */
  1.1359 +-static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p)
  1.1360 ++static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p,
  1.1361 ++					       void (*error)(char *x))
  1.1362 + {
  1.1363 +-	rc_normalize(rc);
  1.1364 ++	rc_normalize(rc, error);
  1.1365 + 	rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
  1.1366 + 	return rc->bound;
  1.1367 + }
  1.1368 +-static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p)
  1.1369 ++static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p, void(*error)(char *x))
  1.1370 + {
  1.1371 +-	uint32_t t = rc_is_bit_0_helper(rc, p);
  1.1372 ++	uint32_t t = rc_is_bit_0_helper(rc, p, error);
  1.1373 + 	return rc->code < t;
  1.1374 + }
  1.1375 + 
  1.1376 +@@ -167,9 +179,9 @@
  1.1377 + }
  1.1378 + 
  1.1379 + /* Called 4 times in unlzma loop */
  1.1380 +-static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
  1.1381 ++static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol, void(*error)(char *x))
  1.1382 + {
  1.1383 +-	if (rc_is_bit_0(rc, p)) {
  1.1384 ++	if (rc_is_bit_0(rc, p, error)) {
  1.1385 + 		rc_update_bit_0(rc, p);
  1.1386 + 		*symbol *= 2;
  1.1387 + 		return 0;
  1.1388 +@@ -181,9 +193,9 @@
  1.1389 + }
  1.1390 + 
  1.1391 + /* Called once */
  1.1392 +-static inline int INIT rc_direct_bit(struct rc *rc)
  1.1393 ++static inline int INIT rc_direct_bit(struct rc *rc , void(*error)(char *x))
  1.1394 + {
  1.1395 +-	rc_normalize(rc);
  1.1396 ++	rc_normalize(rc, error);
  1.1397 + 	rc->range >>= 1;
  1.1398 + 	if (rc->code >= rc->range) {
  1.1399 + 		rc->code -= rc->range;
  1.1400 +@@ -194,13 +206,14 @@
  1.1401 + 
  1.1402 + /* Called twice */
  1.1403 + static inline void INIT
  1.1404 +-rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol)
  1.1405 ++rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol,
  1.1406 ++							void(*error)(char *x))
  1.1407 + {
  1.1408 + 	int i = num_levels;
  1.1409 + 
  1.1410 + 	*symbol = 1;
  1.1411 + 	while (i--)
  1.1412 +-		rc_get_bit(rc, p + *symbol, symbol);
  1.1413 ++		rc_get_bit(rc, p + *symbol, symbol, error);
  1.1414 + 	*symbol -= 1 << num_levels;
  1.1415 + }
  1.1416 + 
  1.1417 +@@ -396,7 +409,8 @@
  1.1418 + static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
  1.1419 + 				     struct cstate *cst, uint16_t *p,
  1.1420 + 				     int pos_state, uint16_t *prob,
  1.1421 +-				     int lc, uint32_t literal_pos_mask) {
  1.1422 ++				     int lc, uint32_t literal_pos_mask,
  1.1423 ++				     void(*error)(char *x)) {
  1.1424 + 	int mi = 1;
  1.1425 + 	static const int state[LZMA_NUM_STATES] = 
  1.1426 + 		{ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
  1.1427 +@@ -417,7 +431,7 @@
  1.1428 + 			match_byte <<= 1;
  1.1429 + 			bit = match_byte & 0x100;
  1.1430 + 			prob_lit = prob + 0x100 + bit + mi;
  1.1431 +-			if (rc_get_bit(rc, prob_lit, &mi)) {
  1.1432 ++			if (rc_get_bit(rc, prob_lit, &mi, error)) {
  1.1433 + 				if (!bit)
  1.1434 + 					break;
  1.1435 + 			} else {
  1.1436 +@@ -428,7 +442,7 @@
  1.1437 + 	}
  1.1438 + 	while (mi < 0x100) {
  1.1439 + 		uint16_t *prob_lit = prob + mi;
  1.1440 +-		rc_get_bit(rc, prob_lit, &mi);
  1.1441 ++		rc_get_bit(rc, prob_lit, &mi, error);
  1.1442 + 	}
  1.1443 + 	write_byte(wr, mi);
  1.1444 + 	cst->state = state[cst->state];
  1.1445 +@@ -436,7 +450,8 @@
  1.1446 + 
  1.1447 + static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
  1.1448 + 					    struct cstate *cst, uint16_t *p,
  1.1449 +-					    int pos_state, uint16_t *prob) {
  1.1450 ++					    int pos_state, uint16_t *prob,
  1.1451 ++					    void(*error)(char *x)) {
  1.1452 + 	int offset;
  1.1453 + 	uint16_t *prob_len;
  1.1454 + 	int num_bits;
  1.1455 +@@ -444,7 +459,7 @@
  1.1456 + 
  1.1457 + 	rc_update_bit_1(rc, prob);
  1.1458 + 	prob = p + LZMA_IS_REP + cst->state;
  1.1459 +-	if (rc_is_bit_0(rc, prob)) {
  1.1460 ++	if (rc_is_bit_0(rc, prob, error)) {
  1.1461 + 		rc_update_bit_0(rc, prob);
  1.1462 + 		cst->rep3 = cst->rep2;
  1.1463 + 		cst->rep2 = cst->rep1;
  1.1464 +@@ -454,13 +469,13 @@
  1.1465 + 	} else {
  1.1466 + 		rc_update_bit_1(rc, prob);
  1.1467 + 		prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
  1.1468 +-		if (rc_is_bit_0(rc, prob)) {
  1.1469 ++		if (rc_is_bit_0(rc, prob, error)) {
  1.1470 + 			rc_update_bit_0(rc, prob);
  1.1471 + 			prob = (p + LZMA_IS_REP_0_LONG
  1.1472 + 				+ (cst->state <<
  1.1473 + 				   LZMA_NUM_POS_BITS_MAX) +
  1.1474 + 				pos_state);
  1.1475 +-			if (rc_is_bit_0(rc, prob)) {
  1.1476 ++			if (rc_is_bit_0(rc, prob, error)) {
  1.1477 + 				rc_update_bit_0(rc, prob);
  1.1478 + 
  1.1479 + 				cst->state = cst->state < LZMA_NUM_LIT_STATES ?
  1.1480 +@@ -475,13 +490,13 @@
  1.1481 + 
  1.1482 + 			rc_update_bit_1(rc, prob);
  1.1483 + 			prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
  1.1484 +-			if (rc_is_bit_0(rc, prob)) {
  1.1485 ++			if (rc_is_bit_0(rc, prob, error)) {
  1.1486 + 				rc_update_bit_0(rc, prob);
  1.1487 + 				distance = cst->rep1;
  1.1488 + 			} else {
  1.1489 + 				rc_update_bit_1(rc, prob);
  1.1490 + 				prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
  1.1491 +-				if (rc_is_bit_0(rc, prob)) {
  1.1492 ++				if (rc_is_bit_0(rc, prob, error)) {
  1.1493 + 					rc_update_bit_0(rc, prob);
  1.1494 + 					distance = cst->rep2;
  1.1495 + 				} else {
  1.1496 +@@ -499,7 +514,7 @@
  1.1497 + 	}
  1.1498 + 
  1.1499 + 	prob_len = prob + LZMA_LEN_CHOICE;
  1.1500 +-	if (rc_is_bit_0(rc, prob_len)) {
  1.1501 ++	if (rc_is_bit_0(rc, prob_len, error)) {
  1.1502 + 		rc_update_bit_0(rc, prob_len);
  1.1503 + 		prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
  1.1504 + 			    + (pos_state <<
  1.1505 +@@ -509,7 +524,7 @@
  1.1506 + 	} else {
  1.1507 + 		rc_update_bit_1(rc, prob_len);
  1.1508 + 		prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
  1.1509 +-		if (rc_is_bit_0(rc, prob_len)) {
  1.1510 ++		if (rc_is_bit_0(rc, prob_len, error)) {
  1.1511 + 			rc_update_bit_0(rc, prob_len);
  1.1512 + 			prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
  1.1513 + 				    + (pos_state <<
  1.1514 +@@ -525,7 +540,7 @@
  1.1515 + 		}
  1.1516 + 	}
  1.1517 + 
  1.1518 +-	rc_bit_tree_decode(rc, prob_len, num_bits, &len);
  1.1519 ++	rc_bit_tree_decode(rc, prob_len, num_bits, &len, error);
  1.1520 + 	len += offset;
  1.1521 + 
  1.1522 + 	if (cst->state < 4) {
  1.1523 +@@ -540,7 +555,7 @@
  1.1524 + 			 << LZMA_NUM_POS_SLOT_BITS);
  1.1525 + 		rc_bit_tree_decode(rc, prob,
  1.1526 + 				   LZMA_NUM_POS_SLOT_BITS,
  1.1527 +-				   &pos_slot);
  1.1528 ++				   &pos_slot, error);
  1.1529 + 		if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
  1.1530 + 			int i, mi;
  1.1531 + 			num_bits = (pos_slot >> 1) - 1;
  1.1532 +@@ -553,7 +568,7 @@
  1.1533 + 				num_bits -= LZMA_NUM_ALIGN_BITS;
  1.1534 + 				while (num_bits--)
  1.1535 + 					cst->rep0 = (cst->rep0 << 1) |
  1.1536 +-						rc_direct_bit(rc);
  1.1537 ++						rc_direct_bit(rc, error);
  1.1538 + 				prob = p + LZMA_ALIGN;
  1.1539 + 				cst->rep0 <<= LZMA_NUM_ALIGN_BITS;
  1.1540 + 				num_bits = LZMA_NUM_ALIGN_BITS;
  1.1541 +@@ -561,7 +576,7 @@
  1.1542 + 			i = 1;
  1.1543 + 			mi = 1;
  1.1544 + 			while (num_bits--) {
  1.1545 +-				if (rc_get_bit(rc, prob + mi, &mi))
  1.1546 ++				if (rc_get_bit(rc, prob + mi, &mi, error))
  1.1547 + 					cst->rep0 |= i;
  1.1548 + 				i <<= 1;
  1.1549 + 			}
  1.1550 +@@ -578,12 +593,12 @@
  1.1551 + 
  1.1552 + 
  1.1553 + 
  1.1554 +-STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
  1.1555 ++STATIC int INIT unlzma(unsigned char *buf, int in_len,
  1.1556 + 			      int(*fill)(void*, unsigned int),
  1.1557 + 			      int(*flush)(void*, unsigned int),
  1.1558 + 			      unsigned char *output,
  1.1559 + 			      int *posp,
  1.1560 +-			      void(*error_fn)(char *x)
  1.1561 ++			      void(*error)(char *x)
  1.1562 + 	)
  1.1563 + {
  1.1564 + 	extern int cpio_flush_buffer(void*, unsigned int);
  1.1565 +@@ -600,10 +615,6 @@
  1.1566 + 	unsigned char *inbuf;
  1.1567 + 	int ret = -1;
  1.1568 + 
  1.1569 +-	set_error_fn(error_fn);
  1.1570 +-	if (!flush)
  1.1571 +-		in_len -= 4; /* Uncompressed size hack active in pre-boot
  1.1572 +-				environment */
  1.1573 + 	if (buf)
  1.1574 + 		inbuf = buf;
  1.1575 + 	else
  1.1576 +@@ -630,7 +641,7 @@
  1.1577 + 
  1.1578 + 	for (i = 0; i < sizeof(header); i++) {
  1.1579 + 		if (rc.ptr >= rc.buffer_end)
  1.1580 +-			rc_read(&rc);
  1.1581 ++			rc_read(&rc, error);
  1.1582 + 		((unsigned char *)&header)[i] = *rc.ptr++;
  1.1583 + 	}
  1.1584 + 
  1.1585 +@@ -675,17 +686,17 @@
  1.1586 + 	for (i = 0; i < num_probs; i++)
  1.1587 + 		p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
  1.1588 + 	wr.max_index = wr.next_index = 0;
  1.1589 +-	rc_init_code(&rc);
  1.1590 ++	rc_init_code(&rc, error);
  1.1591 + 
  1.1592 + 	while (get_pos(&wr) < header.dst_size) {
  1.1593 + 		int pos_state =	get_pos(&wr) & pos_state_mask;
  1.1594 + 		uint16_t *prob = p + LZMA_IS_MATCH +
  1.1595 + 			(cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
  1.1596 +-		if (rc_is_bit_0(&rc, prob))
  1.1597 ++		if (rc_is_bit_0(&rc, prob, error))
  1.1598 + 			process_bit0(&wr, &rc, &cst, p, pos_state, prob,
  1.1599 +-				     lc, literal_pos_mask);
  1.1600 ++				     lc, literal_pos_mask, error);
  1.1601 + 		else {
  1.1602 +-			process_bit1(&wr, &rc, &cst, p, pos_state, prob);
  1.1603 ++			process_bit1(&wr, &rc, &cst, p, pos_state, prob, error);
  1.1604 + 			if (cst.rep0 == 0)
  1.1605 + 				break;
  1.1606 + 		}
  1.1607 +@@ -719,5 +730,19 @@
  1.1608 + exit_0:
  1.1609 + 	return ret;
  1.1610 + }
  1.1611 ++#if defined(CONFIG_DECOMPRESS_LZMA_NEEDED) && !defined(PREBOOT)
  1.1612 ++EXPORT_SYMBOL(unlzma);
  1.1613 ++#endif
  1.1614 + 
  1.1615 +-#define decompress unlzma
  1.1616 ++#ifdef PREBOOT
  1.1617 ++STATIC int INIT decompress(unsigned char *buf, int in_len,
  1.1618 ++			      int(*fill)(void*, unsigned int),
  1.1619 ++			      int(*flush)(void*, unsigned int),
  1.1620 ++			      unsigned char *output,
  1.1621 ++			      int *posp,
  1.1622 ++			      void(*error_fn)(char *x)
  1.1623 ++	)
  1.1624 ++{
  1.1625 ++	return unlzma(buf, in_len - 4, fill, flush, output, posp, error_fn);
  1.1626 ++}
  1.1627 ++#endif