wok view linux/stuff/linux-unlzma-2.6.30.4.u @ rev 3909

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