MOXA linux-2.6.x / linux-2.6.19-uc1 from UC-7110-LX-BOOTLOADER-1.9_VERSION-4.2.tgz
[linux-2.6.19-moxart.git] / fs / squashfs / LzmaWrapper.c
bloba8ec90bb70e49e496a38f1b1c2b3bcdf35bdcca3
1 /*
2 LzmaTest.c
3 Test application for LZMA Decoder
4 LZMA SDK 4.01 Copyright (c) 1999-2004 Igor Pavlov (2004-02-15)
5 */
7 #include <linux/kernel.h>
8 #include <linux/string.h>
9 #include "LzmaDecode.h"
10 #include "LzmaWrapper.h"
12 static int internal_size;
13 static unsigned char *internal_data=0;
14 //static int dictionary_size;
16 int lzma_workspace_size(void)
18 // int pb=2;
19 int lp=0;
20 int lc=3;
22 return (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb);
25 int lzma_init(unsigned char *data, int size)
27 internal_data=data;
28 internal_size=size;
29 return 0;
32 int lzma_inflate(
33 unsigned char *source,
34 int s_len,
35 unsigned char *dest,
36 int *d_len)
38 /* Get the properties */
39 unsigned int check_internal_size;
40 unsigned char properties[5];
41 unsigned char prop0;
42 int lc, lp, pb;
43 int res, i;
44 unsigned int dictionary_size = 0;
45 unsigned int encoded_size;
47 if(s_len<5){
48 /* Can't even get properities, just exit */
49 return LZMA_ERROR;
52 /* Get the size of the uncompressed buffer */
53 encoded_size =
54 source[0] | (source[1] << 8) | (source[2] << 16) | (source[3] << 24);
55 source+=4;
57 /* We use this to check that the size of internal data structures
58 are big enough. If it isn't, then we flag it. */
59 memcpy(properties, source, sizeof(properties));
60 prop0 = properties[0];
61 if (prop0 >= (9*5*5))
62 return LZMA_ERROR;
63 for (pb = 0; prop0 >= (9 * 5);
64 pb++, prop0 -= (9 * 5));
65 for (lp = 0; prop0 >= 9;
66 lp++, prop0 -= 9);
67 lc = prop0;
69 source += 5;
71 check_internal_size =
72 (LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)))* sizeof(CProb);
74 for (i = 0; i < 4; i++)
75 dictionary_size += (UInt32)(properties[1 + i]) << (i * 8);
77 if(check_internal_size > internal_size){
78 printk("internal_size = %d, header size = %d\n", internal_size, check_internal_size);
79 printk("lc = %d, lp=%d, pb=%d\n", lc, lp, pb);
80 printk("byte=%x, dictionary size = %8.8x\n", prop0, dictionary_size);
81 return LZMA_TOO_BIG;
84 res = LzmaDecode(internal_data, internal_size,
85 lc, lp, pb,
86 (unsigned char *)source, s_len,
87 (unsigned char *)dest, encoded_size, d_len);
89 return res;