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