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