update brcm-2.4 to 2.4.35.4, integrate new broadcom system code, update broadcom...
[openwrt/svn-archive/archive.git] / target / linux / generic-2.4 / patches / 002-squashfs_lzma.patch
1 Index: linux-2.4.35.4/fs/squashfs/inode.c
2 ===================================================================
3 --- linux-2.4.35.4.orig/fs/squashfs/inode.c 2007-12-15 05:19:48.647193283 +0100
4 +++ linux-2.4.35.4/fs/squashfs/inode.c 2007-12-15 05:19:49.015214255 +0100
5 @@ -4,6 +4,9 @@
6 * Copyright (c) 2002, 2003, 2004, 2005, 2006
7 * Phillip Lougher <phillip@lougher.org.uk>
8 *
9 + * LZMA decompressor support added by Oleg I. Vdovikin
10 + * Copyright (c) 2005 Oleg I.Vdovikin <oleg@cs.msu.su>
11 + *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2,
15 @@ -21,6 +24,7 @@
16 * inode.c
17 */
18
19 +#define SQUASHFS_LZMA
20 #include <linux/types.h>
21 #include <linux/squashfs_fs.h>
22 #include <linux/module.h>
23 @@ -40,6 +44,20 @@
24
25 #include "squashfs.h"
26
27 +#ifdef SQUASHFS_LZMA
28 +#include "LzmaDecode.h"
29 +
30 +/* default LZMA settings, should be in sync with mksquashfs */
31 +#define LZMA_LC 3
32 +#define LZMA_LP 0
33 +#define LZMA_PB 2
34 +
35 +#define LZMA_WORKSPACE_SIZE ((LZMA_BASE_SIZE + \
36 + (LZMA_LIT_SIZE << (LZMA_LC + LZMA_LP))) * sizeof(CProb))
37 +
38 +#endif
39 +
40 +
41 static struct super_block *squashfs_read_super(struct super_block *, void *, int);
42 static void squashfs_put_super(struct super_block *);
43 static int squashfs_statfs(struct super_block *, struct statfs *);
44 @@ -53,7 +71,11 @@
45 int readahead_blks, char *block_list,
46 unsigned short **block_p, unsigned int *bsize);
47
48 +#ifdef SQUASHFS_LZMA
49 +static unsigned char lzma_workspace[LZMA_WORKSPACE_SIZE];
50 +#else
51 static z_stream stream;
52 +#endif
53
54 static DECLARE_FSTYPE_DEV(squashfs_fs_type, "squashfs", squashfs_read_super);
55
56 @@ -229,6 +251,15 @@
57 if (compressed) {
58 int zlib_err;
59
60 +#ifdef SQUASHFS_LZMA
61 + if ((zlib_err = LzmaDecode(lzma_workspace,
62 + LZMA_WORKSPACE_SIZE, LZMA_LC, LZMA_LP, LZMA_PB,
63 + c_buffer, c_byte, buffer, msblk->read_size, &bytes)) != LZMA_RESULT_OK)
64 + {
65 + ERROR("lzma returned unexpected result 0x%x\n", zlib_err);
66 + bytes = 0;
67 + }
68 +#else
69 stream.next_in = c_buffer;
70 stream.avail_in = c_byte;
71 stream.next_out = buffer;
72 @@ -243,6 +274,7 @@
73 bytes = 0;
74 } else
75 bytes = stream.total_out;
76 +#endif
77
78 up(&msblk->read_data_mutex);
79 }
80 @@ -2004,17 +2036,21 @@
81 printk(KERN_INFO "squashfs: version 3.0 (2006/03/15) "
82 "Phillip Lougher\n");
83
84 +#ifndef SQUASHFS_LZMA
85 if (!(stream.workspace = vmalloc(zlib_inflate_workspacesize()))) {
86 ERROR("Failed to allocate zlib workspace\n");
87 return -ENOMEM;
88 }
89 +#endif
90 return register_filesystem(&squashfs_fs_type);
91 }
92
93
94 static void __exit exit_squashfs_fs(void)
95 {
96 +#ifndef SQUASHFS_LZMA
97 vfree(stream.workspace);
98 +#endif
99 unregister_filesystem(&squashfs_fs_type);
100 }
101
102 Index: linux-2.4.35.4/fs/squashfs/LzmaDecode.c
103 ===================================================================
104 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
105 +++ linux-2.4.35.4/fs/squashfs/LzmaDecode.c 2007-12-15 05:19:49.019214484 +0100
106 @@ -0,0 +1,663 @@
107 +/*
108 + LzmaDecode.c
109 + LZMA Decoder
110 +
111 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
112 + http://www.7-zip.org/
113 +
114 + LZMA SDK is licensed under two licenses:
115 + 1) GNU Lesser General Public License (GNU LGPL)
116 + 2) Common Public License (CPL)
117 + It means that you can select one of these two licenses and
118 + follow rules of that license.
119 +
120 + SPECIAL EXCEPTION:
121 + Igor Pavlov, as the author of this code, expressly permits you to
122 + statically or dynamically link your code (or bind by name) to the
123 + interfaces of this file without subjecting your linked code to the
124 + terms of the CPL or GNU LGPL. Any modifications or additions
125 + to this file, however, are subject to the LGPL or CPL terms.
126 +*/
127 +
128 +#include "LzmaDecode.h"
129 +
130 +#ifndef Byte
131 +#define Byte unsigned char
132 +#endif
133 +
134 +#define kNumTopBits 24
135 +#define kTopValue ((UInt32)1 << kNumTopBits)
136 +
137 +#define kNumBitModelTotalBits 11
138 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
139 +#define kNumMoveBits 5
140 +
141 +typedef struct _CRangeDecoder
142 +{
143 + Byte *Buffer;
144 + Byte *BufferLim;
145 + UInt32 Range;
146 + UInt32 Code;
147 + #ifdef _LZMA_IN_CB
148 + ILzmaInCallback *InCallback;
149 + int Result;
150 + #endif
151 + int ExtraBytes;
152 +} CRangeDecoder;
153 +
154 +Byte RangeDecoderReadByte(CRangeDecoder *rd)
155 +{
156 + if (rd->Buffer == rd->BufferLim)
157 + {
158 + #ifdef _LZMA_IN_CB
159 + UInt32 size;
160 + rd->Result = rd->InCallback->Read(rd->InCallback, &rd->Buffer, &size);
161 + rd->BufferLim = rd->Buffer + size;
162 + if (size == 0)
163 + #endif
164 + {
165 + rd->ExtraBytes = 1;
166 + return 0xFF;
167 + }
168 + }
169 + return (*rd->Buffer++);
170 +}
171 +
172 +/* #define ReadByte (*rd->Buffer++) */
173 +#define ReadByte (RangeDecoderReadByte(rd))
174 +
175 +void RangeDecoderInit(CRangeDecoder *rd,
176 + #ifdef _LZMA_IN_CB
177 + ILzmaInCallback *inCallback
178 + #else
179 + Byte *stream, UInt32 bufferSize
180 + #endif
181 + )
182 +{
183 + int i;
184 + #ifdef _LZMA_IN_CB
185 + rd->InCallback = inCallback;
186 + rd->Buffer = rd->BufferLim = 0;
187 + #else
188 + rd->Buffer = stream;
189 + rd->BufferLim = stream + bufferSize;
190 + #endif
191 + rd->ExtraBytes = 0;
192 + rd->Code = 0;
193 + rd->Range = (0xFFFFFFFF);
194 + for(i = 0; i < 5; i++)
195 + rd->Code = (rd->Code << 8) | ReadByte;
196 +}
197 +
198 +#define RC_INIT_VAR UInt32 range = rd->Range; UInt32 code = rd->Code;
199 +#define RC_FLUSH_VAR rd->Range = range; rd->Code = code;
200 +#define RC_NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | ReadByte; }
201 +
202 +UInt32 RangeDecoderDecodeDirectBits(CRangeDecoder *rd, int numTotalBits)
203 +{
204 + RC_INIT_VAR
205 + UInt32 result = 0;
206 + int i;
207 + for (i = numTotalBits; i > 0; i--)
208 + {
209 + /* UInt32 t; */
210 + range >>= 1;
211 +
212 + result <<= 1;
213 + if (code >= range)
214 + {
215 + code -= range;
216 + result |= 1;
217 + }
218 + /*
219 + t = (code - range) >> 31;
220 + t &= 1;
221 + code -= range & (t - 1);
222 + result = (result + result) | (1 - t);
223 + */
224 + RC_NORMALIZE
225 + }
226 + RC_FLUSH_VAR
227 + return result;
228 +}
229 +
230 +int RangeDecoderBitDecode(CProb *prob, CRangeDecoder *rd)
231 +{
232 + UInt32 bound = (rd->Range >> kNumBitModelTotalBits) * *prob;
233 + if (rd->Code < bound)
234 + {
235 + rd->Range = bound;
236 + *prob += (kBitModelTotal - *prob) >> kNumMoveBits;
237 + if (rd->Range < kTopValue)
238 + {
239 + rd->Code = (rd->Code << 8) | ReadByte;
240 + rd->Range <<= 8;
241 + }
242 + return 0;
243 + }
244 + else
245 + {
246 + rd->Range -= bound;
247 + rd->Code -= bound;
248 + *prob -= (*prob) >> kNumMoveBits;
249 + if (rd->Range < kTopValue)
250 + {
251 + rd->Code = (rd->Code << 8) | ReadByte;
252 + rd->Range <<= 8;
253 + }
254 + return 1;
255 + }
256 +}
257 +
258 +#define RC_GET_BIT2(prob, mi, A0, A1) \
259 + UInt32 bound = (range >> kNumBitModelTotalBits) * *prob; \
260 + if (code < bound) \
261 + { A0; range = bound; *prob += (kBitModelTotal - *prob) >> kNumMoveBits; mi <<= 1; } \
262 + else \
263 + { A1; range -= bound; code -= bound; *prob -= (*prob) >> kNumMoveBits; mi = (mi + mi) + 1; } \
264 + RC_NORMALIZE
265 +
266 +#define RC_GET_BIT(prob, mi) RC_GET_BIT2(prob, mi, ; , ;)
267 +
268 +int RangeDecoderBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
269 +{
270 + int mi = 1;
271 + int i;
272 + #ifdef _LZMA_LOC_OPT
273 + RC_INIT_VAR
274 + #endif
275 + for(i = numLevels; i > 0; i--)
276 + {
277 + #ifdef _LZMA_LOC_OPT
278 + CProb *prob = probs + mi;
279 + RC_GET_BIT(prob, mi)
280 + #else
281 + mi = (mi + mi) + RangeDecoderBitDecode(probs + mi, rd);
282 + #endif
283 + }
284 + #ifdef _LZMA_LOC_OPT
285 + RC_FLUSH_VAR
286 + #endif
287 + return mi - (1 << numLevels);
288 +}
289 +
290 +int RangeDecoderReverseBitTreeDecode(CProb *probs, int numLevels, CRangeDecoder *rd)
291 +{
292 + int mi = 1;
293 + int i;
294 + int symbol = 0;
295 + #ifdef _LZMA_LOC_OPT
296 + RC_INIT_VAR
297 + #endif
298 + for(i = 0; i < numLevels; i++)
299 + {
300 + #ifdef _LZMA_LOC_OPT
301 + CProb *prob = probs + mi;
302 + RC_GET_BIT2(prob, mi, ; , symbol |= (1 << i))
303 + #else
304 + int bit = RangeDecoderBitDecode(probs + mi, rd);
305 + mi = mi + mi + bit;
306 + symbol |= (bit << i);
307 + #endif
308 + }
309 + #ifdef _LZMA_LOC_OPT
310 + RC_FLUSH_VAR
311 + #endif
312 + return symbol;
313 +}
314 +
315 +Byte LzmaLiteralDecode(CProb *probs, CRangeDecoder *rd)
316 +{
317 + int symbol = 1;
318 + #ifdef _LZMA_LOC_OPT
319 + RC_INIT_VAR
320 + #endif
321 + do
322 + {
323 + #ifdef _LZMA_LOC_OPT
324 + CProb *prob = probs + symbol;
325 + RC_GET_BIT(prob, symbol)
326 + #else
327 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
328 + #endif
329 + }
330 + while (symbol < 0x100);
331 + #ifdef _LZMA_LOC_OPT
332 + RC_FLUSH_VAR
333 + #endif
334 + return symbol;
335 +}
336 +
337 +Byte LzmaLiteralDecodeMatch(CProb *probs, CRangeDecoder *rd, Byte matchByte)
338 +{
339 + int symbol = 1;
340 + #ifdef _LZMA_LOC_OPT
341 + RC_INIT_VAR
342 + #endif
343 + do
344 + {
345 + int bit;
346 + int matchBit = (matchByte >> 7) & 1;
347 + matchByte <<= 1;
348 + #ifdef _LZMA_LOC_OPT
349 + {
350 + CProb *prob = probs + ((1 + matchBit) << 8) + symbol;
351 + RC_GET_BIT2(prob, symbol, bit = 0, bit = 1)
352 + }
353 + #else
354 + bit = RangeDecoderBitDecode(probs + ((1 + matchBit) << 8) + symbol, rd);
355 + symbol = (symbol << 1) | bit;
356 + #endif
357 + if (matchBit != bit)
358 + {
359 + while (symbol < 0x100)
360 + {
361 + #ifdef _LZMA_LOC_OPT
362 + CProb *prob = probs + symbol;
363 + RC_GET_BIT(prob, symbol)
364 + #else
365 + symbol = (symbol + symbol) | RangeDecoderBitDecode(probs + symbol, rd);
366 + #endif
367 + }
368 + break;
369 + }
370 + }
371 + while (symbol < 0x100);
372 + #ifdef _LZMA_LOC_OPT
373 + RC_FLUSH_VAR
374 + #endif
375 + return symbol;
376 +}
377 +
378 +#define kNumPosBitsMax 4
379 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
380 +
381 +#define kLenNumLowBits 3
382 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
383 +#define kLenNumMidBits 3
384 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
385 +#define kLenNumHighBits 8
386 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
387 +
388 +#define LenChoice 0
389 +#define LenChoice2 (LenChoice + 1)
390 +#define LenLow (LenChoice2 + 1)
391 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
392 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
393 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
394 +
395 +int LzmaLenDecode(CProb *p, CRangeDecoder *rd, int posState)
396 +{
397 + if(RangeDecoderBitDecode(p + LenChoice, rd) == 0)
398 + return RangeDecoderBitTreeDecode(p + LenLow +
399 + (posState << kLenNumLowBits), kLenNumLowBits, rd);
400 + if(RangeDecoderBitDecode(p + LenChoice2, rd) == 0)
401 + return kLenNumLowSymbols + RangeDecoderBitTreeDecode(p + LenMid +
402 + (posState << kLenNumMidBits), kLenNumMidBits, rd);
403 + return kLenNumLowSymbols + kLenNumMidSymbols +
404 + RangeDecoderBitTreeDecode(p + LenHigh, kLenNumHighBits, rd);
405 +}
406 +
407 +#define kNumStates 12
408 +
409 +#define kStartPosModelIndex 4
410 +#define kEndPosModelIndex 14
411 +#define kNumFullDistances (1 << (kEndPosModelIndex >> 1))
412 +
413 +#define kNumPosSlotBits 6
414 +#define kNumLenToPosStates 4
415 +
416 +#define kNumAlignBits 4
417 +#define kAlignTableSize (1 << kNumAlignBits)
418 +
419 +#define kMatchMinLen 2
420 +
421 +#define IsMatch 0
422 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
423 +#define IsRepG0 (IsRep + kNumStates)
424 +#define IsRepG1 (IsRepG0 + kNumStates)
425 +#define IsRepG2 (IsRepG1 + kNumStates)
426 +#define IsRep0Long (IsRepG2 + kNumStates)
427 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
428 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
429 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
430 +#define LenCoder (Align + kAlignTableSize)
431 +#define RepLenCoder (LenCoder + kNumLenProbs)
432 +#define Literal (RepLenCoder + kNumLenProbs)
433 +
434 +#if Literal != LZMA_BASE_SIZE
435 +StopCompilingDueBUG
436 +#endif
437 +
438 +#ifdef _LZMA_OUT_READ
439 +
440 +typedef struct _LzmaVarState
441 +{
442 + CRangeDecoder RangeDecoder;
443 + Byte *Dictionary;
444 + UInt32 DictionarySize;
445 + UInt32 DictionaryPos;
446 + UInt32 GlobalPos;
447 + UInt32 Reps[4];
448 + int lc;
449 + int lp;
450 + int pb;
451 + int State;
452 + int PreviousIsMatch;
453 + int RemainLen;
454 +} LzmaVarState;
455 +
456 +int LzmaDecoderInit(
457 + unsigned char *buffer, UInt32 bufferSize,
458 + int lc, int lp, int pb,
459 + unsigned char *dictionary, UInt32 dictionarySize,
460 + #ifdef _LZMA_IN_CB
461 + ILzmaInCallback *inCallback
462 + #else
463 + unsigned char *inStream, UInt32 inSize
464 + #endif
465 + )
466 +{
467 + LzmaVarState *vs = (LzmaVarState *)buffer;
468 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
469 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
470 + UInt32 i;
471 + if (bufferSize < numProbs * sizeof(CProb) + sizeof(LzmaVarState))
472 + return LZMA_RESULT_NOT_ENOUGH_MEM;
473 + vs->Dictionary = dictionary;
474 + vs->DictionarySize = dictionarySize;
475 + vs->DictionaryPos = 0;
476 + vs->GlobalPos = 0;
477 + vs->Reps[0] = vs->Reps[1] = vs->Reps[2] = vs->Reps[3] = 1;
478 + vs->lc = lc;
479 + vs->lp = lp;
480 + vs->pb = pb;
481 + vs->State = 0;
482 + vs->PreviousIsMatch = 0;
483 + vs->RemainLen = 0;
484 + dictionary[dictionarySize - 1] = 0;
485 + for (i = 0; i < numProbs; i++)
486 + p[i] = kBitModelTotal >> 1;
487 + RangeDecoderInit(&vs->RangeDecoder,
488 + #ifdef _LZMA_IN_CB
489 + inCallback
490 + #else
491 + inStream, inSize
492 + #endif
493 + );
494 + return LZMA_RESULT_OK;
495 +}
496 +
497 +int LzmaDecode(unsigned char *buffer,
498 + unsigned char *outStream, UInt32 outSize,
499 + UInt32 *outSizeProcessed)
500 +{
501 + LzmaVarState *vs = (LzmaVarState *)buffer;
502 + CProb *p = (CProb *)(buffer + sizeof(LzmaVarState));
503 + CRangeDecoder rd = vs->RangeDecoder;
504 + int state = vs->State;
505 + int previousIsMatch = vs->PreviousIsMatch;
506 + Byte previousByte;
507 + UInt32 rep0 = vs->Reps[0], rep1 = vs->Reps[1], rep2 = vs->Reps[2], rep3 = vs->Reps[3];
508 + UInt32 nowPos = 0;
509 + UInt32 posStateMask = (1 << (vs->pb)) - 1;
510 + UInt32 literalPosMask = (1 << (vs->lp)) - 1;
511 + int lc = vs->lc;
512 + int len = vs->RemainLen;
513 + UInt32 globalPos = vs->GlobalPos;
514 +
515 + Byte *dictionary = vs->Dictionary;
516 + UInt32 dictionarySize = vs->DictionarySize;
517 + UInt32 dictionaryPos = vs->DictionaryPos;
518 +
519 + if (len == -1)
520 + {
521 + *outSizeProcessed = 0;
522 + return LZMA_RESULT_OK;
523 + }
524 +
525 + while(len > 0 && nowPos < outSize)
526 + {
527 + UInt32 pos = dictionaryPos - rep0;
528 + if (pos >= dictionarySize)
529 + pos += dictionarySize;
530 + outStream[nowPos++] = dictionary[dictionaryPos] = dictionary[pos];
531 + if (++dictionaryPos == dictionarySize)
532 + dictionaryPos = 0;
533 + len--;
534 + }
535 + if (dictionaryPos == 0)
536 + previousByte = dictionary[dictionarySize - 1];
537 + else
538 + previousByte = dictionary[dictionaryPos - 1];
539 +#else
540 +
541 +int LzmaDecode(
542 + Byte *buffer, UInt32 bufferSize,
543 + int lc, int lp, int pb,
544 + #ifdef _LZMA_IN_CB
545 + ILzmaInCallback *inCallback,
546 + #else
547 + unsigned char *inStream, UInt32 inSize,
548 + #endif
549 + unsigned char *outStream, UInt32 outSize,
550 + UInt32 *outSizeProcessed)
551 +{
552 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (lc + lp));
553 + CProb *p = (CProb *)buffer;
554 + CRangeDecoder rd;
555 + UInt32 i;
556 + int state = 0;
557 + int previousIsMatch = 0;
558 + Byte previousByte = 0;
559 + UInt32 rep0 = 1, rep1 = 1, rep2 = 1, rep3 = 1;
560 + UInt32 nowPos = 0;
561 + UInt32 posStateMask = (1 << pb) - 1;
562 + UInt32 literalPosMask = (1 << lp) - 1;
563 + int len = 0;
564 + if (bufferSize < numProbs * sizeof(CProb))
565 + return LZMA_RESULT_NOT_ENOUGH_MEM;
566 + for (i = 0; i < numProbs; i++)
567 + p[i] = kBitModelTotal >> 1;
568 + RangeDecoderInit(&rd,
569 + #ifdef _LZMA_IN_CB
570 + inCallback
571 + #else
572 + inStream, inSize
573 + #endif
574 + );
575 +#endif
576 +
577 + *outSizeProcessed = 0;
578 + while(nowPos < outSize)
579 + {
580 + int posState = (int)(
581 + (nowPos
582 + #ifdef _LZMA_OUT_READ
583 + + globalPos
584 + #endif
585 + )
586 + & posStateMask);
587 + #ifdef _LZMA_IN_CB
588 + if (rd.Result != LZMA_RESULT_OK)
589 + return rd.Result;
590 + #endif
591 + if (rd.ExtraBytes != 0)
592 + return LZMA_RESULT_DATA_ERROR;
593 + if (RangeDecoderBitDecode(p + IsMatch + (state << kNumPosBitsMax) + posState, &rd) == 0)
594 + {
595 + CProb *probs = p + Literal + (LZMA_LIT_SIZE *
596 + (((
597 + (nowPos
598 + #ifdef _LZMA_OUT_READ
599 + + globalPos
600 + #endif
601 + )
602 + & literalPosMask) << lc) + (previousByte >> (8 - lc))));
603 +
604 + if (state < 4) state = 0;
605 + else if (state < 10) state -= 3;
606 + else state -= 6;
607 + if (previousIsMatch)
608 + {
609 + Byte matchByte;
610 + #ifdef _LZMA_OUT_READ
611 + UInt32 pos = dictionaryPos - rep0;
612 + if (pos >= dictionarySize)
613 + pos += dictionarySize;
614 + matchByte = dictionary[pos];
615 + #else
616 + matchByte = outStream[nowPos - rep0];
617 + #endif
618 + previousByte = LzmaLiteralDecodeMatch(probs, &rd, matchByte);
619 + previousIsMatch = 0;
620 + }
621 + else
622 + previousByte = LzmaLiteralDecode(probs, &rd);
623 + outStream[nowPos++] = previousByte;
624 + #ifdef _LZMA_OUT_READ
625 + dictionary[dictionaryPos] = previousByte;
626 + if (++dictionaryPos == dictionarySize)
627 + dictionaryPos = 0;
628 + #endif
629 + }
630 + else
631 + {
632 + previousIsMatch = 1;
633 + if (RangeDecoderBitDecode(p + IsRep + state, &rd) == 1)
634 + {
635 + if (RangeDecoderBitDecode(p + IsRepG0 + state, &rd) == 0)
636 + {
637 + if (RangeDecoderBitDecode(p + IsRep0Long + (state << kNumPosBitsMax) + posState, &rd) == 0)
638 + {
639 + #ifdef _LZMA_OUT_READ
640 + UInt32 pos;
641 + #endif
642 + if (
643 + (nowPos
644 + #ifdef _LZMA_OUT_READ
645 + + globalPos
646 + #endif
647 + )
648 + == 0)
649 + return LZMA_RESULT_DATA_ERROR;
650 + state = state < 7 ? 9 : 11;
651 + #ifdef _LZMA_OUT_READ
652 + pos = dictionaryPos - rep0;
653 + if (pos >= dictionarySize)
654 + pos += dictionarySize;
655 + previousByte = dictionary[pos];
656 + dictionary[dictionaryPos] = previousByte;
657 + if (++dictionaryPos == dictionarySize)
658 + dictionaryPos = 0;
659 + #else
660 + previousByte = outStream[nowPos - rep0];
661 + #endif
662 + outStream[nowPos++] = previousByte;
663 + continue;
664 + }
665 + }
666 + else
667 + {
668 + UInt32 distance;
669 + if(RangeDecoderBitDecode(p + IsRepG1 + state, &rd) == 0)
670 + distance = rep1;
671 + else
672 + {
673 + if(RangeDecoderBitDecode(p + IsRepG2 + state, &rd) == 0)
674 + distance = rep2;
675 + else
676 + {
677 + distance = rep3;
678 + rep3 = rep2;
679 + }
680 + rep2 = rep1;
681 + }
682 + rep1 = rep0;
683 + rep0 = distance;
684 + }
685 + len = LzmaLenDecode(p + RepLenCoder, &rd, posState);
686 + state = state < 7 ? 8 : 11;
687 + }
688 + else
689 + {
690 + int posSlot;
691 + rep3 = rep2;
692 + rep2 = rep1;
693 + rep1 = rep0;
694 + state = state < 7 ? 7 : 10;
695 + len = LzmaLenDecode(p + LenCoder, &rd, posState);
696 + posSlot = RangeDecoderBitTreeDecode(p + PosSlot +
697 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
698 + kNumPosSlotBits), kNumPosSlotBits, &rd);
699 + if (posSlot >= kStartPosModelIndex)
700 + {
701 + int numDirectBits = ((posSlot >> 1) - 1);
702 + rep0 = ((2 | ((UInt32)posSlot & 1)) << numDirectBits);
703 + if (posSlot < kEndPosModelIndex)
704 + {
705 + rep0 += RangeDecoderReverseBitTreeDecode(
706 + p + SpecPos + rep0 - posSlot - 1, numDirectBits, &rd);
707 + }
708 + else
709 + {
710 + rep0 += RangeDecoderDecodeDirectBits(&rd,
711 + numDirectBits - kNumAlignBits) << kNumAlignBits;
712 + rep0 += RangeDecoderReverseBitTreeDecode(p + Align, kNumAlignBits, &rd);
713 + }
714 + }
715 + else
716 + rep0 = posSlot;
717 + rep0++;
718 + }
719 + if (rep0 == (UInt32)(0))
720 + {
721 + /* it's for stream version */
722 + len = -1;
723 + break;
724 + }
725 + if (rep0 > nowPos
726 + #ifdef _LZMA_OUT_READ
727 + + globalPos
728 + #endif
729 + )
730 + {
731 + return LZMA_RESULT_DATA_ERROR;
732 + }
733 + len += kMatchMinLen;
734 + do
735 + {
736 + #ifdef _LZMA_OUT_READ
737 + UInt32 pos = dictionaryPos - rep0;
738 + if (pos >= dictionarySize)
739 + pos += dictionarySize;
740 + previousByte = dictionary[pos];
741 + dictionary[dictionaryPos] = previousByte;
742 + if (++dictionaryPos == dictionarySize)
743 + dictionaryPos = 0;
744 + #else
745 + previousByte = outStream[nowPos - rep0];
746 + #endif
747 + outStream[nowPos++] = previousByte;
748 + len--;
749 + }
750 + while(len > 0 && nowPos < outSize);
751 + }
752 + }
753 +
754 + #ifdef _LZMA_OUT_READ
755 + vs->RangeDecoder = rd;
756 + vs->DictionaryPos = dictionaryPos;
757 + vs->GlobalPos = globalPos + nowPos;
758 + vs->Reps[0] = rep0;
759 + vs->Reps[1] = rep1;
760 + vs->Reps[2] = rep2;
761 + vs->Reps[3] = rep3;
762 + vs->State = state;
763 + vs->PreviousIsMatch = previousIsMatch;
764 + vs->RemainLen = len;
765 + #endif
766 +
767 + *outSizeProcessed = nowPos;
768 + return LZMA_RESULT_OK;
769 +}
770 Index: linux-2.4.35.4/fs/squashfs/LzmaDecode.h
771 ===================================================================
772 --- /dev/null 1970-01-01 00:00:00.000000000 +0000
773 +++ linux-2.4.35.4/fs/squashfs/LzmaDecode.h 2007-12-15 05:19:49.027214939 +0100
774 @@ -0,0 +1,100 @@
775 +/*
776 + LzmaDecode.h
777 + LZMA Decoder interface
778 +
779 + LZMA SDK 4.05 Copyright (c) 1999-2004 Igor Pavlov (2004-08-25)
780 + http://www.7-zip.org/
781 +
782 + LZMA SDK is licensed under two licenses:
783 + 1) GNU Lesser General Public License (GNU LGPL)
784 + 2) Common Public License (CPL)
785 + It means that you can select one of these two licenses and
786 + follow rules of that license.
787 +
788 + SPECIAL EXCEPTION:
789 + Igor Pavlov, as the author of this code, expressly permits you to
790 + statically or dynamically link your code (or bind by name) to the
791 + interfaces of this file without subjecting your linked code to the
792 + terms of the CPL or GNU LGPL. Any modifications or additions
793 + to this file, however, are subject to the LGPL or CPL terms.
794 +*/
795 +
796 +#ifndef __LZMADECODE_H
797 +#define __LZMADECODE_H
798 +
799 +/* #define _LZMA_IN_CB */
800 +/* Use callback for input data */
801 +
802 +/* #define _LZMA_OUT_READ */
803 +/* Use read function for output data */
804 +
805 +/* #define _LZMA_PROB32 */
806 +/* It can increase speed on some 32-bit CPUs,
807 + but memory usage will be doubled in that case */
808 +
809 +/* #define _LZMA_LOC_OPT */
810 +/* Enable local speed optimizations inside code */
811 +
812 +#ifndef UInt32
813 +#ifdef _LZMA_UINT32_IS_ULONG
814 +#define UInt32 unsigned long
815 +#else
816 +#define UInt32 unsigned int
817 +#endif
818 +#endif
819 +
820 +#ifdef _LZMA_PROB32
821 +#define CProb UInt32
822 +#else
823 +#define CProb unsigned short
824 +#endif
825 +
826 +#define LZMA_RESULT_OK 0
827 +#define LZMA_RESULT_DATA_ERROR 1
828 +#define LZMA_RESULT_NOT_ENOUGH_MEM 2
829 +
830 +#ifdef _LZMA_IN_CB
831 +typedef struct _ILzmaInCallback
832 +{
833 + int (*Read)(void *object, unsigned char **buffer, UInt32 *bufferSize);
834 +} ILzmaInCallback;
835 +#endif
836 +
837 +#define LZMA_BASE_SIZE 1846
838 +#define LZMA_LIT_SIZE 768
839 +
840 +/*
841 +bufferSize = (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb)
842 +bufferSize += 100 in case of _LZMA_OUT_READ
843 +by default CProb is unsigned short,
844 +but if specify _LZMA_PROB_32, CProb will be UInt32(unsigned int)
845 +*/
846 +
847 +#ifdef _LZMA_OUT_READ
848 +int LzmaDecoderInit(
849 + unsigned char *buffer, UInt32 bufferSize,
850 + int lc, int lp, int pb,
851 + unsigned char *dictionary, UInt32 dictionarySize,
852 + #ifdef _LZMA_IN_CB
853 + ILzmaInCallback *inCallback
854 + #else
855 + unsigned char *inStream, UInt32 inSize
856 + #endif
857 +);
858 +#endif
859 +
860 +int LzmaDecode(
861 + unsigned char *buffer,
862 + #ifndef _LZMA_OUT_READ
863 + UInt32 bufferSize,
864 + int lc, int lp, int pb,
865 + #ifdef _LZMA_IN_CB
866 + ILzmaInCallback *inCallback,
867 + #else
868 + unsigned char *inStream, UInt32 inSize,
869 + #endif
870 + #endif
871 + unsigned char *outStream, UInt32 outSize,
872 + UInt32 *outSizeProcessed);
873 +
874 +#endif
875 Index: linux-2.4.35.4/fs/squashfs/Makefile
876 ===================================================================
877 --- linux-2.4.35.4.orig/fs/squashfs/Makefile 2007-12-15 05:19:48.651193513 +0100
878 +++ linux-2.4.35.4/fs/squashfs/Makefile 2007-12-15 05:19:49.031215169 +0100
879 @@ -4,7 +4,7 @@
880
881 O_TARGET := squashfs.o
882
883 -obj-y := inode.o squashfs2_0.o
884 +obj-y := inode.o squashfs2_0.o LzmaDecode.o
885
886 obj-m := $(O_TARGET)
887