Carl-Daniel Hailfinger | cba07dd | 2006-09-14 15:12:36 +0000 | [diff] [blame^] | 1 | /* |
| 2 | |
| 3 | LinuxBIOS interface to memory-saving variant of LZMA decoder |
| 4 | (C)opyright 2006 Carl-Daniel Hailfinger |
| 5 | Released under the GNU GPL |
| 6 | |
| 7 | */ |
| 8 | |
| 9 | #include "lzmadecode.c" |
| 10 | |
| 11 | |
| 12 | static unsigned long ulzma(unsigned char * src, unsigned char * dst) |
| 13 | { |
| 14 | unsigned char properties[LZMA_PROPERTIES_SIZE]; |
| 15 | UInt32 outSize; |
| 16 | SizeT inProcessed; |
| 17 | SizeT outProcessed; |
| 18 | int res; |
| 19 | CLzmaDecoderState state; |
| 20 | SizeT mallocneeds; |
| 21 | unsigned char scratchpad[15980]; |
| 22 | |
| 23 | memcpy(properties, src, LZMA_PROPERTIES_SIZE); |
| 24 | outSize = *(UInt32 *)(src + LZMA_PROPERTIES_SIZE); |
| 25 | if (LzmaDecodeProperties(&state.Properties, properties, LZMA_PROPERTIES_SIZE) != LZMA_RESULT_OK) { |
| 26 | printk_warning("Incorrect stream properties\n"); |
| 27 | } |
| 28 | mallocneeds = (LzmaGetNumProbs(&state.Properties) * sizeof(CProb)); |
| 29 | if (mallocneeds > 15980) { |
| 30 | printk_warning("Decoder scratchpad too small!\n"); |
| 31 | } |
| 32 | state.Probs = (CProb *)scratchpad; |
| 33 | res = LzmaDecode(&state, src + LZMA_PROPERTIES_SIZE + 8, (SizeT)0xffffffff, &inProcessed, |
| 34 | dst, outSize, &outProcessed); |
| 35 | if (res != 0) { |
| 36 | printk_warning("Decoding error = %d\n", res); |
| 37 | } |
| 38 | return outSize; |
| 39 | } |