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