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