wok-current view grub4dos/stuff/lzma.diff @ rev 13737

xscavenger, xdigger: add menu entry
author Pascal Bellard <pascal.bellard@slitaz.org>
date Wed Dec 26 11:05:26 2012 +0100 (2012-12-26)
parents
children
line source
1 From http://code.google.com/p/grub4dos-chenall/issues/detail?id=6
3 diff -Naur ../grub4dos-chenall-r63/stage2/common.c ./stage2/common.c
4 --- grub4dos-chenall-r63/stage2/common.c 2010-11-19 12:41:03.196955000 +0700
5 +++ grub4dos/stage2/common.c 2010-11-23 21:28:26.509102100 +0700
6 @@ -143,6 +143,7 @@
7 [ERR_WRITE_GZIP_FILE] = "Attempt to write a gzip file",
8 [ERR_FUNC_CALL] = "Invalid function call",
9 // [ERR_WRITE_TO_NON_MEM_DRIVE] = "Only RAM drives can be written when running in a script",
10 + [ERR_NOT_ENOUGH_MEMORY] = "Not enough memory",
12 };
14 diff -Naur ../grub4dos-chenall-r63/stage2/dec_lzma.c ./stage2/dec_lzma.c
15 --- grub4dos-chenall-r63/stage2/dec_lzma.c 1970-01-01 07:00:00.000000000 +0700
16 +++ grub4dos/stage2/dec_lzma.c 2010-11-28 22:12:06.452791800 +0700
17 @@ -0,0 +1,1384 @@
18 +/*
19 + * GRUB4DOS -- GRand Unified Bootloader
20 + * Copyright (C) 1999 Free Software Foundation, Inc.
21 + *
22 + * This program is free software; you can redistribute it and/or modify
23 + * it under the terms of the GNU General Public License as published by
24 + * the Free Software Foundation; either version 2 of the License, or
25 + * (at your option) any later version.
26 + *
27 + * This program is distributed in the hope that it will be useful,
28 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
29 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 + * GNU General Public License for more details.
31 + *
32 + * You should have received a copy of the GNU General Public License
33 + * along with this program; if not, write to the Free Software
34 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
35 + */
36 +
37 +/*
38 + * Most of this file is derives from LZMA SDK 9.12 beta
39 + * files Types.h, LzmaDec.h, LzmaDec.c by Igor Pavlov
40 + * It has been modified for used in GRUB4DOS.
41 + */
42 +
43 +#ifndef NO_DECOMPRESSION
44 +
45 +#include "shared.h"
46 +#include "decomp.h"
47 +
48 +/* Types.h -- Basic types
49 +2010-03-11 : Igor Pavlov : Public domain */
50 +
51 +#define SZ_OK 0
52 +
53 +#define SZ_ERROR_DATA 1
54 +#define SZ_ERROR_MEM 2
55 +#define SZ_ERROR_CRC 3
56 +#define SZ_ERROR_UNSUPPORTED 4
57 +#define SZ_ERROR_PARAM 5
58 +#define SZ_ERROR_INPUT_EOF 6
59 +#define SZ_ERROR_OUTPUT_EOF 7
60 +#define SZ_ERROR_READ 8
61 +#define SZ_ERROR_WRITE 9
62 +#define SZ_ERROR_PROGRESS 10
63 +#define SZ_ERROR_FAIL 11
64 +#define SZ_ERROR_THREAD 12
65 +
66 +#define SZ_ERROR_ARCHIVE 16
67 +#define SZ_ERROR_NO_ARCHIVE 17
68 +
69 +typedef int SRes;
70 +typedef int WRes;
71 +
72 +#ifndef RINOK
73 +#define RINOK(x) { int __result__ = (x); if (__result__ != 0) return __result__; }
74 +#endif
75 +
76 +typedef unsigned char Byte;
77 +typedef short Int16;
78 +typedef unsigned short UInt16;
79 +
80 +typedef int Int32;
81 +typedef unsigned int UInt32;
82 +
83 +typedef long long int Int64;
84 +typedef unsigned long long int UInt64;
85 +
86 +typedef UInt32 SizeT;
87 +typedef int ptrdiff_t;
88 +
89 +typedef int Bool;
90 +#define True 1
91 +#define False 0
92 +
93 +#define MY_STD_CALL
94 +#define MY_CDECL
95 +#define MY_FAST_CALL
96 +
97 +typedef struct
98 +{
99 + void *(*Alloc)(void *p, SizeT size);
100 + void (*Free)(void *p, void *address); /* address can be 0 */
101 +} ISzAlloc;
102 +
103 +#define IAlloc_Alloc(p, size) (p)->Alloc((p), size)
104 +#define IAlloc_Free(p, a) (p)->Free((p), a)
105 +
106 +/* -------------------------------------------------------------------------- */
107 +
108 +/* LzmaDec.h -- LZMA Decoder
109 +2009-02-07 : Igor Pavlov : Public domain */
110 +
111 +/* #define _LZMA_PROB32 */
112 +/* _LZMA_PROB32 can increase the speed on some CPUs,
113 + but memory usage for CLzmaDec::probs will be doubled in that case */
114 +
115 +#ifdef _LZMA_PROB32
116 +#define UIntLzmaProb UInt32
117 +#else
118 +#define UIntLzmaProb UInt16
119 +#endif
120 +
121 +
122 +/* ---------- LZMA Properties ---------- */
123 +
124 +#define LZMA_PROPS_SIZE 5
125 +
126 +typedef struct _CLzmaProps
127 +{
128 + unsigned lc, lp, pb;
129 + UInt32 dicSize;
130 +} CLzmaProps;
131 +
132 +/* LzmaProps_Decode - decodes properties
133 +Returns:
134 + SZ_OK
135 + SZ_ERROR_UNSUPPORTED - Unsupported properties
136 +*/
137 +
138 +SRes LzmaProps_Decode(CLzmaProps *p, const Byte *data, unsigned size);
139 +
140 +
141 +/* ---------- LZMA Decoder state ---------- */
142 +
143 +/* LZMA_REQUIRED_INPUT_MAX = number of required input bytes for worst case.
144 + Num bits = log2((2^11 / 31) ^ 22) + 26 < 134 + 26 = 160; */
145 +
146 +#define LZMA_REQUIRED_INPUT_MAX 20
147 +
148 +typedef struct
149 +{
150 + CLzmaProps prop;
151 + UIntLzmaProb *probs;
152 + const Byte *buf;
153 + UInt32 range, code;
154 + Byte *dic;
155 + UInt32 dicPos;
156 + UInt32 dicBufSize;
157 + Byte *inp;
158 + UInt32 inpPos, inpSize;
159 + UInt32 inpBufSize;
160 + UInt32 processedPos;
161 + UInt32 checkDicSize;
162 + unsigned state;
163 + UInt32 reps[4];
164 + unsigned remainLen;
165 + int needFlush;
166 + int needInitState;
167 + UInt32 numProbs;
168 + unsigned tempBufSize;
169 + Byte tempBuf[LZMA_REQUIRED_INPUT_MAX];
170 + UInt64 inpFilePos;
171 + UInt64 dicFilePos;
172 + struct {
173 + UInt64 fmax, fpos;
174 + } filec, fileu;
175 +} CLzmaDec;
176 +
177 +#define LzmaDec_Construct(p) { (p)->dic = 0; (p)->probs = 0; }
178 +
179 +void LzmaDec_Init(CLzmaDec *p);
180 +
181 +/* There are two types of LZMA streams:
182 + 0) Stream with end mark. That end mark adds about 6 bytes to compressed size.
183 + 1) Stream without end mark. You must know exact uncompressed size to decompress such stream. */
184 +
185 +typedef enum
186 +{
187 + LZMA_FINISH_ANY, /* finish at any point */
188 + LZMA_FINISH_END /* block must be finished at the end */
189 +} ELzmaFinishMode;
190 +
191 +/* ELzmaFinishMode has meaning only if the decoding reaches output limit !!!
192 +
193 + You must use LZMA_FINISH_END, when you know that current output buffer
194 + covers last bytes of block. In other cases you must use LZMA_FINISH_ANY.
195 +
196 + If LZMA decoder sees end marker before reaching output limit, it returns SZ_OK,
197 + and output value of destLen will be less than output buffer size limit.
198 + You can check status result also.
199 +
200 + You can use multiple checks to test data integrity after full decompression:
201 + 1) Check Result and "status" variable.
202 + 2) Check that output(destLen) = uncompressedSize, if you know real uncompressedSize.
203 + 3) Check that output(srcLen) = compressedSize, if you know real compressedSize.
204 + You must use correct finish mode in that case. */
205 +
206 +typedef enum
207 +{
208 + LZMA_STATUS_NOT_SPECIFIED, /* use main error code instead */
209 + LZMA_STATUS_FINISHED_WITH_MARK, /* stream was finished with end mark. */
210 + LZMA_STATUS_NOT_FINISHED, /* stream was not finished */
211 + LZMA_STATUS_NEEDS_MORE_INPUT, /* you must provide more input bytes */
212 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK /* there is probability that stream was finished without end mark */
213 +} ELzmaStatus;
214 +
215 +/* ELzmaStatus is used only as output value for function call */
216 +
217 +
218 +/* ---------- Interfaces ---------- */
219 +
220 +/* There are 3 levels of interfaces:
221 + 1) Dictionary Interface
222 + 2) Buffer Interface
223 + 3) One Call Interface
224 + You can select any of these interfaces, but don't mix functions from different
225 + groups for same object. */
226 +
227 +
228 +/* There are two variants to allocate state for Dictionary Interface:
229 + 1) LzmaDec_Allocate / LzmaDec_Free
230 + 2) LzmaDec_AllocateProbs / LzmaDec_FreeProbs
231 + You can use variant 2, if you set dictionary buffer manually.
232 + For Buffer Interface you must always use variant 1.
233 +
234 +LzmaDec_Allocate* can return:
235 + SZ_OK
236 + SZ_ERROR_MEM - Memory allocation error
237 + SZ_ERROR_UNSUPPORTED - Unsupported properties
238 +*/
239 +
240 +SRes LzmaDec_AllocateProbs(CLzmaDec *p, const Byte *props, unsigned propsSize, ISzAlloc *alloc);
241 +void LzmaDec_FreeProbs(CLzmaDec *p, ISzAlloc *alloc);
242 +
243 +SRes LzmaDec_Allocate(CLzmaDec *state, const Byte *prop, unsigned propsSize, ISzAlloc *alloc);
244 +void LzmaDec_Free(CLzmaDec *state, ISzAlloc *alloc);
245 +
246 +/* ---------- Dictionary Interface ---------- */
247 +
248 +/* You can use it, if you want to eliminate the overhead for data copying from
249 + dictionary to some other external buffer.
250 + You must work with CLzmaDec variables directly in this interface.
251 +
252 + STEPS:
253 + LzmaDec_Constr()
254 + LzmaDec_Allocate()
255 + for (each new stream)
256 + {
257 + LzmaDec_Init()
258 + while (it needs more decompression)
259 + {
260 + LzmaDec_DecodeToDic()
261 + use data from CLzmaDec::dic and update CLzmaDec::dicPos
262 + }
263 + }
264 + LzmaDec_Free()
265 +*/
266 +
267 +/* LzmaDec_DecodeToDic
268 +
269 + The decoding to internal dictionary buffer (CLzmaDec::dic).
270 + You must manually update CLzmaDec::dicPos, if it reaches CLzmaDec::dicBufSize !!!
271 +
272 +finishMode:
273 + It has meaning only if the decoding reaches output limit (dicLimit).
274 + LZMA_FINISH_ANY - Decode just dicLimit bytes.
275 + LZMA_FINISH_END - Stream must be finished after dicLimit.
276 +
277 +Returns:
278 + SZ_OK
279 + status:
280 + LZMA_STATUS_FINISHED_WITH_MARK
281 + LZMA_STATUS_NOT_FINISHED
282 + LZMA_STATUS_NEEDS_MORE_INPUT
283 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
284 + SZ_ERROR_DATA - Data error
285 +*/
286 +
287 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit,
288 + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
289 +
290 +
291 +/* ---------- Buffer Interface ---------- */
292 +
293 +/* It's zlib-like interface.
294 + See LzmaDec_DecodeToDic description for information about STEPS and return results,
295 + but you must use LzmaDec_DecodeToBuf instead of LzmaDec_DecodeToDic and you don't need
296 + to work with CLzmaDec variables manually.
297 +
298 +finishMode:
299 + It has meaning only if the decoding reaches output limit (*destLen).
300 + LZMA_FINISH_ANY - Decode just destLen bytes.
301 + LZMA_FINISH_END - Stream must be finished after (*destLen).
302 +*/
303 +
304 +SRes LzmaDec_DecodeToBuf(CLzmaDec *p, Byte *dest, SizeT *destLen,
305 + const Byte *src, SizeT *srcLen, ELzmaFinishMode finishMode, ELzmaStatus *status);
306 +
307 +
308 +/* ---------- One Call Interface ---------- */
309 +
310 +/* LzmaDecode
311 +
312 +finishMode:
313 + It has meaning only if the decoding reaches output limit (*destLen).
314 + LZMA_FINISH_ANY - Decode just destLen bytes.
315 + LZMA_FINISH_END - Stream must be finished after (*destLen).
316 +
317 +Returns:
318 + SZ_OK
319 + status:
320 + LZMA_STATUS_FINISHED_WITH_MARK
321 + LZMA_STATUS_NOT_FINISHED
322 + LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK
323 + SZ_ERROR_DATA - Data error
324 + SZ_ERROR_MEM - Memory allocation error
325 + SZ_ERROR_UNSUPPORTED - Unsupported properties
326 + SZ_ERROR_INPUT_EOF - It needs more bytes in input buffer (src).
327 +*/
328 +
329 +SRes LzmaDecode(Byte *dest, SizeT *destLen, const Byte *src, SizeT *srcLen,
330 + const Byte *propData, unsigned propSize, ELzmaFinishMode finishMode,
331 + ELzmaStatus *status, ISzAlloc *alloc);
332 +
333 +/* -------------------------------------------------------------------------- */
334 +
335 +/* LzmaDec.c -- LZMA Decoder
336 +2009-09-20 : Igor Pavlov : Public domain */
337 +
338 +//#include "LzmaDec.h"
339 +
340 +//#include <string.h>
341 +
342 +#define kNumTopBits 24
343 +#define kTopValue ((UInt32)1 << kNumTopBits)
344 +
345 +#define kNumBitModelTotalBits 11
346 +#define kBitModelTotal (1 << kNumBitModelTotalBits)
347 +#define kNumMoveBits 5
348 +
349 +#define RC_INIT_SIZE 5
350 +
351 +#define NORMALIZE if (range < kTopValue) { range <<= 8; code = (code << 8) | (*buf++); }
352 +
353 +#define TEST_BIT_0(p) ({ttt = *(p); NORMALIZE; bound = (range >> kNumBitModelTotalBits) * ttt; (code < bound);})
354 +#define UPDATE_0(p) range = bound; *(p) = (UIntLzmaProb)(ttt + ((kBitModelTotal - ttt) >> kNumMoveBits));
355 +#define UPDATE_1(p) range -= bound; code -= bound; *(p) = (UIntLzmaProb)(ttt - (ttt >> kNumMoveBits));
356 +#define GET_BIT2(p, i, A0, A1) if(TEST_BIT_0(p)) \
357 + { UPDATE_0(p); i = (i + i); A0; } else \
358 + { UPDATE_1(p); i = (i + i) + 1; A1; }
359 +#define GET_BIT(p, i) GET_BIT2(p, i, ; , ;)
360 +
361 +#define TREE_GET_BIT(probs, i) { GET_BIT((probs + i), i); }
362 +#define TREE_DECODE(probs, limit, i) \
363 + { i = 1; do { TREE_GET_BIT(probs, i); } while (i < limit); i -= limit; }
364 +
365 +/* #define _LZMA_SIZE_OPT */
366 +
367 +#ifdef _LZMA_SIZE_OPT
368 +#define TREE_6_DECODE(probs, i) TREE_DECODE(probs, (1 << 6), i)
369 +#else
370 +#define TREE_6_DECODE(probs, i) \
371 + { i = 1; \
372 + TREE_GET_BIT(probs, i); \
373 + TREE_GET_BIT(probs, i); \
374 + TREE_GET_BIT(probs, i); \
375 + TREE_GET_BIT(probs, i); \
376 + TREE_GET_BIT(probs, i); \
377 + TREE_GET_BIT(probs, i); \
378 + i -= 0x40; }
379 +#endif
380 +
381 +#define NORMALIZE_CHECK if (range < kTopValue) { if (buf >= bufLimit) return DUMMY_ERROR; range <<= 8; code = (code << 8) | (*buf++); }
382 +
383 +#define IF_BIT_0_CHECK(p) ttt = *(p); NORMALIZE_CHECK; bound = (range >> kNumBitModelTotalBits) * ttt; if (code < bound)
384 +#define UPDATE_0_CHECK range = bound;
385 +#define UPDATE_1_CHECK range -= bound; code -= bound;
386 +#define GET_BIT2_CHECK(p, i, A0, A1) IF_BIT_0_CHECK(p) \
387 + { UPDATE_0_CHECK; i = (i + i); A0; } else \
388 + { UPDATE_1_CHECK; i = (i + i) + 1; A1; }
389 +#define GET_BIT_CHECK(p, i) GET_BIT2_CHECK(p, i, ; , ;)
390 +#define TREE_DECODE_CHECK(probs, limit, i) \
391 + { i = 1; do { GET_BIT_CHECK(probs + i, i) } while (i < limit); i -= limit; }
392 +
393 +
394 +#define kNumPosBitsMax 4
395 +#define kNumPosStatesMax (1 << kNumPosBitsMax)
396 +
397 +#define kLenNumLowBits 3
398 +#define kLenNumLowSymbols (1 << kLenNumLowBits)
399 +#define kLenNumMidBits 3
400 +#define kLenNumMidSymbols (1 << kLenNumMidBits)
401 +#define kLenNumHighBits 8
402 +#define kLenNumHighSymbols (1 << kLenNumHighBits)
403 +
404 +#define LenChoice 0
405 +#define LenChoice2 (LenChoice + 1)
406 +#define LenLow (LenChoice2 + 1)
407 +#define LenMid (LenLow + (kNumPosStatesMax << kLenNumLowBits))
408 +#define LenHigh (LenMid + (kNumPosStatesMax << kLenNumMidBits))
409 +#define kNumLenProbs (LenHigh + kLenNumHighSymbols)
410 +
411 +
412 +#define kNumStates 12
413 +#define kNumLitStates 7
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 +#define kMatchSpecLenStart (kMatchMinLen + kLenNumLowSymbols + kLenNumMidSymbols + kLenNumHighSymbols)
427 +
428 +#define IsMatch 0
429 +#define IsRep (IsMatch + (kNumStates << kNumPosBitsMax))
430 +#define IsRepG0 (IsRep + kNumStates)
431 +#define IsRepG1 (IsRepG0 + kNumStates)
432 +#define IsRepG2 (IsRepG1 + kNumStates)
433 +#define IsRep0Long (IsRepG2 + kNumStates)
434 +#define PosSlot (IsRep0Long + (kNumStates << kNumPosBitsMax))
435 +#define SpecPos (PosSlot + (kNumLenToPosStates << kNumPosSlotBits))
436 +#define Align (SpecPos + kNumFullDistances - kEndPosModelIndex)
437 +#define LenCoder (Align + kAlignTableSize)
438 +#define RepLenCoder (LenCoder + kNumLenProbs)
439 +#define Literal (RepLenCoder + kNumLenProbs)
440 +
441 +#define LZMA_BASE_SIZE 1846
442 +#define LZMA_LIT_SIZE 768
443 +
444 +#define LzmaProps_GetNumProbs(p) ((UInt32)LZMA_BASE_SIZE + (LZMA_LIT_SIZE << ((p)->lc + (p)->lp)))
445 +
446 +#if Literal != LZMA_BASE_SIZE
447 +StopCompilingDueBUG
448 +#endif
449 +
450 +#define LZMA_DIC_MIN (1 << 12)
451 +
452 +/* First LZMA-symbol is always decoded.
453 +And it decodes new LZMA-symbols while (buf < bufLimit), but "buf" is without last normalization
454 +Out:
455 + Result:
456 + SZ_OK - OK
457 + SZ_ERROR_DATA - Error
458 + p->remainLen:
459 + < kMatchSpecLenStart : normal remain
460 + = kMatchSpecLenStart : finished
461 + = kMatchSpecLenStart + 1 : Flush marker
462 + = kMatchSpecLenStart + 2 : State Init Marker
463 +*/
464 +
465 +static int MY_FAST_CALL LzmaDec_DecodeReal(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
466 +{
467 + UIntLzmaProb *probs = p->probs;
468 +
469 + unsigned state = p->state;
470 + UInt32 rep0 = p->reps[0], rep1 = p->reps[1], rep2 = p->reps[2], rep3 = p->reps[3];
471 + unsigned pbMask = ((unsigned)1 << (p->prop.pb)) - 1;
472 + unsigned lpMask = ((unsigned)1 << (p->prop.lp)) - 1;
473 + unsigned lc = p->prop.lc;
474 +
475 + Byte *dic = p->dic;
476 + SizeT dicBufSize = p->dicBufSize;
477 + SizeT dicPos = p->dicPos;
478 +
479 + UInt32 processedPos = p->processedPos;
480 + UInt32 checkDicSize = p->checkDicSize;
481 + unsigned len = 0;
482 +
483 + const Byte *buf = p->buf;
484 + UInt32 range = p->range;
485 + UInt32 code = p->code;
486 +
487 + do
488 + {
489 + UIntLzmaProb *prob;
490 + UInt32 bound;
491 + unsigned ttt;
492 + unsigned posState = processedPos & pbMask;
493 +
494 + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
495 + if(TEST_BIT_0(prob))
496 + {
497 + unsigned symbol;
498 + UPDATE_0(prob);
499 + prob = probs + Literal;
500 + if (checkDicSize != 0 || processedPos != 0)
501 + prob += (LZMA_LIT_SIZE * (((processedPos & lpMask) << lc) +
502 + (dic[(dicPos == 0 ? dicBufSize : dicPos) - 1] >> (8 - lc))));
503 +
504 + if (state < kNumLitStates)
505 + {
506 + state -= (state < 4) ? state : 3;
507 + symbol = 1;
508 + do { GET_BIT(prob + symbol, symbol) } while (symbol < 0x100);
509 + }
510 + else
511 + {
512 + unsigned matchByte = p->dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
513 + unsigned offs = 0x100;
514 + state -= (state < 10) ? 3 : 6;
515 + symbol = 1;
516 + do
517 + {
518 + unsigned bit;
519 + UIntLzmaProb *probLit;
520 + matchByte <<= 1;
521 + bit = (matchByte & offs);
522 + probLit = prob + offs + bit + symbol;
523 + GET_BIT2(probLit, symbol, offs &= ~bit, offs &= bit)
524 + }
525 + while (symbol < 0x100);
526 + }
527 + dic[dicPos++] = (Byte)symbol;
528 + processedPos++;
529 + continue;
530 + }
531 + else
532 + {
533 + UPDATE_1(prob);
534 + prob = probs + IsRep + state;
535 + if(TEST_BIT_0(prob))
536 + {
537 + UPDATE_0(prob);
538 + state += kNumStates;
539 + prob = probs + LenCoder;
540 + }
541 + else
542 + {
543 + UPDATE_1(prob);
544 + if (checkDicSize == 0 && processedPos == 0)
545 + return SZ_ERROR_DATA;
546 + prob = probs + IsRepG0 + state;
547 + if(TEST_BIT_0(prob))
548 + {
549 + UPDATE_0(prob);
550 + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
551 + if(TEST_BIT_0(prob))
552 + {
553 + UPDATE_0(prob);
554 + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
555 + dicPos++;
556 + processedPos++;
557 + state = state < kNumLitStates ? 9 : 11;
558 + continue;
559 + }
560 + UPDATE_1(prob);
561 + }
562 + else
563 + {
564 + UInt32 distance;
565 + UPDATE_1(prob);
566 + prob = probs + IsRepG1 + state;
567 + if(TEST_BIT_0(prob))
568 + {
569 + UPDATE_0(prob);
570 + distance = rep1;
571 + }
572 + else
573 + {
574 + UPDATE_1(prob);
575 + prob = probs + IsRepG2 + state;
576 + if(TEST_BIT_0(prob))
577 + {
578 + UPDATE_0(prob);
579 + distance = rep2;
580 + }
581 + else
582 + {
583 + UPDATE_1(prob);
584 + distance = rep3;
585 + rep3 = rep2;
586 + }
587 + rep2 = rep1;
588 + }
589 + rep1 = rep0;
590 + rep0 = distance;
591 + }
592 + state = state < kNumLitStates ? 8 : 11;
593 + prob = probs + RepLenCoder;
594 + }
595 + {
596 + unsigned limit, offset;
597 + UIntLzmaProb *probLen = prob + LenChoice;
598 + if(TEST_BIT_0(probLen))
599 + {
600 + UPDATE_0(probLen);
601 + probLen = prob + LenLow + (posState << kLenNumLowBits);
602 + offset = 0;
603 + limit = (1 << kLenNumLowBits);
604 + }
605 + else
606 + {
607 + UPDATE_1(probLen);
608 + probLen = prob + LenChoice2;
609 + if(TEST_BIT_0(probLen))
610 + {
611 + UPDATE_0(probLen);
612 + probLen = prob + LenMid + (posState << kLenNumMidBits);
613 + offset = kLenNumLowSymbols;
614 + limit = (1 << kLenNumMidBits);
615 + }
616 + else
617 + {
618 + UPDATE_1(probLen);
619 + probLen = prob + LenHigh;
620 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
621 + limit = (1 << kLenNumHighBits);
622 + }
623 + }
624 + TREE_DECODE(probLen, limit, len);
625 + len += offset;
626 + }
627 +
628 + if (state >= kNumStates)
629 + {
630 + UInt32 distance;
631 + prob = probs + PosSlot +
632 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) << kNumPosSlotBits);
633 + TREE_6_DECODE(prob, distance);
634 + if (distance >= kStartPosModelIndex)
635 + {
636 + unsigned posSlot = (unsigned)distance;
637 + int numDirectBits = (int)(((distance >> 1) - 1));
638 + distance = (2 | (distance & 1));
639 + if (posSlot < kEndPosModelIndex)
640 + {
641 + distance <<= numDirectBits;
642 + prob = probs + SpecPos + distance - posSlot - 1;
643 + {
644 + UInt32 mask = 1;
645 + unsigned i = 1;
646 + do
647 + {
648 + GET_BIT2(prob + i, i, ; , distance |= mask);
649 + mask <<= 1;
650 + }
651 + while (--numDirectBits != 0);
652 + }
653 + }
654 + else
655 + {
656 + numDirectBits -= kNumAlignBits;
657 + do
658 + {
659 + NORMALIZE
660 + range >>= 1;
661 +
662 + {
663 + UInt32 t;
664 + code -= range;
665 + t = (0 - ((UInt32)code >> 31)); /* (UInt32)((Int32)code >> 31) */
666 + distance = (distance << 1) + (t + 1);
667 + code += range & t;
668 + }
669 + /*
670 + distance <<= 1;
671 + if (code >= range)
672 + {
673 + code -= range;
674 + distance |= 1;
675 + }
676 + */
677 + }
678 + while (--numDirectBits != 0);
679 + prob = probs + Align;
680 + distance <<= kNumAlignBits;
681 + {
682 + unsigned i = 1;
683 + GET_BIT2(prob + i, i, ; , distance |= 1);
684 + GET_BIT2(prob + i, i, ; , distance |= 2);
685 + GET_BIT2(prob + i, i, ; , distance |= 4);
686 + GET_BIT2(prob + i, i, ; , distance |= 8);
687 + }
688 + if (distance == (UInt32)0xFFFFFFFF)
689 + {
690 + len += kMatchSpecLenStart;
691 + state -= kNumStates;
692 + break;
693 + }
694 + }
695 + }
696 + rep3 = rep2;
697 + rep2 = rep1;
698 + rep1 = rep0;
699 + rep0 = distance + 1;
700 + if (checkDicSize == 0)
701 + {
702 + if (distance >= processedPos)
703 + return SZ_ERROR_DATA;
704 + }
705 + else if (distance >= checkDicSize)
706 + return SZ_ERROR_DATA;
707 + state = (state < kNumStates + kNumLitStates) ? kNumLitStates : kNumLitStates + 3;
708 + }
709 +
710 + len += kMatchMinLen;
711 +
712 + if (limit == dicPos)
713 + return SZ_ERROR_DATA;
714 + {
715 + SizeT rem = limit - dicPos;
716 + unsigned curLen = ((rem < len) ? (unsigned)rem : len);
717 + SizeT pos = (dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0);
718 +
719 + processedPos += curLen;
720 +
721 + len -= curLen;
722 + if (pos + curLen <= dicBufSize)
723 + {
724 + Byte *dest = dic + dicPos;
725 + ptrdiff_t src = (ptrdiff_t)pos - (ptrdiff_t)dicPos;
726 + const Byte *lim = dest + curLen;
727 + dicPos += curLen;
728 + do
729 + *(dest) = (Byte)(*(dest + src));
730 + while (++dest != lim);
731 + }
732 + else
733 + {
734 + do
735 + {
736 + dic[dicPos++] = dic[pos];
737 + if (++pos == dicBufSize)
738 + pos = 0;
739 + }
740 + while (--curLen != 0);
741 + }
742 + }
743 + }
744 + }
745 + while (dicPos < limit && buf < bufLimit);
746 + NORMALIZE;
747 + p->buf = buf;
748 + p->range = range;
749 + p->code = code;
750 + p->remainLen = len;
751 + p->dicPos = dicPos;
752 + p->processedPos = processedPos;
753 + p->reps[0] = rep0;
754 + p->reps[1] = rep1;
755 + p->reps[2] = rep2;
756 + p->reps[3] = rep3;
757 + p->state = state;
758 +
759 + return SZ_OK;
760 +}
761 +
762 +static void MY_FAST_CALL LzmaDec_WriteRem(CLzmaDec *p, SizeT limit)
763 +{
764 + if (p->remainLen != 0 && p->remainLen < kMatchSpecLenStart)
765 + {
766 + Byte *dic = p->dic;
767 + SizeT dicPos = p->dicPos;
768 + SizeT dicBufSize = p->dicBufSize;
769 + unsigned len = p->remainLen;
770 + UInt32 rep0 = p->reps[0];
771 + if (limit - dicPos < len)
772 + len = (unsigned)(limit - dicPos);
773 +
774 + if (p->checkDicSize == 0 && p->prop.dicSize - p->processedPos <= len)
775 + p->checkDicSize = p->prop.dicSize;
776 +
777 + p->processedPos += len;
778 + p->remainLen -= len;
779 + while (len-- != 0)
780 + {
781 + dic[dicPos] = dic[(dicPos - rep0) + ((dicPos < rep0) ? dicBufSize : 0)];
782 + dicPos++;
783 + }
784 + p->dicPos = dicPos;
785 + }
786 +}
787 +
788 +static int MY_FAST_CALL LzmaDec_DecodeReal2(CLzmaDec *p, SizeT limit, const Byte *bufLimit)
789 +{
790 + do
791 + {
792 + SizeT limit2 = limit;
793 + if (p->checkDicSize == 0)
794 + {
795 + UInt32 rem = p->prop.dicSize - p->processedPos;
796 + if (limit - p->dicPos > rem)
797 + limit2 = p->dicPos + rem;
798 + }
799 + RINOK(LzmaDec_DecodeReal(p, limit2, bufLimit));
800 + if (p->processedPos >= p->prop.dicSize)
801 + p->checkDicSize = p->prop.dicSize;
802 + LzmaDec_WriteRem(p, limit);
803 + }
804 + while (p->dicPos < limit && p->buf < bufLimit && p->remainLen < kMatchSpecLenStart);
805 +
806 + if (p->remainLen > kMatchSpecLenStart)
807 + {
808 + p->remainLen = kMatchSpecLenStart;
809 + }
810 + return 0;
811 +}
812 +
813 +typedef enum
814 +{
815 + DUMMY_ERROR, /* unexpected end of input stream */
816 + DUMMY_LIT,
817 + DUMMY_MATCH,
818 + DUMMY_REP
819 +} ELzmaDummy;
820 +
821 +static ELzmaDummy LzmaDec_TryDummy(const CLzmaDec *p, const Byte *buf, SizeT inSize)
822 +{
823 + UInt32 range = p->range;
824 + UInt32 code = p->code;
825 + const Byte *bufLimit = buf + inSize;
826 + UIntLzmaProb *probs = p->probs;
827 + unsigned state = p->state;
828 + ELzmaDummy res;
829 +
830 + {
831 + UIntLzmaProb *prob;
832 + UInt32 bound;
833 + unsigned ttt;
834 + unsigned posState = (p->processedPos) & ((1 << p->prop.pb) - 1);
835 +
836 + prob = probs + IsMatch + (state << kNumPosBitsMax) + posState;
837 + IF_BIT_0_CHECK(prob)
838 + {
839 + UPDATE_0_CHECK
840 +
841 + /* if (bufLimit - buf >= 7) return DUMMY_LIT; */
842 +
843 + prob = probs + Literal;
844 + if (p->checkDicSize != 0 || p->processedPos != 0)
845 + prob += (LZMA_LIT_SIZE *
846 + ((((p->processedPos) & ((1 << (p->prop.lp)) - 1)) << p->prop.lc) +
847 + (p->dic[(p->dicPos == 0 ? p->dicBufSize : p->dicPos) - 1] >> (8 - p->prop.lc))));
848 +
849 + if (state < kNumLitStates)
850 + {
851 + unsigned symbol = 1;
852 + do { GET_BIT_CHECK(prob + symbol, symbol) } while (symbol < 0x100);
853 + }
854 + else
855 + {
856 + unsigned matchByte = p->dic[p->dicPos - p->reps[0] +
857 + ((p->dicPos < p->reps[0]) ? p->dicBufSize : 0)];
858 + unsigned offs = 0x100;
859 + unsigned symbol = 1;
860 + do
861 + {
862 + unsigned bit;
863 + UIntLzmaProb *probLit;
864 + matchByte <<= 1;
865 + bit = (matchByte & offs);
866 + probLit = prob + offs + bit + symbol;
867 + GET_BIT2_CHECK(probLit, symbol, offs &= ~bit, offs &= bit)
868 + }
869 + while (symbol < 0x100);
870 + }
871 + res = DUMMY_LIT;
872 + }
873 + else
874 + {
875 + unsigned len;
876 + UPDATE_1_CHECK;
877 +
878 + prob = probs + IsRep + state;
879 + IF_BIT_0_CHECK(prob)
880 + {
881 + UPDATE_0_CHECK;
882 + state = 0;
883 + prob = probs + LenCoder;
884 + res = DUMMY_MATCH;
885 + }
886 + else
887 + {
888 + UPDATE_1_CHECK;
889 + res = DUMMY_REP;
890 + prob = probs + IsRepG0 + state;
891 + IF_BIT_0_CHECK(prob)
892 + {
893 + UPDATE_0_CHECK;
894 + prob = probs + IsRep0Long + (state << kNumPosBitsMax) + posState;
895 + IF_BIT_0_CHECK(prob)
896 + {
897 + UPDATE_0_CHECK;
898 + NORMALIZE_CHECK;
899 + return DUMMY_REP;
900 + }
901 + else
902 + {
903 + UPDATE_1_CHECK;
904 + }
905 + }
906 + else
907 + {
908 + UPDATE_1_CHECK;
909 + prob = probs + IsRepG1 + state;
910 + IF_BIT_0_CHECK(prob)
911 + {
912 + UPDATE_0_CHECK;
913 + }
914 + else
915 + {
916 + UPDATE_1_CHECK;
917 + prob = probs + IsRepG2 + state;
918 + IF_BIT_0_CHECK(prob)
919 + {
920 + UPDATE_0_CHECK;
921 + }
922 + else
923 + {
924 + UPDATE_1_CHECK;
925 + }
926 + }
927 + }
928 + state = kNumStates;
929 + prob = probs + RepLenCoder;
930 + }
931 + {
932 + unsigned limit, offset;
933 + UIntLzmaProb *probLen = prob + LenChoice;
934 + IF_BIT_0_CHECK(probLen)
935 + {
936 + UPDATE_0_CHECK;
937 + probLen = prob + LenLow + (posState << kLenNumLowBits);
938 + offset = 0;
939 + limit = 1 << kLenNumLowBits;
940 + }
941 + else
942 + {
943 + UPDATE_1_CHECK;
944 + probLen = prob + LenChoice2;
945 + IF_BIT_0_CHECK(probLen)
946 + {
947 + UPDATE_0_CHECK;
948 + probLen = prob + LenMid + (posState << kLenNumMidBits);
949 + offset = kLenNumLowSymbols;
950 + limit = 1 << kLenNumMidBits;
951 + }
952 + else
953 + {
954 + UPDATE_1_CHECK;
955 + probLen = prob + LenHigh;
956 + offset = kLenNumLowSymbols + kLenNumMidSymbols;
957 + limit = 1 << kLenNumHighBits;
958 + }
959 + }
960 + TREE_DECODE_CHECK(probLen, limit, len);
961 + len += offset;
962 + }
963 +
964 + if (state < 4)
965 + {
966 + unsigned posSlot;
967 + prob = probs + PosSlot +
968 + ((len < kNumLenToPosStates ? len : kNumLenToPosStates - 1) <<
969 + kNumPosSlotBits);
970 + TREE_DECODE_CHECK(prob, 1 << kNumPosSlotBits, posSlot);
971 + if (posSlot >= kStartPosModelIndex)
972 + {
973 + int numDirectBits = ((posSlot >> 1) - 1);
974 +
975 + /* if (bufLimit - buf >= 8) return DUMMY_MATCH; */
976 +
977 + if (posSlot < kEndPosModelIndex)
978 + {
979 + prob = probs + SpecPos + ((2 | (posSlot & 1)) << numDirectBits) - posSlot - 1;
980 + }
981 + else
982 + {
983 + numDirectBits -= kNumAlignBits;
984 + do
985 + {
986 + NORMALIZE_CHECK
987 + range >>= 1;
988 + code -= range & (((code - range) >> 31) - 1);
989 + /* if (code >= range) code -= range; */
990 + }
991 + while (--numDirectBits != 0);
992 + prob = probs + Align;
993 + numDirectBits = kNumAlignBits;
994 + }
995 + {
996 + unsigned i = 1;
997 + do
998 + {
999 + GET_BIT_CHECK(prob + i, i);
1000 + }
1001 + while (--numDirectBits != 0);
1002 + }
1003 + }
1004 + }
1005 + }
1006 + }
1007 + NORMALIZE_CHECK;
1008 + return res;
1009 +}
1012 +static void LzmaDec_InitRc(CLzmaDec *p, const Byte *data)
1013 +{
1014 + p->code = ((UInt32)data[1] << 24) | ((UInt32)data[2] << 16) | ((UInt32)data[3] << 8) | ((UInt32)data[4]);
1015 + p->range = 0xFFFFFFFF;
1016 + p->needFlush = 0;
1017 +}
1019 +void LzmaDec_Init(CLzmaDec *p)
1020 +{
1021 + p->dicFilePos = 0;
1022 + p->dicPos = 0;
1023 + p->needFlush = 1;
1024 + p->remainLen = 0;
1025 + p->tempBufSize = 0;
1026 + p->processedPos = 0;
1027 + p->checkDicSize = 0;
1028 + p->needInitState = 1;
1029 + p->needInitState = 1;
1030 +}
1032 +static void LzmaDec_InitStateReal(CLzmaDec *p)
1033 +{
1034 + UInt32 numProbs = Literal + ((UInt32)LZMA_LIT_SIZE << (p->prop.lc + p->prop.lp));
1035 + UInt32 i;
1036 + UIntLzmaProb *probs = p->probs;
1037 + for (i = 0; i < numProbs; i++)
1038 + probs[i] = kBitModelTotal >> 1;
1039 + p->reps[0] = p->reps[1] = p->reps[2] = p->reps[3] = 1;
1040 + p->state = 0;
1041 + p->needInitState = 0;
1042 +}
1044 +SRes LzmaDec_DecodeToDic(CLzmaDec *p, SizeT dicLimit, const Byte *src, SizeT *srcLen,
1045 + ELzmaFinishMode finishMode, ELzmaStatus *status)
1046 +{
1047 + SizeT inSize = *srcLen;
1048 + (*srcLen) = 0;
1049 + LzmaDec_WriteRem(p, dicLimit);
1051 + *status = LZMA_STATUS_NOT_SPECIFIED;
1053 + while (p->remainLen != kMatchSpecLenStart)
1054 + {
1055 + int checkEndMarkNow;
1057 + if (p->needFlush != 0)
1058 + {
1059 + for (; inSize > 0 && p->tempBufSize < RC_INIT_SIZE; (*srcLen)++, inSize--)
1060 + p->tempBuf[p->tempBufSize++] = *src++;
1061 + if (p->tempBufSize < RC_INIT_SIZE)
1062 + {
1063 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
1064 + return SZ_OK;
1065 + }
1066 + if (p->tempBuf[0] != 0)
1067 + return SZ_ERROR_DATA;
1069 + LzmaDec_InitRc(p, p->tempBuf);
1070 + p->tempBufSize = 0;
1071 + }
1073 + checkEndMarkNow = 0;
1074 + if (p->dicPos >= dicLimit)
1075 + {
1076 + if (p->remainLen == 0 && p->code == 0)
1077 + {
1078 + *status = LZMA_STATUS_MAYBE_FINISHED_WITHOUT_MARK;
1079 + return SZ_OK;
1080 + }
1081 + if (finishMode == LZMA_FINISH_ANY)
1082 + {
1083 + *status = LZMA_STATUS_NOT_FINISHED;
1084 + return SZ_OK;
1085 + }
1086 + if (p->remainLen != 0)
1087 + {
1088 + *status = LZMA_STATUS_NOT_FINISHED;
1089 + return SZ_ERROR_DATA;
1090 + }
1091 + checkEndMarkNow = 1;
1092 + }
1094 + if (p->needInitState)
1095 + LzmaDec_InitStateReal(p);
1097 + if (p->tempBufSize == 0)
1098 + {
1099 + SizeT processed;
1100 + const Byte *bufLimit;
1101 + if (inSize < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
1102 + {
1103 + int dummyRes = LzmaDec_TryDummy(p, src, inSize);
1104 + if (dummyRes == DUMMY_ERROR)
1105 + {
1106 + memcpy(p->tempBuf, src, inSize);
1107 + p->tempBufSize = (unsigned)inSize;
1108 + (*srcLen) += inSize;
1109 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
1110 + return SZ_OK;
1111 + }
1112 + if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
1113 + {
1114 + *status = LZMA_STATUS_NOT_FINISHED;
1115 + return SZ_ERROR_DATA;
1116 + }
1117 + bufLimit = src;
1118 + }
1119 + else
1120 + bufLimit = src + inSize - LZMA_REQUIRED_INPUT_MAX;
1121 + p->buf = src;
1122 + if (LzmaDec_DecodeReal2(p, dicLimit, bufLimit) != 0)
1123 + return SZ_ERROR_DATA;
1124 + processed = (SizeT)(p->buf - src);
1125 + (*srcLen) += processed;
1126 + src += processed;
1127 + inSize -= processed;
1128 + }
1129 + else
1130 + {
1131 + unsigned rem = p->tempBufSize, lookAhead = 0;
1132 + while (rem < LZMA_REQUIRED_INPUT_MAX && lookAhead < inSize)
1133 + p->tempBuf[rem++] = src[lookAhead++];
1134 + p->tempBufSize = rem;
1135 + if (rem < LZMA_REQUIRED_INPUT_MAX || checkEndMarkNow)
1136 + {
1137 + int dummyRes = LzmaDec_TryDummy(p, p->tempBuf, rem);
1138 + if (dummyRes == DUMMY_ERROR)
1139 + {
1140 + (*srcLen) += lookAhead;
1141 + *status = LZMA_STATUS_NEEDS_MORE_INPUT;
1142 + return SZ_OK;
1143 + }
1144 + if (checkEndMarkNow && dummyRes != DUMMY_MATCH)
1145 + {
1146 + *status = LZMA_STATUS_NOT_FINISHED;
1147 + return SZ_ERROR_DATA;
1148 + }
1149 + }
1150 + p->buf = p->tempBuf;
1151 + if (LzmaDec_DecodeReal2(p, dicLimit, p->buf) != 0)
1152 + return SZ_ERROR_DATA;
1153 + lookAhead -= (rem - (unsigned)(p->buf - p->tempBuf));
1154 + (*srcLen) += lookAhead;
1155 + src += lookAhead;
1156 + inSize -= lookAhead;
1157 + p->tempBufSize = 0;
1158 + }
1159 + }
1160 + if (p->code == 0)
1161 + *status = LZMA_STATUS_FINISHED_WITH_MARK;
1162 + return (p->code == 0) ? SZ_OK : SZ_ERROR_DATA;
1163 +}
1165 +/* -------------------------------------------------------------------------- */
1167 +#define ReadUnalignedUInt32(p) ((UInt32)((Byte*)(p))[0] | ((UInt32)((Byte*)(p))[1]<<8) | ((UInt32)((Byte*)(p))[2]<<16) | ((UInt32)((Byte*)(p))[3]<<24))
1168 +#define ReadUnalignedUInt64(p) (ReadUnalignedUInt32(p) | ((UInt64)ReadUnalignedUInt32((Byte*)(p)+4)<<32))
1170 +CLzmaDec lzmadec;
1172 +static unsigned long malloc_top = 0;
1173 +static void *grub_malloc(unsigned long size)
1174 +{
1175 + if (!malloc_top)
1176 + malloc_top = RAW_ADDR ((saved_mem_upper << 10) + 0x100000);
1177 + malloc_top = (malloc_top - size) & ~3;
1178 + return (void *) malloc_top;
1179 +}
1180 +#define grub_free(x)
1182 +int
1183 +dec_lzma_open (void)
1184 +// return 1=success or 0=failure
1185 +{
1186 + unsigned char header[13];
1187 + unsigned char d;
1189 + if (no_decompression) return 0;
1191 + // Now it does not support openning more than 1 file at a time.
1192 + // Make sure previously allocated memory blocks is freed.
1193 + // Don't need this line if grub_close is called for every openned file before grub_open is called for next file.
1194 + dec_lzma_close();
1196 + filepos = 0;
1197 + if (grub_read ((char *)header, 13, 0xedde0d90) == 13)
1198 + {
1199 + // check header
1200 + lzmadec.prop.dicSize = ReadUnalignedUInt32(header+1);
1201 + if (lzmadec.prop.dicSize < LZMA_DIC_MIN)
1202 + lzmadec.prop.dicSize = LZMA_DIC_MIN;
1203 + d = header[0];
1204 + if (d < 9*5*5)
1205 + {
1206 + // valid LZMA file
1207 + lzmadec.prop.lc = d % 9; d /= 9;
1208 + lzmadec.prop.lp = d % 5;
1209 + lzmadec.prop.pb = d / 5;
1210 + lzmadec.fileu.fmax = ReadUnalignedUInt64(header+5);
1211 + lzmadec.fileu.fpos = 0;
1212 + lzmadec.dicBufSize = lzmadec.prop.dicSize;
1213 + lzmadec.dic = (Byte*) grub_malloc(lzmadec.dicBufSize);
1214 + //grub_printf("LZMA allocate memory\n");
1215 + if (lzmadec.dic)
1216 + {
1217 + lzmadec.numProbs = LzmaProps_GetNumProbs(&lzmadec.prop);
1218 + lzmadec.probs = (UIntLzmaProb *) grub_malloc(lzmadec.numProbs * sizeof(UIntLzmaProb));
1219 + if (lzmadec.probs)
1220 + {
1221 + lzmadec.inpBufSize = 0x8000;
1222 + lzmadec.inp = (Byte*) grub_malloc(lzmadec.inpBufSize);
1223 + if (lzmadec.inp)
1224 + {
1225 + lzmadec.inpFilePos = 0;
1226 + lzmadec.inpPos = 0;
1227 + lzmadec.inpSize = 0;
1228 + LzmaDec_Init(&lzmadec);
1229 + decomp_type = 1;
1230 + compressed_file = 1;
1231 + lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax;
1232 + lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos;
1233 + // success
1234 + //grub_printf("LZMA open success\n");
1235 + errnum = 0;
1236 + return 1;
1237 + }
1238 + else
1239 + {
1240 + errnum = ERR_NOT_ENOUGH_MEMORY;
1241 + }
1242 + grub_free(lzmadec.probs); lzmadec.probs = 0;
1243 + }
1244 + else
1245 + {
1246 + errnum = ERR_NOT_ENOUGH_MEMORY;
1247 + }
1248 + grub_free(lzmadec.dic); lzmadec.dic = 0;
1249 + }
1250 + else
1251 + {
1252 + errnum = ERR_NOT_ENOUGH_MEMORY;
1253 + }
1254 + }
1255 + else
1256 + {
1257 + //grub_printf("LZMA allocate memory\n");
1258 + errnum = ERR_BAD_GZIP_HEADER;
1259 + }
1260 + }
1261 + else
1262 + {
1263 + //grub_printf("LZMA error reading header\n");
1264 + errnum = ERR_BAD_GZIP_HEADER;
1265 + }
1266 + //grub_printf("LZMA open fail\n");
1267 + filepos = 0;
1268 + return 0;
1269 +}
1271 +void
1272 +dec_lzma_close (void)
1273 +{
1274 + if (lzmadec.inp ) { grub_free(lzmadec.inp ); lzmadec.inp = 0; }
1275 + if (lzmadec.dic ) { grub_free(lzmadec.dic ); lzmadec.dic = 0; }
1276 + if (lzmadec.probs) { grub_free(lzmadec.probs); lzmadec.probs = 0; }
1277 +}
1279 +unsigned long
1280 +dec_lzma_read (char *buf, unsigned long len, unsigned long write)
1281 +{
1282 + UInt64 outTx, outSkip;
1283 + //grub_printf("LZMA read buf=%ld len=%ld dic=%d inp=%d\n",buf,len,lzmadec.dic,lzmadec.inp);
1285 + compressed_file = 0;
1286 + lzmadec.fileu.fmax = filemax; filemax = lzmadec.filec.fmax;
1287 + lzmadec.fileu.fpos = filepos; filepos = lzmadec.filec.fpos;
1288 + /* Now filepos, filemax is of compressed file
1289 + * fileu.fpos, fileu.fmax is of uncompressed data
1290 + * filec is not used
1291 + */
1293 + /*
1294 + * When dicPos>0,
1295 + * dic[0 ... dicPos-1] contains
1296 + * uncompressed_data [dicFilePos ... dicFilePos+dicPos-1].
1297 + * When dicFilePos>0,
1298 + * dic[dicPos ... dicBufSize-1] contains
1299 + * uncompressed_data [dicFilePos-dicBufSize+dicFilePos ... dicFilePos-1]
1300 + */
1301 + /* do we reset decompression to the beginning of the file? */
1302 + if (lzmadec.dicFilePos && (lzmadec.fileu.fpos < lzmadec.dicFilePos-lzmadec.dicBufSize+lzmadec.dicFilePos))
1303 + {
1304 + LzmaDec_Init(&lzmadec);
1305 + filepos = 13;
1306 + lzmadec.inpPos = lzmadec.inpSize = 0;
1307 + }
1309 + outTx = 0;
1310 + outSkip = lzmadec.fileu.fpos - lzmadec.dicFilePos;
1311 + //grub_printf("fileu.fpos=%ld dicFilePos=%ld\n",lzmadec.fileu.fpos,lzmadec.dicFilePos);
1313 + /* Copy uncompressed data from upper part of dic. dic[dicPos]...dic[dicBufSize-1] */
1314 + if (lzmadec.dicFilePos > lzmadec.fileu.fpos)
1315 + {
1316 + UInt32 outTxCur = lzmadec.dicFilePos - lzmadec.fileu.fpos;
1317 + if (outTxCur > len) outTxCur = len;
1318 + if (buf)
1319 + {
1320 + grub_memmove(buf, lzmadec.dic+outSkip+lzmadec.dicBufSize, outTxCur);
1321 + buf += outTxCur;
1322 + }
1323 + outSkip = 0;
1324 + outTx += outTxCur;
1325 + lzmadec.fileu.fpos += outTxCur;
1326 + len -= outTxCur;
1327 + }
1329 + while (len!=0)
1330 + {
1331 + SizeT inSizeCur, dicLimit;
1332 + UInt32 dicPos;
1333 + ELzmaStatus status;
1334 + SRes res;
1336 + /* Copy uncompressed data from lower part of dic. dic[0]...dic[dicPos-1] */
1337 + //grub_printf("Loop len=%ld outSkip=%ld dicPos=%d\n",len,outSkip,lzmadec.dicPos);
1338 + if (outSkip < lzmadec.dicPos)
1339 + {
1340 + UInt32 outTxCur = lzmadec.dicPos - outSkip;
1341 + //grub_printf("Copy %d byte ",outTxCur);
1342 + if (buf)
1343 + {
1344 + grub_memmove(buf, lzmadec.dic+outSkip, outTxCur);
1345 + buf += outTxCur;
1346 + }
1347 + outSkip = lzmadec.dicPos;
1348 + outTx += outTxCur;
1349 + lzmadec.fileu.fpos += outTxCur;
1350 + len -= outTxCur;
1351 + //grub_printf(" remaining len=%ld\n",len);
1352 + if (len==0) break;
1353 + }
1354 + /* All existing wanted data from dic have been copied. We will add more data to dic. */
1355 + /* Read more input if there is no unprocessed input left. */
1356 + if (lzmadec.inpPos == lzmadec.inpSize)
1357 + {
1358 + UInt32 inTxCur = (filemax-filepos<lzmadec.inpBufSize)?filemax-filepos:lzmadec.inpBufSize;
1359 + lzmadec.inpFilePos = filepos;
1360 + lzmadec.inpPos = 0;
1361 + //grub_printf("read inp %d ",inTxCur);
1362 + lzmadec.inpSize = grub_read(lzmadec.inp, inTxCur, 0xedde0d90);
1363 + //grub_printf("->%d\n",lzmadec.inpSize);
1364 + }
1365 + inSizeCur = lzmadec.inpSize - lzmadec.inpPos;
1367 + /* Prepare output dicPos, dicLimit. */
1368 + if (lzmadec.dicPos == lzmadec.dicBufSize)
1369 + {
1370 + lzmadec.dicPos = 0;
1371 + outSkip -= lzmadec.dicBufSize;
1372 + }
1373 + dicPos = lzmadec.dicPos;
1374 + dicLimit = (lzmadec.dicBufSize-dicPos < len)? lzmadec.dicBufSize: dicPos+len;
1376 + /* Do decompression. */
1377 + //grub_printf("DecodeToDic dicPos=%d limit=%d inPos=%d inSize=%d ",dicPos,dicLimit,lzmadec.inpPos,inSizeCur);
1378 + status = LZMA_STATUS_NOT_SPECIFIED;
1379 + res = LzmaDec_DecodeToDic(&lzmadec, dicLimit, lzmadec.inp+lzmadec.inpPos, &inSizeCur, LZMA_FINISH_ANY, &status);
1380 + //grub_printf("->%d\n",inSizeCur);
1381 + lzmadec.inpPos += inSizeCur;
1382 + if (inSizeCur==0 && lzmadec.dicPos==dicPos)
1383 + {
1384 + /* Error */
1385 + //grub_printf("No more input and output\n");
1386 + break;
1387 + }
1388 + }
1389 + compressed_file = 1;
1390 + lzmadec.filec.fmax = filemax; filemax = lzmadec.fileu.fmax;
1391 + lzmadec.filec.fpos = filepos; filepos = lzmadec.fileu.fpos;
1392 + /* Now filepos, file max is of uncompressed data
1393 + * filec.fpos, filwc.fmax is of compressed file
1394 + * fileu is not used
1395 + */
1397 + //grub_printf("LZMA read end %ld\n",outTx);
1398 + return outTx;
1399 +}
1401 +#endif /* ! NO_DECOMPRESSION */
1402 diff -Naur ../grub4dos-chenall-r63/stage2/decomp.h ./stage2/decomp.h
1403 --- grub4dos-chenall-r63/stage2/decomp.h 1970-01-01 07:00:00.000000000 +0700
1404 +++ grub4dos/stage2/decomp.h 2010-11-28 13:51:54.687217000 +0700
1405 @@ -0,0 +1,36 @@
1406 +/* decomp.h - abstract decompression interface */
1407 +/*
1408 + * GRUB -- GRand Unified Bootloader
1409 + * Copyright (C) 1999,2000,2001,2004 Free Software Foundation, Inc.
1410 + *
1411 + * This program is free software; you can redistribute it and/or modify
1412 + * it under the terms of the GNU General Public License as published by
1413 + * the Free Software Foundation; either version 2 of the License, or
1414 + * (at your option) any later version.
1415 + *
1416 + * This program is distributed in the hope that it will be useful,
1417 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1418 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1419 + * GNU General Public License for more details.
1420 + *
1421 + * You should have received a copy of the GNU General Public License
1422 + * along with this program; if not, write to the Free Software
1423 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1424 + */
1426 +#ifndef ASM_FILE
1428 +struct decomp_entry
1429 +{
1430 + char *name;
1431 + int (*open_func) (void);
1432 + void (*close_func) (void);
1433 + unsigned long (*read_func) (char *buf, unsigned long len, unsigned long write);
1434 +};
1436 +#define NUM_DECOM 2
1438 +extern struct decomp_entry decomp_table[NUM_DECOM];
1439 +extern int decomp_type;
1441 +#endif
1442 \ No newline at end of file
1443 diff -Naur ../grub4dos-chenall-r63/stage2/disk_io.c ./stage2/disk_io.c
1444 --- grub4dos-chenall-r63/stage2/disk_io.c 2010-08-12 14:22:47.111207000 +0700
1445 +++ grub4dos/stage2/disk_io.c 2010-11-28 20:26:39.089887300 +0700
1446 @@ -21,6 +21,7 @@
1448 #include <shared.h>
1449 #include <filesys.h>
1450 +#include <decomp.h>
1451 #include <iso9660.h>
1453 #ifdef SUPPORT_NETBOOT
1454 @@ -1872,7 +1873,16 @@
1455 #ifdef NO_DECOMPRESSION
1456 return 1;
1457 #else
1458 - return gunzip_test_header ();
1459 + if (no_decompression)
1460 + return 1;
1461 + int i;
1462 + i = strlen(open_filename);
1463 + if (i>=5 && strcmp(open_filename+i-5,".lzma")==0)
1464 + dec_lzma_open ();
1465 + else
1466 + gunzip_test_header ();
1467 + errnum = 0;
1468 + return 1;
1469 #endif
1472 @@ -1903,7 +1903,7 @@
1474 if (write == 0x900ddeed)
1475 return !(errnum = ERR_WRITE_GZIP_FILE);
1476 - return gunzip_read (buf, len);
1477 + return decomp_table[decomp_type].read_func (buf, len, write);
1479 #endif /* NO_DECOMPRESSION */
1481 @@ -1978,6 +1982,12 @@
1482 void
1483 grub_close (void)
1485 +#ifndef NO_DECOMPRESSION
1486 + if (compressed_file)
1487 + decomp_table[decomp_type].close_func ();
1488 + compressed_file = 0;
1489 +#endif /* NO_DECOMPRESSION */
1491 #ifndef NO_BLOCK_FILES
1492 if (block_file)
1493 return;
1494 diff -Naur ../grub4dos-chenall-r63/stage2/gunzip.c ./stage2/gunzip.c
1495 --- grub4dos-chenall-r63/stage2/gunzip.c 2010-07-26 19:35:48.440546000 +0700
1496 +++ grub4dos/stage2/gunzip.c 2010-11-28 14:20:56.983870700 +0700
1497 @@ -129,6 +129,8 @@
1499 #include "filesys.h"
1501 +#include "decomp.h"
1503 /* so we can disable decompression */
1504 #ifdef GRUB_UTIL
1505 int no_decompression = 0;
1506 @@ -137,6 +139,15 @@
1507 /* used to tell if "read" should be redirected to "gunzip_read" */
1508 int compressed_file;
1510 +/* identify active decompressor */
1511 +int decomp_type;
1513 +struct decomp_entry decomp_table[NUM_DECOM] =
1514 +{
1515 + {"gz",gunzip_test_header,gunzip_close,gunzip_read},
1516 + {"lzma",dec_lzma_open,dec_lzma_close,dec_lzma_read}
1517 +};
1519 /* internal variables only */
1520 static unsigned long long gzip_data_offset;
1521 static unsigned long long gzip_filepos;
1522 @@ -227,6 +238,7 @@
1523 /* Little-Endian defines for the 2-byte magic number for gzip files */
1524 #define GZIP_HDR_LE 0x8B1F
1525 #define OLD_GZIP_HDR_LE 0x9E1F
1526 +#define LZMA_HDR_LE 0x005D
1528 /* Compression methods (see algorithm.doc) */
1529 #define STORED 0
1530 @@ -281,10 +292,18 @@
1531 if (no_decompression
1532 || grub_read ((char *)buf, 10, 0xedde0d90) != 10
1533 || ((*((unsigned short *) buf) != GZIP_HDR_LE)
1534 - && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE)))
1535 + && (*((unsigned short *) buf) != OLD_GZIP_HDR_LE)
1536 + && (*((unsigned short *) buf) != LZMA_HDR_LE)))
1538 filepos = 0;
1539 return ! errnum;
1540 + }
1542 + if (*((unsigned short *) buf) == LZMA_HDR_LE)
1543 + {
1544 + filepos = 0;
1545 + dec_lzma_open();
1546 + return 1;
1549 /*
1550 @@ -323,6 +334,7 @@
1552 initialize_tables ();
1554 + decomp_type = 0;
1555 compressed_file = 1;
1556 gunzip_swap_values ();
1557 /*
1558 @@ -334,6 +346,11 @@
1559 return 1;
1562 +void
1563 +gunzip_close (void)
1564 +{
1565 +}
1568 /* Huffman code lookup table entry--this entry is four bytes for machines
1569 that have 16-bit pointers (e.g. PC's in the small or medium model).
1570 @@ -1190,7 +1226,7 @@
1573 unsigned long
1574 -gunzip_read (char *buf, unsigned long len)
1575 +gunzip_read (char *buf, unsigned long len, unsigned long write)
1577 unsigned long ret = 0;
1579 diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.am ./stage2/Makefile.am
1580 --- grub4dos-chenall-r63/stage2/Makefile.am 2010-08-12 14:22:47.111207000 +0700
1581 +++ grub4dos/stage2/Makefile.am 2010-11-28 16:35:18.724975900 +0700
1582 @@ -16,6 +16,7 @@
1583 # The library for /sbin/grub.
1584 noinst_LIBRARIES = libgrub.a
1585 libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
1586 + dec_lzma.c \
1587 disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \
1588 fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
1589 fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \
1590 @@ -100,7 +101,7 @@
1592 # For stage2 target.
1593 pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
1594 - cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
1595 + cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \
1596 fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
1597 fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \
1598 hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c
1599 diff -Naur ../grub4dos-chenall-r63/stage2/Makefile.in ./stage2/Makefile.in
1600 --- grub4dos-chenall-r63/stage2/Makefile.in 2010-08-12 14:22:47.111207000 +0700
1601 +++ grub4dos/stage2/Makefile.in 2010-11-28 16:38:22.871508400 +0700
1602 @@ -104,10 +104,11 @@
1603 am_libgrub_a_OBJECTS = libgrub_a-boot.$(OBJEXT) \
1604 libgrub_a-builtins.$(OBJEXT) libgrub_a-char_io.$(OBJEXT) \
1605 libgrub_a-cmdline.$(OBJEXT) libgrub_a-common.$(OBJEXT) \
1606 - libgrub_a-disk_io.$(OBJEXT) libgrub_a-fsys_ext2fs.$(OBJEXT) \
1607 - libgrub_a-fsys_fat.$(OBJEXT) libgrub_a-fsys_ntfs.$(OBJEXT) \
1608 - libgrub_a-fsys_ffs.$(OBJEXT) libgrub_a-fsys_iso9660.$(OBJEXT) \
1609 - libgrub_a-fsys_jfs.$(OBJEXT) libgrub_a-fsys_minix.$(OBJEXT) \
1610 + libgrub_a-dec_lzma.$(OBJEXT) libgrub_a-disk_io.$(OBJEXT) \
1611 + libgrub_a-fsys_ext2fs.$(OBJEXT) libgrub_a-fsys_fat.$(OBJEXT) \
1612 + libgrub_a-fsys_ntfs.$(OBJEXT) libgrub_a-fsys_ffs.$(OBJEXT) \
1613 + libgrub_a-fsys_iso9660.$(OBJEXT) libgrub_a-fsys_jfs.$(OBJEXT) \
1614 + libgrub_a-fsys_minix.$(OBJEXT) \
1615 libgrub_a-fsys_reiserfs.$(OBJEXT) \
1616 libgrub_a-fsys_ufs2.$(OBJEXT) libgrub_a-fsys_vstafs.$(OBJEXT) \
1617 libgrub_a-fsys_xfs.$(OBJEXT) libgrub_a-fsys_pxe.$(OBJEXT) \
1618 @@ -131,6 +132,7 @@
1619 diskless_exec-char_io.$(OBJEXT) \
1620 diskless_exec-cmdline.$(OBJEXT) diskless_exec-common.$(OBJEXT) \
1621 diskless_exec-console.$(OBJEXT) \
1622 + diskless_exec-dec_lzma.$(OBJEXT) \
1623 diskless_exec-disk_io.$(OBJEXT) \
1624 diskless_exec-fsys_ext2fs.$(OBJEXT) \
1625 diskless_exec-fsys_fat.$(OBJEXT) \
1626 @@ -247,6 +249,7 @@
1627 pre_stage2_exec-cmdline.$(OBJEXT) \
1628 pre_stage2_exec-common.$(OBJEXT) \
1629 pre_stage2_exec-console.$(OBJEXT) \
1630 + pre_stage2_exec-dec_lzma.$(OBJEXT) \
1631 pre_stage2_exec-disk_io.$(OBJEXT) \
1632 pre_stage2_exec-fsys_ext2fs.$(OBJEXT) \
1633 pre_stage2_exec-fsys_fat.$(OBJEXT) \
1634 @@ -512,6 +513,7 @@
1635 # The library for /sbin/grub.
1636 noinst_LIBRARIES = libgrub.a
1637 libgrub_a_SOURCES = boot.c builtins.c char_io.c cmdline.c common.c \
1638 + dec_lzma.c \
1639 disk_io.c fsys_ext2fs.c fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c \
1640 fsys_jfs.c fsys_minix.c fsys_reiserfs.c fsys_ufs2.c \
1641 fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c md5.c serial.c stage2.c \
1642 @@ -559,7 +563,7 @@
1644 # For stage2 target.
1645 pre_stage2_exec_SOURCES = asm.S bios.c boot.c builtins.c char_io.c \
1646 - cmdline.c common.c console.c disk_io.c fsys_ext2fs.c \
1647 + cmdline.c common.c console.c dec_lzma.c disk_io.c fsys_ext2fs.c \
1648 fsys_fat.c fsys_ntfs.c fsys_ffs.c fsys_iso9660.c fsys_jfs.c fsys_minix.c \
1649 fsys_reiserfs.c fsys_ufs2.c fsys_vstafs.c fsys_xfs.c fsys_pxe.c gunzip.c \
1650 hercules.c md5.c serial.c smp-imps.c stage2.c terminfo.c tparm.c graphics.c
1651 @@ -878,6 +882,7 @@
1652 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-cmdline.Po@am__quote@
1653 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-common.Po@am__quote@
1654 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-console.Po@am__quote@
1655 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-dec_lzma.Po@am__quote@
1656 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-disk_io.Po@am__quote@
1657 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_ext2fs.Po@am__quote@
1658 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/diskless_exec-fsys_fat.Po@am__quote@
1659 @@ -935,6 +940,7 @@
1660 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-char_io.Po@am__quote@
1661 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-cmdline.Po@am__quote@
1662 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-common.Po@am__quote@
1663 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-dec_lzma.Po@am__quote@
1664 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-disk_io.Po@am__quote@
1665 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_ext2fs.Po@am__quote@
1666 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libgrub_a-fsys_fat.Po@am__quote@
1667 @@ -974,6 +980,7 @@
1668 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-cmdline.Po@am__quote@
1669 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-common.Po@am__quote@
1670 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-console.Po@am__quote@
1671 +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-dec_lzma.Po@am__quote@
1672 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-disk_io.Po@am__quote@
1673 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_ext2fs.Po@am__quote@
1674 @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/pre_stage2_exec-fsys_fat.Po@am__quote@
1675 @@ -1315,6 +1322,20 @@
1676 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1677 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-common.obj `if test -f 'common.c'; then $(CYGPATH_W) 'common.c'; else $(CYGPATH_W) '$(srcdir)/common.c'; fi`
1679 +libgrub_a-dec_lzma.o: dec_lzma.c
1680 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-dec_lzma.o -MD -MP -MF "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" -c -o libgrub_a-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
1681 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" "$(DEPDIR)/libgrub_a-dec_lzma.Po"; else rm -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo"; exit 1; fi
1682 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
1683 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1684 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
1686 +libgrub_a-dec_lzma.obj: dec_lzma.c
1687 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" -c -o libgrub_a-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
1688 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo" "$(DEPDIR)/libgrub_a-dec_lzma.Po"; else rm -f "$(DEPDIR)/libgrub_a-dec_lzma.Tpo"; exit 1; fi
1689 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='libgrub_a-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
1690 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1691 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -c -o libgrub_a-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
1693 libgrub_a-disk_io.o: disk_io.c
1694 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(libgrub_a_CFLAGS) $(CFLAGS) -MT libgrub_a-disk_io.o -MD -MP -MF "$(DEPDIR)/libgrub_a-disk_io.Tpo" -c -o libgrub_a-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
1695 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/libgrub_a-disk_io.Tpo" "$(DEPDIR)/libgrub_a-disk_io.Po"; else rm -f "$(DEPDIR)/libgrub_a-disk_io.Tpo"; exit 1; fi
1696 @@ -1693,6 +1714,20 @@
1697 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1698 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-console.obj `if test -f 'console.c'; then $(CYGPATH_W) 'console.c'; else $(CYGPATH_W) '$(srcdir)/console.c'; fi`
1700 +diskless_exec-dec_lzma.o: dec_lzma.c
1701 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-dec_lzma.o -MD -MP -MF "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" -c -o diskless_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
1702 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" "$(DEPDIR)/diskless_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo"; exit 1; fi
1703 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
1704 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1705 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
1707 +diskless_exec-dec_lzma.obj: dec_lzma.c
1708 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" -c -o diskless_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
1709 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo" "$(DEPDIR)/diskless_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/diskless_exec-dec_lzma.Tpo"; exit 1; fi
1710 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='diskless_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
1711 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1712 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -c -o diskless_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
1714 diskless_exec-disk_io.o: disk_io.c
1715 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(diskless_exec_CFLAGS) $(CFLAGS) -MT diskless_exec-disk_io.o -MD -MP -MF "$(DEPDIR)/diskless_exec-disk_io.Tpo" -c -o diskless_exec-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
1716 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/diskless_exec-disk_io.Tpo" "$(DEPDIR)/diskless_exec-disk_io.Po"; else rm -f "$(DEPDIR)/diskless_exec-disk_io.Tpo"; exit 1; fi
1717 @@ -2687,6 +2722,20 @@
1718 @AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1719 @am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-console.obj `if test -f 'console.c'; then $(CYGPATH_W) 'console.c'; else $(CYGPATH_W) '$(srcdir)/console.c'; fi`
1721 +pre_stage2_exec-dec_lzma.o: dec_lzma.c
1722 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-dec_lzma.o -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" -c -o pre_stage2_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c; \
1723 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" "$(DEPDIR)/pre_stage2_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo"; exit 1; fi
1724 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.o' libtool=no @AMDEPBACKSLASH@
1725 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1726 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-dec_lzma.o `test -f 'dec_lzma.c' || echo '$(srcdir)/'`dec_lzma.c
1728 +pre_stage2_exec-dec_lzma.obj: dec_lzma.c
1729 +@am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-dec_lzma.obj -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" -c -o pre_stage2_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`; \
1730 +@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo" "$(DEPDIR)/pre_stage2_exec-dec_lzma.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-dec_lzma.Tpo"; exit 1; fi
1731 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='dec_lzma.c' object='pre_stage2_exec-dec_lzma.obj' libtool=no @AMDEPBACKSLASH@
1732 +@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
1733 +@am__fastdepCC_FALSE@ $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -c -o pre_stage2_exec-dec_lzma.obj `if test -f 'dec_lzma.c'; then $(CYGPATH_W) 'dec_lzma.c'; else $(CYGPATH_W) '$(srcdir)/dec_lzma.c'; fi`
1735 pre_stage2_exec-disk_io.o: disk_io.c
1736 @am__fastdepCC_TRUE@ if $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(pre_stage2_exec_CFLAGS) $(CFLAGS) -MT pre_stage2_exec-disk_io.o -MD -MP -MF "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo" -c -o pre_stage2_exec-disk_io.o `test -f 'disk_io.c' || echo '$(srcdir)/'`disk_io.c; \
1737 @am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo" "$(DEPDIR)/pre_stage2_exec-disk_io.Po"; else rm -f "$(DEPDIR)/pre_stage2_exec-disk_io.Tpo"; exit 1; fi
1738 diff -Naur ../grub4dos-chenall-r63/stage2/shared.h ./stage2/shared.h
1739 --- grub4dos-chenall-r63/stage2/shared.h 2010-11-17 15:33:51.826683000 +0700
1740 +++ grub4dos/stage2/shared.h 2010-11-27 01:16:46.996893700 +0700
1741 @@ -640,6 +640,7 @@
1742 ERR_WRITE_GZIP_FILE,
1743 ERR_FUNC_CALL,
1744 // ERR_WRITE_TO_NON_MEM_DRIVE,
1745 + ERR_NOT_ENOUGH_MEMORY,
1747 MAX_ERR_NUM
1748 } grub_error_t;
1749 @@ -1185,7 +1186,11 @@
1750 #ifndef NO_DECOMPRESSION
1751 /* Compression support. */
1752 int gunzip_test_header (void);
1753 -unsigned long gunzip_read (char *buf, unsigned long len);
1754 +void gunzip_close (void);
1755 +unsigned long gunzip_read (char *buf, unsigned long len, unsigned long write);
1756 +int dec_lzma_open (void);
1757 +void dec_lzma_close (void);
1758 +unsigned long dec_lzma_read (char *buf, unsigned long len, unsigned long write);
1759 #endif /* NO_DECOMPRESSION */
1761 int rawread (unsigned long drive, unsigned long sector, unsigned long byte_offset, unsigned long byte_len, char *buf, unsigned long write);