rev |
line source |
slaxemulator@8085
|
1 --- linux-2.6.30.4/init/initramfs.c
|
slaxemulator@8085
|
2 +++ linux-2.6.30.4/init/initramfs.c
|
slaxemulator@8085
|
3 @@ -425,7 +425,8 @@
|
slaxemulator@8085
|
4 return len - count;
|
slaxemulator@8085
|
5 }
|
slaxemulator@8085
|
6
|
slaxemulator@8085
|
7 -static int __init flush_buffer(void *bufv, unsigned len)
|
slaxemulator@8085
|
8 +#define flush_buffer cpio_flush_buffer
|
slaxemulator@8085
|
9 +int __init flush_buffer(void *bufv, unsigned len)
|
slaxemulator@8085
|
10 {
|
slaxemulator@8085
|
11 char *buf = (char *) bufv;
|
slaxemulator@8085
|
12 int written;
|
slaxemulator@8085
|
13
|
slaxemulator@8085
|
14 --- linux-2.6.30.4/lib/decompress_unlzma.c
|
slaxemulator@8085
|
15 +++ linux-2.6.30.4/lib/decompress_unlzma.c
|
slaxemulator@8085
|
16 @@ -278,6 +278,10 @@
|
slaxemulator@8085
|
17 size_t global_pos;
|
slaxemulator@8085
|
18 int(*flush)(void*, unsigned int);
|
slaxemulator@8085
|
19 struct lzma_header *header;
|
slaxemulator@8085
|
20 + int is_cpio_flush;
|
slaxemulator@8085
|
21 + uint8_t **buffer_index;
|
slaxemulator@8085
|
22 + int next_index;
|
slaxemulator@8085
|
23 + int max_index;
|
slaxemulator@8085
|
24 };
|
slaxemulator@8085
|
25
|
slaxemulator@8085
|
26 struct cstate {
|
slaxemulator@8085
|
27 @@ -294,6 +298,14 @@
|
slaxemulator@8085
|
28 static inline uint8_t INIT peek_old_byte(struct writer *wr,
|
slaxemulator@8085
|
29 uint32_t offs)
|
slaxemulator@8085
|
30 {
|
slaxemulator@8085
|
31 + if (wr->is_cpio_flush) {
|
slaxemulator@8085
|
32 + int32_t pos;
|
slaxemulator@8085
|
33 + while (offs > wr->header->dict_size)
|
slaxemulator@8085
|
34 + offs -= wr->header->dict_size;
|
slaxemulator@8085
|
35 + pos = wr->buffer_pos - offs;
|
slaxemulator@8085
|
36 + return wr->buffer_index[pos / LZMA_IOBUF_SIZE]
|
slaxemulator@8085
|
37 + [pos % LZMA_IOBUF_SIZE];
|
slaxemulator@8085
|
38 + }
|
slaxemulator@8085
|
39 if (!wr->flush) {
|
slaxemulator@8085
|
40 int32_t pos;
|
slaxemulator@8085
|
41 while (offs > wr->header->dict_size)
|
slaxemulator@8085
|
42 @@ -309,8 +321,41 @@
|
slaxemulator@8085
|
43
|
slaxemulator@8085
|
44 }
|
slaxemulator@8085
|
45
|
slaxemulator@8085
|
46 +static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte)
|
slaxemulator@8085
|
47 +{
|
slaxemulator@8085
|
48 + if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) {
|
slaxemulator@8085
|
49 + // if the following large_malloc fails, the initramfs
|
slaxemulator@8085
|
50 + // whould not be load with is_cpio_flush forced 0 too.
|
slaxemulator@8085
|
51 + // Remember we do not allocate historic buffer.
|
slaxemulator@8085
|
52 + // Let's assume it will never fail !
|
slaxemulator@8085
|
53 + if (wr->next_index >= wr->max_index) {
|
slaxemulator@8085
|
54 + // realloc wr->buffer_index
|
slaxemulator@8085
|
55 + uint8_t **p = wr->buffer_index;
|
slaxemulator@8085
|
56 + wr->buffer_index = (uint8_t **)
|
slaxemulator@8085
|
57 + large_malloc(LZMA_IOBUF_SIZE +
|
slaxemulator@8085
|
58 + sizeof(*p) * wr->max_index);
|
slaxemulator@8085
|
59 + if (wr->max_index) {
|
slaxemulator@8085
|
60 + memcpy(wr->buffer_index, p,
|
slaxemulator@8085
|
61 + sizeof(*p) * wr->max_index);
|
slaxemulator@8085
|
62 + free(p);
|
slaxemulator@8085
|
63 + }
|
slaxemulator@8085
|
64 + wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p);
|
slaxemulator@8085
|
65 + }
|
slaxemulator@8085
|
66 + wr->buffer_index[wr->next_index++] =
|
slaxemulator@8085
|
67 + (uint8_t *) large_malloc(LZMA_IOBUF_SIZE);
|
slaxemulator@8085
|
68 + }
|
slaxemulator@8085
|
69 + wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE]
|
slaxemulator@8085
|
70 + [wr->buffer_pos % LZMA_IOBUF_SIZE] =
|
slaxemulator@8085
|
71 + wr->previous_byte = byte;
|
slaxemulator@8085
|
72 + wr->buffer_pos++;
|
slaxemulator@8085
|
73 +}
|
slaxemulator@8085
|
74 +
|
slaxemulator@8085
|
75 static inline void INIT write_byte(struct writer *wr, uint8_t byte)
|
slaxemulator@8085
|
76 {
|
slaxemulator@8085
|
77 + if (wr->is_cpio_flush) {
|
slaxemulator@8085
|
78 + write_byte_if_cpio(wr, byte);
|
slaxemulator@8085
|
79 + return;
|
slaxemulator@8085
|
80 + }
|
slaxemulator@8085
|
81 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
|
slaxemulator@8085
|
82 if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
|
slaxemulator@8085
|
83 wr->buffer_pos = 0;
|
slaxemulator@8085
|
84 @@ -328,7 +373,21 @@
|
slaxemulator@8085
|
85 static inline void INIT copy_bytes(struct writer *wr,
|
slaxemulator@8085
|
86 uint32_t rep0, int len)
|
slaxemulator@8085
|
87 {
|
slaxemulator@8085
|
88 - do {
|
slaxemulator@8085
|
89 + if (wr->is_cpio_flush) {
|
slaxemulator@8085
|
90 + int32_t pos;
|
slaxemulator@8085
|
91 + uint32_t offs = rep0;
|
slaxemulator@8085
|
92 + while (offs > wr->header->dict_size)
|
slaxemulator@8085
|
93 + offs -= wr->header->dict_size;
|
slaxemulator@8085
|
94 + pos = wr->buffer_pos - offs;
|
slaxemulator@8085
|
95 + do {
|
slaxemulator@8085
|
96 + write_byte_if_cpio(wr,
|
slaxemulator@8085
|
97 + wr->buffer_index[pos / LZMA_IOBUF_SIZE]
|
slaxemulator@8085
|
98 + [pos % LZMA_IOBUF_SIZE]);
|
slaxemulator@8085
|
99 + pos++;
|
slaxemulator@8085
|
100 + len--;
|
slaxemulator@8085
|
101 + } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
|
slaxemulator@8085
|
102 + }
|
slaxemulator@8085
|
103 + else do {
|
slaxemulator@8085
|
104 copy_byte(wr, rep0);
|
slaxemulator@8085
|
105 len--;
|
slaxemulator@8085
|
106 } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
|
slaxemulator@8085
|
107 @@ -339,6 +398,9 @@
|
slaxemulator@8085
|
108 int pos_state, uint16_t *prob,
|
slaxemulator@8085
|
109 int lc, uint32_t literal_pos_mask) {
|
slaxemulator@8085
|
110 int mi = 1;
|
slaxemulator@8085
|
111 + static const int state[LZMA_NUM_STATES] =
|
slaxemulator@8085
|
112 + { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
|
slaxemulator@8085
|
113 +
|
slaxemulator@8085
|
114 rc_update_bit_0(rc, prob);
|
slaxemulator@8085
|
115 prob = (p + LZMA_LITERAL +
|
slaxemulator@8085
|
116 (LZMA_LIT_SIZE
|
slaxemulator@8085
|
117 @@ -369,18 +431,13 @@
|
slaxemulator@8085
|
118 rc_get_bit(rc, prob_lit, &mi);
|
slaxemulator@8085
|
119 }
|
slaxemulator@8085
|
120 write_byte(wr, mi);
|
slaxemulator@8085
|
121 - if (cst->state < 4)
|
slaxemulator@8085
|
122 - cst->state = 0;
|
slaxemulator@8085
|
123 - else if (cst->state < 10)
|
slaxemulator@8085
|
124 - cst->state -= 3;
|
slaxemulator@8085
|
125 - else
|
slaxemulator@8085
|
126 - cst->state -= 6;
|
slaxemulator@8085
|
127 + cst->state = state[cst->state];
|
slaxemulator@8085
|
128 }
|
slaxemulator@8085
|
129
|
slaxemulator@8085
|
130 static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
|
slaxemulator@8085
|
131 struct cstate *cst, uint16_t *p,
|
slaxemulator@8085
|
132 int pos_state, uint16_t *prob) {
|
slaxemulator@8085
|
133 - int offset;
|
slaxemulator@8085
|
134 + int offset;
|
slaxemulator@8085
|
135 uint16_t *prob_len;
|
slaxemulator@8085
|
136 int num_bits;
|
slaxemulator@8085
|
137 int len;
|
slaxemulator@8085
|
138 @@ -396,7 +453,7 @@
|
slaxemulator@8085
|
139 prob = p + LZMA_LEN_CODER;
|
slaxemulator@8085
|
140 } else {
|
slaxemulator@8085
|
141 rc_update_bit_1(rc, prob);
|
slaxemulator@8085
|
142 - prob = p + LZMA_IS_REP_G0 + cst->state;
|
slaxemulator@8085
|
143 + prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
|
slaxemulator@8085
|
144 if (rc_is_bit_0(rc, prob)) {
|
slaxemulator@8085
|
145 rc_update_bit_0(rc, prob);
|
slaxemulator@8085
|
146 prob = (p + LZMA_IS_REP_0_LONG
|
slaxemulator@8085
|
147 @@ -417,13 +474,13 @@
|
slaxemulator@8085
|
148 uint32_t distance;
|
slaxemulator@8085
|
149
|
slaxemulator@8085
|
150 rc_update_bit_1(rc, prob);
|
slaxemulator@8085
|
151 - prob = p + LZMA_IS_REP_G1 + cst->state;
|
slaxemulator@8085
|
152 + prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
|
slaxemulator@8085
|
153 if (rc_is_bit_0(rc, prob)) {
|
slaxemulator@8085
|
154 rc_update_bit_0(rc, prob);
|
slaxemulator@8085
|
155 distance = cst->rep1;
|
slaxemulator@8085
|
156 } else {
|
slaxemulator@8085
|
157 rc_update_bit_1(rc, prob);
|
slaxemulator@8085
|
158 - prob = p + LZMA_IS_REP_G2 + cst->state;
|
slaxemulator@8085
|
159 + prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
|
slaxemulator@8085
|
160 if (rc_is_bit_0(rc, prob)) {
|
slaxemulator@8085
|
161 rc_update_bit_0(rc, prob);
|
slaxemulator@8085
|
162 distance = cst->rep2;
|
slaxemulator@8085
|
163 @@ -444,24 +501,24 @@
|
slaxemulator@8085
|
164 prob_len = prob + LZMA_LEN_CHOICE;
|
slaxemulator@8085
|
165 if (rc_is_bit_0(rc, prob_len)) {
|
slaxemulator@8085
|
166 rc_update_bit_0(rc, prob_len);
|
slaxemulator@8085
|
167 - prob_len = (prob + LZMA_LEN_LOW
|
slaxemulator@8085
|
168 + prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
|
slaxemulator@8085
|
169 + (pos_state <<
|
slaxemulator@8085
|
170 - LZMA_LEN_NUM_LOW_BITS));
|
slaxemulator@8085
|
171 + LZMA_LEN_NUM_LOW_BITS);
|
slaxemulator@8085
|
172 offset = 0;
|
slaxemulator@8085
|
173 num_bits = LZMA_LEN_NUM_LOW_BITS;
|
slaxemulator@8085
|
174 } else {
|
slaxemulator@8085
|
175 rc_update_bit_1(rc, prob_len);
|
slaxemulator@8085
|
176 - prob_len = prob + LZMA_LEN_CHOICE_2;
|
slaxemulator@8085
|
177 + prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
|
slaxemulator@8085
|
178 if (rc_is_bit_0(rc, prob_len)) {
|
slaxemulator@8085
|
179 rc_update_bit_0(rc, prob_len);
|
slaxemulator@8085
|
180 - prob_len = (prob + LZMA_LEN_MID
|
slaxemulator@8085
|
181 + prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
|
slaxemulator@8085
|
182 + (pos_state <<
|
slaxemulator@8085
|
183 - LZMA_LEN_NUM_MID_BITS));
|
slaxemulator@8085
|
184 + LZMA_LEN_NUM_MID_BITS);
|
slaxemulator@8085
|
185 offset = 1 << LZMA_LEN_NUM_LOW_BITS;
|
slaxemulator@8085
|
186 num_bits = LZMA_LEN_NUM_MID_BITS;
|
slaxemulator@8085
|
187 } else {
|
slaxemulator@8085
|
188 rc_update_bit_1(rc, prob_len);
|
slaxemulator@8085
|
189 - prob_len = prob + LZMA_LEN_HIGH;
|
slaxemulator@8085
|
190 + prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
|
slaxemulator@8085
|
191 offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
|
slaxemulator@8085
|
192 + (1 << LZMA_LEN_NUM_MID_BITS));
|
slaxemulator@8085
|
193 num_bits = LZMA_LEN_NUM_HIGH_BITS;
|
slaxemulator@8085
|
194 @@ -529,6 +586,7 @@
|
slaxemulator@8085
|
195 void(*error_fn)(char *x)
|
slaxemulator@8085
|
196 )
|
slaxemulator@8085
|
197 {
|
slaxemulator@8085
|
198 + extern int cpio_flush_buffer(void*, unsigned int);
|
slaxemulator@8085
|
199 struct lzma_header header;
|
slaxemulator@8085
|
200 int lc, pb, lp;
|
slaxemulator@8085
|
201 uint32_t pos_state_mask;
|
slaxemulator@8085
|
202 @@ -563,6 +621,10 @@
|
slaxemulator@8085
|
203 wr.global_pos = 0;
|
slaxemulator@8085
|
204 wr.previous_byte = 0;
|
slaxemulator@8085
|
205 wr.buffer_pos = 0;
|
slaxemulator@8085
|
206 + wr.is_cpio_flush = 0;
|
slaxemulator@8085
|
207 + if (flush == cpio_flush_buffer)
|
slaxemulator@8085
|
208 + wr.is_cpio_flush = 1;
|
slaxemulator@8085
|
209 + wr.buffer_index = NULL;
|
slaxemulator@8085
|
210
|
slaxemulator@8085
|
211 rc_init(&rc, fill, inbuf, in_len);
|
slaxemulator@8085
|
212
|
slaxemulator@8085
|
213 @@ -596,23 +658,23 @@
|
slaxemulator@8085
|
214 if (header.dict_size == 0)
|
slaxemulator@8085
|
215 header.dict_size = 1;
|
slaxemulator@8085
|
216
|
slaxemulator@8085
|
217 - if (output)
|
slaxemulator@8085
|
218 + if (output || wr.is_cpio_flush)
|
slaxemulator@8085
|
219 wr.buffer = output;
|
slaxemulator@8085
|
220 else {
|
slaxemulator@8085
|
221 wr.bufsize = MIN(header.dst_size, header.dict_size);
|
slaxemulator@8085
|
222 wr.buffer = large_malloc(wr.bufsize);
|
slaxemulator@8085
|
223 }
|
slaxemulator@8085
|
224 - if (wr.buffer == NULL)
|
slaxemulator@8085
|
225 + if (wr.buffer == NULL && !wr.is_cpio_flush)
|
slaxemulator@8085
|
226 goto exit_1;
|
slaxemulator@8085
|
227
|
slaxemulator@8085
|
228 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
|
slaxemulator@8085
|
229 p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
|
slaxemulator@8085
|
230 if (p == 0)
|
slaxemulator@8085
|
231 goto exit_2;
|
slaxemulator@8085
|
232 - num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
|
slaxemulator@8085
|
233 + num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
|
slaxemulator@8085
|
234 for (i = 0; i < num_probs; i++)
|
slaxemulator@8085
|
235 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
|
slaxemulator@8085
|
236 -
|
slaxemulator@8085
|
237 + wr.max_index = wr.next_index = 0;
|
slaxemulator@8085
|
238 rc_init_code(&rc);
|
slaxemulator@8085
|
239
|
slaxemulator@8085
|
240 while (get_pos(&wr) < header.dst_size) {
|
slaxemulator@8085
|
241 @@ -631,12 +693,25 @@
|
slaxemulator@8085
|
242
|
slaxemulator@8085
|
243 if (posp)
|
slaxemulator@8085
|
244 *posp = rc.ptr-rc.buffer;
|
slaxemulator@8085
|
245 - if (wr.flush)
|
slaxemulator@8085
|
246 + if (wr.is_cpio_flush) {
|
slaxemulator@8085
|
247 + int i;
|
slaxemulator@8085
|
248 + for (i = 0; i < wr.next_index -1; i++) {
|
slaxemulator@8085
|
249 + wr.flush(wr.buffer_index[i], LZMA_IOBUF_SIZE);
|
slaxemulator@8085
|
250 + large_free(wr.buffer_index[i]);
|
slaxemulator@8085
|
251 + }
|
slaxemulator@8085
|
252 + if (i < wr.next_index) {
|
slaxemulator@8085
|
253 + wr.flush(wr.buffer_index[i],
|
slaxemulator@8085
|
254 + wr.buffer_pos % LZMA_IOBUF_SIZE);
|
slaxemulator@8085
|
255 + large_free(wr.buffer_index[i]);
|
slaxemulator@8085
|
256 + }
|
slaxemulator@8085
|
257 + large_free(wr.buffer_index);
|
slaxemulator@8085
|
258 + }
|
slaxemulator@8085
|
259 + else if (wr.flush)
|
slaxemulator@8085
|
260 wr.flush(wr.buffer, wr.buffer_pos);
|
slaxemulator@8085
|
261 ret = 0;
|
slaxemulator@8085
|
262 large_free(p);
|
slaxemulator@8085
|
263 exit_2:
|
slaxemulator@8085
|
264 - if (!output)
|
slaxemulator@8085
|
265 + if (!output && !wr.is_cpio_flush)
|
slaxemulator@8085
|
266 large_free(wr.buffer);
|
slaxemulator@8085
|
267 exit_1:
|
slaxemulator@8085
|
268 if (!buf)
|