wok-next view linux/stuff/linux-lzma-loram-2.6.24.2.u @ rev 1838
curl: --disable-ldap
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Thu Dec 11 14:45:41 2008 +0100 (2008-12-11) |
parents | |
children |
line source
1 --- linux-2.6.24.2/init/initramfs.c
2 +++ linux-2.6.24.2/init/initramfs.c
3 @@ -468,6 +468,29 @@
4 }
5 #endif
7 +#include <linux/initrd.h>
8 +#ifdef CONFIG_RD_LZMA
9 +#define INITRD_PAGE ((PAGE_SIZE > 1024*1024) ? PAGE_SIZE : 1024*1024)
10 +static int fill_offset, fill_total;
11 +static int fill_buffer(void *buffer, unsigned size)
12 +{
13 + int max = initrd_end - initrd_start - fill_offset;
14 + if (size < max) max = size;
15 + memcpy(buffer, (void *)(initrd_start + fill_offset), max);
16 + fill_offset += max;
17 + fill_total += max;
18 + if (fill_offset >= INITRD_PAGE) {
19 + unsigned rem = fill_offset % INITRD_PAGE;
20 + unsigned end = initrd_start + fill_offset - rem;
21 + free_initrd_mem(initrd_start, end);
22 + printk(".");
23 + initrd_start = end;
24 + fill_offset = rem;
25 + }
26 + return max;
27 +}
28 +#endif
29 +
30 static char * __init unpack_to_rootfs(char *buf, unsigned len, int check_only)
31 {
32 int written;
33 @@ -484,6 +507,9 @@
34 this_header = 0;
35 message = NULL;
36 while (!message && len) {
37 +#ifdef CONFIG_RD_LZMA
38 + int status;
39 +#endif
40 loff_t saved_offset = this_header;
41 if (*buf == '0' && !(this_header & 3)) {
42 state = Start;
43 @@ -523,8 +549,20 @@
44 #ifdef CONFIG_RD_LZMA
45 message = NULL; /* Zero out message, or else cpio will
46 think an error has already occured */
47 - if(!unlzma(buf, len, NULL, flush_buffer, &inptr) < 0 &&
48 - message == NULL) {
49 + status = -1;
50 + if(buf == (char *) initrd_start) {
51 + char *work_buffer = malloc(LZMA_IOBUF_SIZE);
52 + if (work_buffer) {
53 + fill_total = fill_offset = 0;
54 + fill_buffer(work_buffer, LZMA_IOBUF_SIZE);
55 + status = unlzma(work_buffer, LZMA_IOBUF_SIZE,
56 + fill_buffer, flush_buffer, NULL);
57 + inptr = fill_total;
58 + free(work_buffer);
59 + }
60 + }
61 + else status = unlzma(buf,len, NULL, flush_buffer, &inptr);
62 + if (status == 0 && message == NULL) {
63 goto ok;
64 }
65 #endif
67 --- linux-2.6.24.2/arch/x86/mm/init_32.c
68 +++ linux-2.6.24.2/arch/x86/mm/init_32.c
69 @@ -834,7 +834,8 @@
70 free_page(addr);
71 totalram_pages++;
72 }
73 - printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
74 + if (what)
75 + printk(KERN_INFO "Freeing %s: %luk freed\n", what, (end - begin) >> 10);
76 }
78 void free_initmem(void)
79 @@ -847,7 +848,7 @@
80 #ifdef CONFIG_BLK_DEV_INITRD
81 void free_initrd_mem(unsigned long start, unsigned long end)
82 {
83 - free_init_pages("initrd memory", start, end);
84 + free_init_pages(NULL, start, end);
85 }
86 #endif
89 --- linux-2.6.24.2/lib/decompress_unlzma.c
90 +++ linux-2.6.24.2/lib/decompress_unlzma.c
91 @@ -366,7 +366,8 @@
92 header.dict_size = 1;
94 bufsize = MIN(header.dst_size, header.dict_size);
95 - buffer = large_malloc(bufsize);
96 + buffer = (uint8_t *) posp;
97 + if (writebb) buffer = large_malloc(bufsize);
98 if(buffer == NULL)
99 return -1;
101 @@ -394,10 +395,12 @@
102 int match_byte;
104 pos = buffer_pos - rep0;
105 - while (pos >= header.dict_size)
106 - pos += header.dict_size;
107 - if(pos >= bufsize) {
108 - goto fail;
109 + if (writebb) {
110 + while (pos >= header.dict_size)
111 + pos += header.dict_size;
112 + if(pos >= bufsize) {
113 + goto fail;
114 + }
115 }
116 match_byte = buffer[pos];
117 do {
118 @@ -419,20 +422,14 @@
119 prob_lit = prob + mi;
120 rc_get_bit(&rc, prob_lit, &mi);
121 }
122 + previous_byte = (uint8_t) mi;
123 if (state < 4)
124 state = 0;
125 else if (state < 10)
126 state -= 3;
127 else
128 state -= 6;
129 - previous_byte = (uint8_t) mi;
130 - one_byte:
131 - buffer[buffer_pos++] = previous_byte;
132 - if (buffer_pos == header.dict_size) {
133 - buffer_pos = 0;
134 - global_pos += header.dict_size;
135 - writebb((char*)buffer, header.dict_size);
136 - }
137 + goto store_previous_byte;
138 } else {
139 int offset;
140 uint16_t *prob_len;
141 @@ -457,14 +454,23 @@
142 rc_update_bit_0(&rc, prob);
144 state = state < LZMA_NUM_LIT_STATES ? 9 : 11;
145 - pos = buffer_pos - rep0;
146 - while (pos >= header.dict_size)
147 - pos += header.dict_size;
148 - if(pos >= bufsize) {
149 - goto fail;
150 + pos = buffer_pos - rep0;
151 + if (writebb) {
152 + while (pos >= header.dict_size)
153 + pos += header.dict_size;
154 + if(pos >= bufsize) {
155 + goto fail;
156 + }
157 }
158 previous_byte = buffer[pos];
159 - goto one_byte;
160 + store_previous_byte:
161 + buffer[buffer_pos++] = previous_byte;
162 + if (writebb && buffer_pos == header.dict_size) {
163 + buffer_pos = 0;
164 + global_pos += header.dict_size;
165 + writebb((char*)buffer, header.dict_size);
166 + }
167 + continue;
168 } else {
169 rc_update_bit_1(&rc, prob);
170 }
171 @@ -566,14 +572,16 @@
173 do {
174 pos = buffer_pos - rep0;
175 - while (pos >= header.dict_size)
176 - pos += header.dict_size;
177 - if(pos >= bufsize) {
178 - goto fail;
179 + if (writebb) {
180 + while (pos >= header.dict_size)
181 + pos += header.dict_size;
182 + if(pos >= bufsize) {
183 + goto fail;
184 + }
185 }
186 previous_byte = buffer[pos];
187 buffer[buffer_pos++] = previous_byte;
188 - if (buffer_pos == header.dict_size) {
189 + if (writebb && buffer_pos == header.dict_size) {
190 buffer_pos = 0;
191 global_pos += header.dict_size;
192 writebb((char*)buffer, header.dict_size);
193 @@ -583,15 +591,17 @@
194 }
195 }
197 - writebb((char*)buffer, buffer_pos);
198 - if(posp) {
199 - *posp = rc.ptr-rc.buffer;
200 + if (writebb) {
201 + writebb((char*)buffer, buffer_pos);
202 + if(posp) {
203 + *posp = rc.ptr-rc.buffer;
204 + }
205 + large_free(buffer);
206 }
207 - large_free(buffer);
208 large_free(p);
209 return 0;
210 fail:
211 - large_free(buffer);
212 + if (writebb) large_free(buffer);
213 large_free(p);
214 return -1;
215 }
217 --- linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
218 +++ linux-2.6.24.2/arch/x86/boot/compressed/misc_32.c
219 @@ -444,7 +444,7 @@
221 #ifdef CONFIG_KERNEL_LZMA
222 putstr("Unlzmaing Linux... ");
223 - unlzma(input_data, input_len-4, NULL, compr_flush, NULL);
224 + unlzma(input_data, input_len-4, NULL, NULL, window);
225 #endif
227 #ifdef CONFIG_KERNEL_GZIP