wok-current annotate linux-libre/stuff/linux-squashfs-lzma-2.6.34.u @ rev 20045

Improvements
author Leonardo Laporte <hackdorte@yandex.com>
date Thu Aug 31 04:02:39 2017 -0300 (2017-08-31)
parents
children
rev   line source
gokhlayeh@9257 1 --- linux-2.6.30.6/include/linux/decompress/bunzip2_mm.h
gokhlayeh@9257 2 +++ linux-2.6.30.6/include/linux/decompress/bunzip2_mm.h
gokhlayeh@9257 3 @@ -0,0 +1,13 @@
gokhlayeh@9257 4 +#ifndef BUNZIP2_MM_H
gokhlayeh@9257 5 +#define BUNZIP2_MM_H
gokhlayeh@9257 6 +
gokhlayeh@9257 7 +#ifdef STATIC
gokhlayeh@9257 8 +/* Code active when included from pre-boot environment: */
gokhlayeh@9257 9 +#define INIT
gokhlayeh@9257 10 +#else
gokhlayeh@9257 11 +/* Compile for initramfs/initrd code only */
gokhlayeh@9257 12 +#define INIT __init
gokhlayeh@9257 13 +static void(*error)(char *m);
gokhlayeh@9257 14 +#endif
gokhlayeh@9257 15 +
gokhlayeh@9257 16 +#endif
gokhlayeh@9257 17
gokhlayeh@9257 18 --- linux-2.6.30.6/include/linux/decompress/inflate_mm.h
gokhlayeh@9257 19 +++ linux-2.6.30.6/include/linux/decompress/inflate_mm.h
gokhlayeh@9257 20 @@ -0,0 +1,13 @@
gokhlayeh@9257 21 +#ifndef INFLATE_MM_H
gokhlayeh@9257 22 +#define INFLATE_MM_H
gokhlayeh@9257 23 +
gokhlayeh@9257 24 +#ifdef STATIC
gokhlayeh@9257 25 +/* Code active when included from pre-boot environment: */
gokhlayeh@9257 26 +#define INIT
gokhlayeh@9257 27 +#else
gokhlayeh@9257 28 +/* Compile for initramfs/initrd code only */
gokhlayeh@9257 29 +#define INIT __init
gokhlayeh@9257 30 +static void(*error)(char *m);
gokhlayeh@9257 31 +#endif
gokhlayeh@9257 32 +
gokhlayeh@9257 33 +#endif
gokhlayeh@9257 34
gokhlayeh@9257 35 #--- linux-2.6.30.6/include/linux/decompress/mm.h
gokhlayeh@9257 36 #+++ linux-2.6.30.6/include/linux/decompress/mm.h
gokhlayeh@9257 37 @@ -63,8 +63,6 @@
gokhlayeh@9257 38
gokhlayeh@9257 39 #define set_error_fn(x)
gokhlayeh@9257 40
gokhlayeh@9257 41 -#define INIT
gokhlayeh@9257 42 -
gokhlayeh@9257 43 #else /* STATIC */
gokhlayeh@9257 44
gokhlayeh@9257 45 /* Code active when compiled standalone for use when loading ramdisk: */
gokhlayeh@9257 46 @@ -84,10 +82,8 @@
gokhlayeh@9257 47 #define large_malloc(a) vmalloc(a)
gokhlayeh@9257 48 #define large_free(a) vfree(a)
gokhlayeh@9257 49
gokhlayeh@9257 50 -static void(*error)(char *m);
gokhlayeh@9257 51 #define set_error_fn(x) error = x;
gokhlayeh@9257 52
gokhlayeh@9257 53 -#define INIT __init
gokhlayeh@9257 54 #define STATIC
gokhlayeh@9257 55
gokhlayeh@9257 56 #include <linux/init.h>
gokhlayeh@9257 57
gokhlayeh@9257 58 --- linux-2.6.30.6/include/linux/decompress/unlzma_mm.h
gokhlayeh@9257 59 +++ linux-2.6.30.6/include/linux/decompress/unlzma_mm.h
gokhlayeh@9257 60 @@ -0,0 +1,20 @@
gokhlayeh@9257 61 +#ifndef UNLZMA_MM_H
gokhlayeh@9257 62 +#define UNLZMA_MM_H
gokhlayeh@9257 63 +
gokhlayeh@9257 64 +#ifdef STATIC
gokhlayeh@9257 65 +
gokhlayeh@9257 66 +/* Code active when included from pre-boot environment: */
gokhlayeh@9257 67 +#define INIT
gokhlayeh@9257 68 +
gokhlayeh@9257 69 +#elif defined(CONFIG_DECOMPRESS_LZMA_NEEDED)
gokhlayeh@9257 70 +
gokhlayeh@9257 71 +/* Make it available to non initramfs/initrd code */
gokhlayeh@9257 72 +#define INIT
gokhlayeh@9257 73 +#include <linux/module.h>
gokhlayeh@9257 74 +#else
gokhlayeh@9257 75 +
gokhlayeh@9257 76 +/* Compile for initramfs/initrd code only */
gokhlayeh@9257 77 +#define INIT __init
gokhlayeh@9257 78 +#endif
gokhlayeh@9257 79 +
gokhlayeh@9257 80 +#endif
gokhlayeh@9257 81
gokhlayeh@9257 82 --- linux-2.6.30.6/lib/Kconfig
gokhlayeh@9257 83 +++ linux-2.6.30.6/lib/Kconfig
gokhlayeh@9257 84 @@ -117,6 +117,9 @@
gokhlayeh@9257 85 config DECOMPRESS_LZMA
gokhlayeh@9257 86 tristate
gokhlayeh@9257 87
gokhlayeh@9257 88 +config DECOMPRESS_LZMA_NEEDED
gokhlayeh@9257 89 + boolean
gokhlayeh@9257 90 +
gokhlayeh@9257 91 config DECOMPRESS_LZO
gokhlayeh@9257 92 select LZO_DECOMPRESS
gokhlayeh@9257 93 tristate
gokhlayeh@9257 94
gokhlayeh@9257 95 --- linux-2.6.30.6/lib/decompress_bunzip2.c
gokhlayeh@9257 96 +++ linux-2.6.30.6/lib/decompress_bunzip2.c
gokhlayeh@9257 97 @@ -52,6 +52,7 @@
gokhlayeh@9257 98 #include <linux/slab.h>
gokhlayeh@9257 99 #endif /* STATIC */
gokhlayeh@9257 100
gokhlayeh@9257 101 +#include <linux/decompress/bunzip2_mm.h>
gokhlayeh@9257 102 #include <linux/decompress/mm.h>
gokhlayeh@9257 103
gokhlayeh@9257 104 #ifndef INT_MAX
gokhlayeh@9257 105
gokhlayeh@9257 106 --- linux-2.6.30.6/lib/decompress_inflate.c
gokhlayeh@9257 107 +++ linux-2.6.30.6/lib/decompress_inflate.c
gokhlayeh@9257 108 @@ -23,6 +23,7 @@
gokhlayeh@9257 109
gokhlayeh@9257 110 #endif /* STATIC */
gokhlayeh@9257 111
gokhlayeh@9257 112 +#include <linux/decompress/inflate_mm.h>
gokhlayeh@9257 113 #include <linux/decompress/mm.h>
gokhlayeh@9257 114
gokhlayeh@9257 115 #define GZIP_IOBUF_SIZE (16*1024)
gokhlayeh@9257 116
gokhlayeh@9257 117 --- linux-2.6.30.6/lib/decompress_unlzma.c
gokhlayeh@9257 118 +++ linux-2.6.30.6/lib/decompress_unlzma.c
gokhlayeh@9257 119 @@ -36,6 +36,7 @@
gokhlayeh@9257 120 #include <linux/slab.h>
gokhlayeh@9257 121 #endif /* STATIC */
gokhlayeh@9257 122
gokhlayeh@9257 123 +#include <linux/decompress/unlzma_mm.h>
gokhlayeh@9257 124 #include <linux/decompress/mm.h>
gokhlayeh@9257 125
gokhlayeh@9257 126 #define MIN(a, b) (((a) < (b)) ? (a) : (b))
gokhlayeh@9257 127 @@ -88,7 +89,7 @@
gokhlayeh@9257 128 }
gokhlayeh@9257 129
gokhlayeh@9257 130 /* Called twice: once at startup and once in rc_normalize() */
gokhlayeh@9257 131 -static void INIT rc_read(struct rc *rc)
gokhlayeh@9257 132 +static void INIT rc_read(struct rc *rc, void(*error)(char *x))
gokhlayeh@9257 133 {
gokhlayeh@9257 134 rc->buffer_size = rc->fill((char *)rc->buffer, LZMA_IOBUF_SIZE);
gokhlayeh@9257 135 if (rc->buffer_size <= 0)
gokhlayeh@9257 136 @@ -115,13 +116,13 @@
gokhlayeh@9257 137 rc->range = 0xFFFFFFFF;
gokhlayeh@9257 138 }
gokhlayeh@9257 139
gokhlayeh@9257 140 -static inline void INIT rc_init_code(struct rc *rc)
gokhlayeh@9257 141 +static inline void INIT rc_init_code(struct rc *rc, void(*error)(char *x))
gokhlayeh@9257 142 {
gokhlayeh@9257 143 int i;
gokhlayeh@9257 144
gokhlayeh@9257 145 for (i = 0; i < 5; i++) {
gokhlayeh@9257 146 if (rc->ptr >= rc->buffer_end)
gokhlayeh@9257 147 - rc_read(rc);
gokhlayeh@9257 148 + rc_read(rc, error);
gokhlayeh@9257 149 rc->code = (rc->code << 8) | *rc->ptr++;
gokhlayeh@9257 150 }
gokhlayeh@9257 151 }
gokhlayeh@9257 152 @@ -134,32 +135,33 @@
gokhlayeh@9257 153 }
gokhlayeh@9257 154
gokhlayeh@9257 155 /* Called twice, but one callsite is in inline'd rc_is_bit_0_helper() */
gokhlayeh@9257 156 -static void INIT rc_do_normalize(struct rc *rc)
gokhlayeh@9257 157 +static void INIT rc_do_normalize(struct rc *rc, void(*error)(char *x))
gokhlayeh@9257 158 {
gokhlayeh@9257 159 if (rc->ptr >= rc->buffer_end)
gokhlayeh@9257 160 - rc_read(rc);
gokhlayeh@9257 161 + rc_read(rc, error);
gokhlayeh@9257 162 rc->range <<= 8;
gokhlayeh@9257 163 rc->code = (rc->code << 8) | *rc->ptr++;
gokhlayeh@9257 164 }
gokhlayeh@9257 165 -static inline void INIT rc_normalize(struct rc *rc)
gokhlayeh@9257 166 +static inline void INIT rc_normalize(struct rc *rc, void(*error)(char *x))
gokhlayeh@9257 167 {
gokhlayeh@9257 168 if (rc->range < (1 << RC_TOP_BITS))
gokhlayeh@9257 169 - rc_do_normalize(rc);
gokhlayeh@9257 170 + rc_do_normalize(rc, error);
gokhlayeh@9257 171 }
gokhlayeh@9257 172
gokhlayeh@9257 173 /* Called 9 times */
gokhlayeh@9257 174 /* Why rc_is_bit_0_helper exists?
gokhlayeh@9257 175 *Because we want to always expose (rc->code < rc->bound) to optimizer
gokhlayeh@9257 176 */
gokhlayeh@9257 177 -static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p)
gokhlayeh@9257 178 +static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p,
gokhlayeh@9257 179 + void (*error)(char *x))
gokhlayeh@9257 180 {
gokhlayeh@9257 181 - rc_normalize(rc);
gokhlayeh@9257 182 + rc_normalize(rc, error);
gokhlayeh@9257 183 rc->bound = *p * (rc->range >> RC_MODEL_TOTAL_BITS);
gokhlayeh@9257 184 return rc->bound;
gokhlayeh@9257 185 }
gokhlayeh@9257 186 -static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p)
gokhlayeh@9257 187 +static inline int INIT rc_is_bit_0(struct rc *rc, uint16_t *p, void(*error)(char *x))
gokhlayeh@9257 188 {
gokhlayeh@9257 189 - uint32_t t = rc_is_bit_0_helper(rc, p);
gokhlayeh@9257 190 + uint32_t t = rc_is_bit_0_helper(rc, p, error);
gokhlayeh@9257 191 return rc->code < t;
gokhlayeh@9257 192 }
gokhlayeh@9257 193
gokhlayeh@9257 194 @@ -177,9 +179,9 @@
gokhlayeh@9257 195 }
gokhlayeh@9257 196
gokhlayeh@9257 197 /* Called 4 times in unlzma loop */
gokhlayeh@9257 198 -static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol)
gokhlayeh@9257 199 +static int INIT rc_get_bit(struct rc *rc, uint16_t *p, int *symbol, void(*error)(char *x))
gokhlayeh@9257 200 {
gokhlayeh@9257 201 - if (rc_is_bit_0(rc, p)) {
gokhlayeh@9257 202 + if (rc_is_bit_0(rc, p, error)) {
gokhlayeh@9257 203 rc_update_bit_0(rc, p);
gokhlayeh@9257 204 *symbol *= 2;
gokhlayeh@9257 205 return 0;
gokhlayeh@9257 206 @@ -191,9 +193,9 @@
gokhlayeh@9257 207 }
gokhlayeh@9257 208
gokhlayeh@9257 209 /* Called once */
gokhlayeh@9257 210 -static inline int INIT rc_direct_bit(struct rc *rc)
gokhlayeh@9257 211 +static inline int INIT rc_direct_bit(struct rc *rc , void(*error)(char *x))
gokhlayeh@9257 212 {
gokhlayeh@9257 213 - rc_normalize(rc);
gokhlayeh@9257 214 + rc_normalize(rc, error);
gokhlayeh@9257 215 rc->range >>= 1;
gokhlayeh@9257 216 if (rc->code >= rc->range) {
gokhlayeh@9257 217 rc->code -= rc->range;
gokhlayeh@9257 218 @@ -204,13 +206,14 @@
gokhlayeh@9257 219
gokhlayeh@9257 220 /* Called twice */
gokhlayeh@9257 221 static inline void INIT
gokhlayeh@9257 222 -rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol)
gokhlayeh@9257 223 +rc_bit_tree_decode(struct rc *rc, uint16_t *p, int num_levels, int *symbol,
gokhlayeh@9257 224 + void(*error)(char *x))
gokhlayeh@9257 225 {
gokhlayeh@9257 226 int i = num_levels;
gokhlayeh@9257 227
gokhlayeh@9257 228 *symbol = 1;
gokhlayeh@9257 229 while (i--)
gokhlayeh@9257 230 - rc_get_bit(rc, p + *symbol, symbol);
gokhlayeh@9257 231 + rc_get_bit(rc, p + *symbol, symbol, error);
gokhlayeh@9257 232 *symbol -= 1 << num_levels;
gokhlayeh@9257 233 }
gokhlayeh@9257 234
gokhlayeh@9257 235 @@ -406,7 +409,8 @@
gokhlayeh@9257 236 static inline void INIT process_bit0(struct writer *wr, struct rc *rc,
gokhlayeh@9257 237 struct cstate *cst, uint16_t *p,
gokhlayeh@9257 238 int pos_state, uint16_t *prob,
gokhlayeh@9257 239 - int lc, uint32_t literal_pos_mask) {
gokhlayeh@9257 240 + int lc, uint32_t literal_pos_mask,
gokhlayeh@9257 241 + void(*error)(char *x)) {
gokhlayeh@9257 242 int mi = 1;
gokhlayeh@9257 243 static const int state[LZMA_NUM_STATES] =
gokhlayeh@9257 244 { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
gokhlayeh@9257 245 @@ -427,7 +431,7 @@
gokhlayeh@9257 246 match_byte <<= 1;
gokhlayeh@9257 247 bit = match_byte & 0x100;
gokhlayeh@9257 248 prob_lit = prob + 0x100 + bit + mi;
gokhlayeh@9257 249 - if (rc_get_bit(rc, prob_lit, &mi)) {
gokhlayeh@9257 250 + if (rc_get_bit(rc, prob_lit, &mi, error)) {
gokhlayeh@9257 251 if (!bit)
gokhlayeh@9257 252 break;
gokhlayeh@9257 253 } else {
gokhlayeh@9257 254 @@ -438,7 +442,7 @@
gokhlayeh@9257 255 }
gokhlayeh@9257 256 while (mi < 0x100) {
gokhlayeh@9257 257 uint16_t *prob_lit = prob + mi;
gokhlayeh@9257 258 - rc_get_bit(rc, prob_lit, &mi);
gokhlayeh@9257 259 + rc_get_bit(rc, prob_lit, &mi, error);
gokhlayeh@9257 260 }
gokhlayeh@9257 261 write_byte(wr, mi);
gokhlayeh@9257 262 cst->state = state[cst->state];
gokhlayeh@9257 263 @@ -446,7 +453,8 @@
gokhlayeh@9257 264
gokhlayeh@9257 265 static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
gokhlayeh@9257 266 struct cstate *cst, uint16_t *p,
gokhlayeh@9257 267 - int pos_state, uint16_t *prob) {
gokhlayeh@9257 268 + int pos_state, uint16_t *prob,
gokhlayeh@9257 269 + void(*error)(char *x)) {
gokhlayeh@9257 270 int offset;
gokhlayeh@9257 271 uint16_t *prob_len;
gokhlayeh@9257 272 int num_bits;
gokhlayeh@9257 273 @@ -454,7 +459,7 @@
gokhlayeh@9257 274
gokhlayeh@9257 275 rc_update_bit_1(rc, prob);
gokhlayeh@9257 276 prob = p + LZMA_IS_REP + cst->state;
gokhlayeh@9257 277 - if (rc_is_bit_0(rc, prob)) {
gokhlayeh@9257 278 + if (rc_is_bit_0(rc, prob, error)) {
gokhlayeh@9257 279 rc_update_bit_0(rc, prob);
gokhlayeh@9257 280 cst->rep3 = cst->rep2;
gokhlayeh@9257 281 cst->rep2 = cst->rep1;
gokhlayeh@9257 282 @@ -464,13 +469,13 @@
gokhlayeh@9257 283 } else {
gokhlayeh@9257 284 rc_update_bit_1(rc, prob);
gokhlayeh@9257 285 prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
gokhlayeh@9257 286 - if (rc_is_bit_0(rc, prob)) {
gokhlayeh@9257 287 + if (rc_is_bit_0(rc, prob, error)) {
gokhlayeh@9257 288 rc_update_bit_0(rc, prob);
gokhlayeh@9257 289 prob = (p + LZMA_IS_REP_0_LONG
gokhlayeh@9257 290 + (cst->state <<
gokhlayeh@9257 291 LZMA_NUM_POS_BITS_MAX) +
gokhlayeh@9257 292 pos_state);
gokhlayeh@9257 293 - if (rc_is_bit_0(rc, prob)) {
gokhlayeh@9257 294 + if (rc_is_bit_0(rc, prob, error)) {
gokhlayeh@9257 295 rc_update_bit_0(rc, prob);
gokhlayeh@9257 296
gokhlayeh@9257 297 cst->state = cst->state < LZMA_NUM_LIT_STATES ?
gokhlayeh@9257 298 @@ -485,13 +490,13 @@
gokhlayeh@9257 299
gokhlayeh@9257 300 rc_update_bit_1(rc, prob);
gokhlayeh@9257 301 prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
gokhlayeh@9257 302 - if (rc_is_bit_0(rc, prob)) {
gokhlayeh@9257 303 + if (rc_is_bit_0(rc, prob, error)) {
gokhlayeh@9257 304 rc_update_bit_0(rc, prob);
gokhlayeh@9257 305 distance = cst->rep1;
gokhlayeh@9257 306 } else {
gokhlayeh@9257 307 rc_update_bit_1(rc, prob);
gokhlayeh@9257 308 prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
gokhlayeh@9257 309 - if (rc_is_bit_0(rc, prob)) {
gokhlayeh@9257 310 + if (rc_is_bit_0(rc, prob, error)) {
gokhlayeh@9257 311 rc_update_bit_0(rc, prob);
gokhlayeh@9257 312 distance = cst->rep2;
gokhlayeh@9257 313 } else {
gokhlayeh@9257 314 @@ -509,7 +514,7 @@
gokhlayeh@9257 315 }
gokhlayeh@9257 316
gokhlayeh@9257 317 prob_len = prob + LZMA_LEN_CHOICE;
gokhlayeh@9257 318 - if (rc_is_bit_0(rc, prob_len)) {
gokhlayeh@9257 319 + if (rc_is_bit_0(rc, prob_len, error)) {
gokhlayeh@9257 320 rc_update_bit_0(rc, prob_len);
gokhlayeh@9257 321 prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
gokhlayeh@9257 322 + (pos_state <<
gokhlayeh@9257 323 @@ -519,7 +524,7 @@
gokhlayeh@9257 324 } else {
gokhlayeh@9257 325 rc_update_bit_1(rc, prob_len);
gokhlayeh@9257 326 prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
gokhlayeh@9257 327 - if (rc_is_bit_0(rc, prob_len)) {
gokhlayeh@9257 328 + if (rc_is_bit_0(rc, prob_len, error)) {
gokhlayeh@9257 329 rc_update_bit_0(rc, prob_len);
gokhlayeh@9257 330 prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
gokhlayeh@9257 331 + (pos_state <<
gokhlayeh@9257 332 @@ -535,7 +540,7 @@
gokhlayeh@9257 333 }
gokhlayeh@9257 334 }
gokhlayeh@9257 335
gokhlayeh@9257 336 - rc_bit_tree_decode(rc, prob_len, num_bits, &len);
gokhlayeh@9257 337 + rc_bit_tree_decode(rc, prob_len, num_bits, &len, error);
gokhlayeh@9257 338 len += offset;
gokhlayeh@9257 339
gokhlayeh@9257 340 if (cst->state < 4) {
gokhlayeh@9257 341 @@ -550,7 +555,7 @@
gokhlayeh@9257 342 << LZMA_NUM_POS_SLOT_BITS);
gokhlayeh@9257 343 rc_bit_tree_decode(rc, prob,
gokhlayeh@9257 344 LZMA_NUM_POS_SLOT_BITS,
gokhlayeh@9257 345 - &pos_slot);
gokhlayeh@9257 346 + &pos_slot, error);
gokhlayeh@9257 347 if (pos_slot >= LZMA_START_POS_MODEL_INDEX) {
gokhlayeh@9257 348 int i, mi;
gokhlayeh@9257 349 num_bits = (pos_slot >> 1) - 1;
gokhlayeh@9257 350 @@ -563,7 +568,7 @@
gokhlayeh@9257 351 num_bits -= LZMA_NUM_ALIGN_BITS;
gokhlayeh@9257 352 while (num_bits--)
gokhlayeh@9257 353 cst->rep0 = (cst->rep0 << 1) |
gokhlayeh@9257 354 - rc_direct_bit(rc);
gokhlayeh@9257 355 + rc_direct_bit(rc, error);
gokhlayeh@9257 356 prob = p + LZMA_ALIGN;
gokhlayeh@9257 357 cst->rep0 <<= LZMA_NUM_ALIGN_BITS;
gokhlayeh@9257 358 num_bits = LZMA_NUM_ALIGN_BITS;
gokhlayeh@9257 359 @@ -571,7 +576,7 @@
gokhlayeh@9257 360 i = 1;
gokhlayeh@9257 361 mi = 1;
gokhlayeh@9257 362 while (num_bits--) {
gokhlayeh@9257 363 - if (rc_get_bit(rc, prob + mi, &mi))
gokhlayeh@9257 364 + if (rc_get_bit(rc, prob + mi, &mi, error))
gokhlayeh@9257 365 cst->rep0 |= i;
gokhlayeh@9257 366 i <<= 1;
gokhlayeh@9257 367 }
gokhlayeh@9257 368 @@ -588,12 +593,12 @@
gokhlayeh@9257 369
gokhlayeh@9257 370
gokhlayeh@9257 371
gokhlayeh@9257 372 -STATIC inline int INIT unlzma(unsigned char *buf, int in_len,
gokhlayeh@9257 373 +STATIC int INIT unlzma(unsigned char *buf, int in_len,
gokhlayeh@9257 374 int(*fill)(void*, unsigned int),
gokhlayeh@9257 375 int(*flush)(void*, unsigned int),
gokhlayeh@9257 376 unsigned char *output,
gokhlayeh@9257 377 int *posp,
gokhlayeh@9257 378 - void(*error_fn)(char *x)
gokhlayeh@9257 379 + void(*error)(char *x)
gokhlayeh@9257 380 )
gokhlayeh@9257 381 {
gokhlayeh@9257 382 extern int cpio_flush_buffer(void*, unsigned int);
gokhlayeh@9257 383 @@ -610,7 +615,6 @@
gokhlayeh@9257 384 unsigned char *inbuf;
gokhlayeh@9257 385 int ret = -1;
gokhlayeh@9257 386
gokhlayeh@9257 387 - set_error_fn(error_fn);
gokhlayeh@9257 388
gokhlayeh@9257 389 if (buf)
gokhlayeh@9257 390 inbuf = buf;
gokhlayeh@9257 391 @@ -638,7 +642,7 @@
gokhlayeh@9257 392
gokhlayeh@9257 393 for (i = 0; i < sizeof(header); i++) {
gokhlayeh@9257 394 if (rc.ptr >= rc.buffer_end)
gokhlayeh@9257 395 - rc_read(&rc);
gokhlayeh@9257 396 + rc_read(&rc, error);
gokhlayeh@9257 397 ((unsigned char *)&header)[i] = *rc.ptr++;
gokhlayeh@9257 398 }
gokhlayeh@9257 399
gokhlayeh@9257 400 @@ -683,17 +687,17 @@
gokhlayeh@9257 401 for (i = 0; i < num_probs; i++)
gokhlayeh@9257 402 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
gokhlayeh@9257 403 wr.max_index = wr.next_index = 0;
gokhlayeh@9257 404 - rc_init_code(&rc);
gokhlayeh@9257 405 + rc_init_code(&rc, error);
gokhlayeh@9257 406
gokhlayeh@9257 407 while (get_pos(&wr) < header.dst_size) {
gokhlayeh@9257 408 int pos_state = get_pos(&wr) & pos_state_mask;
gokhlayeh@9257 409 uint16_t *prob = p + LZMA_IS_MATCH +
gokhlayeh@9257 410 (cst.state << LZMA_NUM_POS_BITS_MAX) + pos_state;
gokhlayeh@9257 411 - if (rc_is_bit_0(&rc, prob))
gokhlayeh@9257 412 + if (rc_is_bit_0(&rc, prob, error))
gokhlayeh@9257 413 process_bit0(&wr, &rc, &cst, p, pos_state, prob,
gokhlayeh@9257 414 - lc, literal_pos_mask);
gokhlayeh@9257 415 + lc, literal_pos_mask, error);
gokhlayeh@9257 416 else {
gokhlayeh@9257 417 - process_bit1(&wr, &rc, &cst, p, pos_state, prob);
gokhlayeh@9257 418 + process_bit1(&wr, &rc, &cst, p, pos_state, prob, error);
gokhlayeh@9257 419 if (cst.rep0 == 0)
gokhlayeh@9257 420 break;
gokhlayeh@9257 421 }
gokhlayeh@9257 422 @@ -727,6 +731,9 @@
gokhlayeh@9257 423 exit_0:
gokhlayeh@9257 424 return ret;
gokhlayeh@9257 425 }
gokhlayeh@9257 426 +#if defined(CONFIG_DECOMPRESS_LZMA_NEEDED) && !defined(PREBOOT)
gokhlayeh@9257 427 +EXPORT_SYMBOL(unlzma);
gokhlayeh@9257 428 +#endif
gokhlayeh@9257 429
gokhlayeh@9257 430 #ifdef PREBOOT
gokhlayeh@9257 431 STATIC int INIT decompress(unsigned char *buf, int in_len,
gokhlayeh@9257 432
gokhlayeh@9257 433 --- linux-2.6.34/fs/squashfs/Kconfig
gokhlayeh@9257 434 +++ linux-2.6.34/fs/squashfs/Kconfig
gokhlayeh@9257 435 @@ -26,6 +26,12 @@
gokhlayeh@9257 436
gokhlayeh@9257 437 If unsure, say N.
gokhlayeh@9257 438
gokhlayeh@9257 439 +config SQUASHFS_LZMA
gokhlayeh@9257 440 + bool "Include support for LZMA compressed file systems"
gokhlayeh@9257 441 + depends on SQUASHFS
gokhlayeh@9257 442 + select DECOMPRESS_LZMA
gokhlayeh@9257 443 + select DECOMPRESS_LZMA_NEEDED
gokhlayeh@9257 444 +
gokhlayeh@9257 445 config SQUASHFS_EMBEDDED
gokhlayeh@9257 446
gokhlayeh@9257 447 bool "Additional option for memory-constrained systems"
gokhlayeh@9257 448
gokhlayeh@9257 449 --- linux-2.6.34/fs/squashfs/Makefile
gokhlayeh@9257 450 +++ linux-2.6.34/fs/squashfs/Makefile
gokhlayeh@9257 451 @@ -5,3 +5,4 @@
gokhlayeh@9257 452 obj-$(CONFIG_SQUASHFS) += squashfs.o
gokhlayeh@9257 453 squashfs-y += block.o cache.o dir.o export.o file.o fragment.o id.o inode.o
gokhlayeh@9257 454 squashfs-y += namei.o super.o symlink.o zlib_wrapper.o decompressor.o
gokhlayeh@9257 455 +squashfs-$(CONFIG_SQUASHFS_LZMA) += lzma_wrapper.o
gokhlayeh@9257 456
gokhlayeh@9257 457 --- linux-2.6.34/fs/squashfs/decompressor.c
gokhlayeh@9257 458 +++ linux-2.6.34/fs/squashfs/decompressor.c
gokhlayeh@9257 459 @@ -50,7 +50,11 @@
gokhlayeh@9257 460
gokhlayeh@9257 461 static const struct squashfs_decompressor *decompressor[] = {
gokhlayeh@9257 462 &squashfs_zlib_comp_ops,
gokhlayeh@9257 463 +#ifdef CONFIG_SQUASHFS_LZMA
gokhlayeh@9257 464 + &squashfs_lzma_comp_ops,
gokhlayeh@9257 465 +#else
gokhlayeh@9257 466 &squashfs_lzma_unsupported_comp_ops,
gokhlayeh@9257 467 +#endif
gokhlayeh@9257 468 &squashfs_lzo_unsupported_comp_ops,
gokhlayeh@9257 469 &squashfs_unknown_comp_ops
gokhlayeh@9257 470 };
gokhlayeh@9257 471
gokhlayeh@9257 472 --- linux-2.6.34/fs/squashfs/lzma_wrapper.c
gokhlayeh@9257 473 +++ linux-2.6.34/fs/squashfs/lzma_wrapper.c
gokhlayeh@9257 474 @@ -0,0 +1,152 @@
gokhlayeh@9257 475 +/*
gokhlayeh@9257 476 + * Squashfs - a compressed read only filesystem for Linux
gokhlayeh@9257 477 + *
gokhlayeh@9257 478 + * Copyright (c) 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
gokhlayeh@9257 479 + * Phillip Lougher <phillip@lougher.demon.co.uk>
gokhlayeh@9257 480 + *
gokhlayeh@9257 481 + * This program is free software; you can redistribute it and/or
gokhlayeh@9257 482 + * modify it under the terms of the GNU General Public License
gokhlayeh@9257 483 + * as published by the Free Software Foundation; either version 2,
gokhlayeh@9257 484 + * or (at your option) any later version.
gokhlayeh@9257 485 + *
gokhlayeh@9257 486 + * This program is distributed in the hope that it will be useful,
gokhlayeh@9257 487 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
gokhlayeh@9257 488 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
gokhlayeh@9257 489 + * GNU General Public License for more details.
gokhlayeh@9257 490 + *
gokhlayeh@9257 491 + * You should have received a copy of the GNU General Public License
gokhlayeh@9257 492 + * along with this program; if not, write to the Free Software
gokhlayeh@9257 493 + * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
gokhlayeh@9257 494 + *
gokhlayeh@9257 495 + * lzma_wrapper.c
gokhlayeh@9257 496 + */
gokhlayeh@9257 497 +
gokhlayeh@9257 498 +#include <asm/unaligned.h>
gokhlayeh@9257 499 +#include <linux/slab.h>
gokhlayeh@9257 500 +#include <linux/buffer_head.h>
gokhlayeh@9257 501 +#include <linux/mutex.h>
gokhlayeh@9257 502 +#include <linux/vmalloc.h>
gokhlayeh@9257 503 +#include <linux/decompress/unlzma.h>
gokhlayeh@9257 504 +
gokhlayeh@9257 505 +#include "squashfs_fs.h"
gokhlayeh@9257 506 +#include "squashfs_fs_sb.h"
gokhlayeh@9257 507 +#include "squashfs_fs_i.h"
gokhlayeh@9257 508 +#include "squashfs.h"
gokhlayeh@9257 509 +#include "decompressor.h"
gokhlayeh@9257 510 +
gokhlayeh@9257 511 +struct squashfs_lzma {
gokhlayeh@9257 512 + void *input;
gokhlayeh@9257 513 + void *output;
gokhlayeh@9257 514 +};
gokhlayeh@9257 515 +
gokhlayeh@9257 516 +/* decompress_unlzma.c is currently non re-entrant... */
gokhlayeh@9257 517 +DEFINE_MUTEX(lzma_mutex);
gokhlayeh@9257 518 +
gokhlayeh@9257 519 +/* decompress_unlzma.c doesn't provide any context in its callbacks... */
gokhlayeh@9257 520 +static int lzma_error;
gokhlayeh@9257 521 +
gokhlayeh@9257 522 +static void error(char *m)
gokhlayeh@9257 523 +{
gokhlayeh@9257 524 + ERROR("unlzma error: %s\n", m);
gokhlayeh@9257 525 + lzma_error = 1;
gokhlayeh@9257 526 +}
gokhlayeh@9257 527 +
gokhlayeh@9257 528 +
gokhlayeh@9257 529 +static void *lzma_init(struct squashfs_sb_info *msblk)
gokhlayeh@9257 530 +{
gokhlayeh@9257 531 + struct squashfs_lzma *stream = kzalloc(sizeof(*stream), GFP_KERNEL);
gokhlayeh@9257 532 + if (stream == NULL)
gokhlayeh@9257 533 + goto failed;
gokhlayeh@9257 534 + stream->input = vmalloc(msblk->block_size);
gokhlayeh@9257 535 + if (stream->input == NULL)
gokhlayeh@9257 536 + goto failed;
gokhlayeh@9257 537 + stream->output = vmalloc(msblk->block_size);
gokhlayeh@9257 538 + if (stream->output == NULL)
gokhlayeh@9257 539 + goto failed2;
gokhlayeh@9257 540 +
gokhlayeh@9257 541 + return stream;
gokhlayeh@9257 542 +
gokhlayeh@9257 543 +failed2:
gokhlayeh@9257 544 + vfree(stream->input);
gokhlayeh@9257 545 +failed:
gokhlayeh@9257 546 + ERROR("failed to allocate lzma workspace\n");
gokhlayeh@9257 547 + kfree(stream);
gokhlayeh@9257 548 + return NULL;
gokhlayeh@9257 549 +}
gokhlayeh@9257 550 +
gokhlayeh@9257 551 +
gokhlayeh@9257 552 +static void lzma_free(void *strm)
gokhlayeh@9257 553 +{
gokhlayeh@9257 554 + struct squashfs_lzma *stream = strm;
gokhlayeh@9257 555 +
gokhlayeh@9257 556 + if (stream) {
gokhlayeh@9257 557 + vfree(stream->input);
gokhlayeh@9257 558 + vfree(stream->output);
gokhlayeh@9257 559 + }
gokhlayeh@9257 560 + kfree(stream);
gokhlayeh@9257 561 +}
gokhlayeh@9257 562 +
gokhlayeh@9257 563 +
gokhlayeh@9257 564 +static int lzma_uncompress(struct squashfs_sb_info *msblk, void **buffer,
gokhlayeh@9257 565 + struct buffer_head **bh, int b, int offset, int length, int srclength,
gokhlayeh@9257 566 + int pages)
gokhlayeh@9257 567 +{
gokhlayeh@9257 568 + struct squashfs_lzma *stream = msblk->stream;
gokhlayeh@9257 569 + void *buff = stream->input;
gokhlayeh@9257 570 + int avail, i, bytes = length, res;
gokhlayeh@9257 571 +
gokhlayeh@9257 572 + mutex_lock(&lzma_mutex);
gokhlayeh@9257 573 +
gokhlayeh@9257 574 + for (i = 0; i < b; i++) {
gokhlayeh@9257 575 + wait_on_buffer(bh[i]);
gokhlayeh@9257 576 + if (!buffer_uptodate(bh[i]))
gokhlayeh@9257 577 + goto block_release;
gokhlayeh@9257 578 +
gokhlayeh@9257 579 + avail = min(bytes, msblk->devblksize - offset);
gokhlayeh@9257 580 + memcpy(buff, bh[i]->b_data + offset, avail);
gokhlayeh@9257 581 + buff += avail;
gokhlayeh@9257 582 + bytes -= avail;
gokhlayeh@9257 583 + offset = 0;
gokhlayeh@9257 584 + put_bh(bh[i]);
gokhlayeh@9257 585 + }
gokhlayeh@9257 586 +
gokhlayeh@9257 587 + lzma_error = 0;
gokhlayeh@9257 588 + res = unlzma(stream->input, length, NULL, NULL, stream->output, NULL,
gokhlayeh@9257 589 + error);
gokhlayeh@9257 590 + if (res || lzma_error)
gokhlayeh@9257 591 + goto failed;
gokhlayeh@9257 592 +
gokhlayeh@9257 593 + /* uncompressed size is stored in the LZMA header (5 byte offset) */
gokhlayeh@9257 594 + res = bytes = get_unaligned_le32(stream->input + 5);
gokhlayeh@9257 595 + for (i = 0, buff = stream->output; bytes && i < pages; i++) {
gokhlayeh@9257 596 + avail = min_t(int, bytes, PAGE_CACHE_SIZE);
gokhlayeh@9257 597 + memcpy(buffer[i], buff, avail);
gokhlayeh@9257 598 + buff += avail;
gokhlayeh@9257 599 + bytes -= avail;
gokhlayeh@9257 600 + }
gokhlayeh@9257 601 + if (bytes)
gokhlayeh@9257 602 + goto failed;
gokhlayeh@9257 603 +
gokhlayeh@9257 604 + mutex_unlock(&lzma_mutex);
gokhlayeh@9257 605 + return res;
gokhlayeh@9257 606 +
gokhlayeh@9257 607 +block_release:
gokhlayeh@9257 608 + for (; i < b; i++)
gokhlayeh@9257 609 + put_bh(bh[i]);
gokhlayeh@9257 610 +
gokhlayeh@9257 611 +failed:
gokhlayeh@9257 612 + mutex_unlock(&lzma_mutex);
gokhlayeh@9257 613 +
gokhlayeh@9257 614 + ERROR("lzma decompression failed, data probably corrupt\n");
gokhlayeh@9257 615 + return -EIO;
gokhlayeh@9257 616 +}
gokhlayeh@9257 617 +
gokhlayeh@9257 618 +const struct squashfs_decompressor squashfs_lzma_comp_ops = {
gokhlayeh@9257 619 + .init = lzma_init,
gokhlayeh@9257 620 + .free = lzma_free,
gokhlayeh@9257 621 + .decompress = lzma_uncompress,
gokhlayeh@9257 622 + .id = LZMA_COMPRESSION,
gokhlayeh@9257 623 + .name = "lzma",
gokhlayeh@9257 624 + .supported = 1
gokhlayeh@9257 625 +};
gokhlayeh@9257 626 +
gokhlayeh@9257 627
gokhlayeh@9257 628 --- linux-2.6.34/fs/squashfs/squashfs.h
gokhlayeh@9257 629 +++ linux-2.6.34/fs/squashfs/squashfs.h
gokhlayeh@9257 630 @@ -94,3 +94,6 @@
gokhlayeh@9257 631
gokhlayeh@9257 632 /* zlib_wrapper.c */
gokhlayeh@9257 633 extern const struct squashfs_decompressor squashfs_zlib_comp_ops;
gokhlayeh@9257 634 +
gokhlayeh@9257 635 +/* lzma wrapper.c */
gokhlayeh@9257 636 +extern const struct squashfs_decompressor squashfs_lzma_comp_ops;
gokhlayeh@9257 637
gokhlayeh@9257 638 --- linux-2.6.34/lib/Makefile
gokhlayeh@9257 639 +++ linux-2.6.34/lib/Makefile
gokhlayeh@9257 640 @@ -69,7 +69,7 @@ obj-$(CONFIG_LZO_DECOMPRESS) += lzo/
gokhlayeh@9257 641
gokhlayeh@9257 642 lib-$(CONFIG_DECOMPRESS_GZIP) += decompress_inflate.o
gokhlayeh@9257 643 lib-$(CONFIG_DECOMPRESS_BZIP2) += decompress_bunzip2.o
gokhlayeh@9257 644 -lib-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
gokhlayeh@9257 645 +obj-$(CONFIG_DECOMPRESS_LZMA) += decompress_unlzma.o
gokhlayeh@9257 646 lib-$(CONFIG_DECOMPRESS_LZO) += decompress_unlzo.o
gokhlayeh@9257 647
gokhlayeh@9257 648 obj-$(CONFIG_TEXTSEARCH) += textsearch.o
gokhlayeh@9257 649