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