wok-current rev 5058
linux: squashfs & lzma patches should be compatible
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Mar 09 00:09:23 2010 +0100 (2010-03-09) |
parents | 68b326a153e2 |
children | f642eb9dd1b4 |
files | linux/stuff/linux-squashfs-lzma-2.6.30.6.u |
line diff
1.1 --- a/linux/stuff/linux-squashfs-lzma-2.6.30.6.u Mon Mar 08 13:52:48 2010 +0000 1.2 +++ b/linux/stuff/linux-squashfs-lzma-2.6.30.6.u Tue Mar 09 00:09:23 2010 +0100 1.3 @@ -1355,7 +1355,7 @@ 1.4 */ 1.5 -static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p) 1.6 +static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p, 1.7 -+ void (*error)(char *x)) 1.8 ++ void (*error)(char *x)) 1.9 { 1.10 - rc_normalize(rc); 1.11 + rc_normalize(rc, error); 1.12 @@ -1411,98 +1411,7 @@ 1.13 *symbol -= 1 << num_levels; 1.14 } 1.15 1.16 -@@ -278,10 +291,6 @@ 1.17 - size_t global_pos; 1.18 - int(*flush)(void*, unsigned int); 1.19 - struct lzma_header *header; 1.20 -- int is_cpio_flush; 1.21 -- uint8_t **buffer_index; 1.22 -- int next_index; 1.23 -- int max_index; 1.24 - }; 1.25 - 1.26 - struct cstate { 1.27 -@@ -298,14 +307,6 @@ 1.28 - static inline uint8_t INIT peek_old_byte(struct writer *wr, 1.29 - uint32_t offs) 1.30 - { 1.31 -- if (wr->is_cpio_flush) { 1.32 -- int32_t pos; 1.33 -- while (offs > wr->header->dict_size) 1.34 -- offs -= wr->header->dict_size; 1.35 -- pos = wr->buffer_pos - offs; 1.36 -- return wr->buffer_index[pos / LZMA_IOBUF_SIZE] 1.37 -- [pos % LZMA_IOBUF_SIZE]; 1.38 -- } 1.39 - if (!wr->flush) { 1.40 - int32_t pos; 1.41 - while (offs > wr->header->dict_size) 1.42 -@@ -321,41 +322,8 @@ 1.43 - 1.44 - } 1.45 - 1.46 --static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte) 1.47 --{ 1.48 -- if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) { 1.49 -- // if the following large_malloc fails, the initramfs 1.50 -- // whould not be load with is_cpio_flush forced 0 too. 1.51 -- // Remember we do not allocate historic buffer. 1.52 -- // Let's assume it will never fail ! 1.53 -- if (wr->next_index >= wr->max_index) { 1.54 -- // realloc wr->buffer_index 1.55 -- uint8_t **p = wr->buffer_index; 1.56 -- wr->buffer_index = (uint8_t **) 1.57 -- large_malloc(LZMA_IOBUF_SIZE + 1.58 -- sizeof(*p) * wr->max_index); 1.59 -- if (wr->max_index) { 1.60 -- memcpy(wr->buffer_index, p, 1.61 -- sizeof(*p) * wr->max_index); 1.62 -- free(p); 1.63 -- } 1.64 -- wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p); 1.65 -- } 1.66 -- wr->buffer_index[wr->next_index++] = 1.67 -- (uint8_t *) large_malloc(LZMA_IOBUF_SIZE); 1.68 -- } 1.69 -- wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE] 1.70 -- [wr->buffer_pos % LZMA_IOBUF_SIZE] = 1.71 -- wr->previous_byte = byte; 1.72 -- wr->buffer_pos++; 1.73 --} 1.74 -- 1.75 - static inline void INIT write_byte(struct writer *wr, uint8_t byte) 1.76 - { 1.77 -- if (wr->is_cpio_flush) { 1.78 -- write_byte_if_cpio(wr, byte); 1.79 -- return; 1.80 -- } 1.81 - wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; 1.82 - if (wr->flush && wr->buffer_pos == wr->header->dict_size) { 1.83 - wr->buffer_pos = 0; 1.84 -@@ -373,21 +341,7 @@ 1.85 - static inline void INIT copy_bytes(struct writer *wr, 1.86 - uint32_t rep0, int len) 1.87 - { 1.88 -- if (wr->is_cpio_flush) { 1.89 -- int32_t pos; 1.90 -- uint32_t offs = rep0; 1.91 -- while (offs > wr->header->dict_size) 1.92 -- offs -= wr->header->dict_size; 1.93 -- pos = wr->buffer_pos - offs; 1.94 -- do { 1.95 -- write_byte_if_cpio(wr, 1.96 -- wr->buffer_index[pos / LZMA_IOBUF_SIZE] 1.97 -- [pos % LZMA_IOBUF_SIZE]); 1.98 -- pos++; 1.99 -- len--; 1.100 -- } while (len != 0 && wr->buffer_pos < wr->header->dst_size); 1.101 -- } 1.102 -- else do { 1.103 -+ do { 1.104 - copy_byte(wr, rep0); 1.105 - len--; 1.106 - } while (len != 0 && wr->buffer_pos < wr->header->dst_size); 1.107 -@@ -396,11 +350,9 @@ 1.108 +@@ -396,7 +409,8 @@ 1.109 static inline void INIT process_bit0(struct writer *wr, struct rc *rc, 1.110 struct cstate *cst, uint16_t *p, 1.111 int pos_state, uint16_t *prob, 1.112 @@ -1510,13 +1419,9 @@ 1.113 + int lc, uint32_t literal_pos_mask, 1.114 + void(*error)(char *x)) { 1.115 int mi = 1; 1.116 -- static const int state[LZMA_NUM_STATES] = 1.117 -- { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; 1.118 -- 1.119 - rc_update_bit_0(rc, prob); 1.120 - prob = (p + LZMA_LITERAL + 1.121 - (LZMA_LIT_SIZE 1.122 -@@ -417,7 +369,7 @@ 1.123 + static const int state[LZMA_NUM_STATES] = 1.124 + { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; 1.125 +@@ -417,7 +431,7 @@ 1.126 match_byte <<= 1; 1.127 bit = match_byte & 0x100; 1.128 prob_lit = prob + 0x100 + bit + mi; 1.129 @@ -1525,7 +1430,7 @@ 1.130 if (!bit) 1.131 break; 1.132 } else { 1.133 -@@ -428,23 +380,29 @@ 1.134 +@@ -428,7 +442,7 @@ 1.135 } 1.136 while (mi < 0x100) { 1.137 uint16_t *prob_lit = prob + mi; 1.138 @@ -1533,25 +1438,18 @@ 1.139 + rc_get_bit(rc, prob_lit, &mi, error); 1.140 } 1.141 write_byte(wr, mi); 1.142 -- cst->state = state[cst->state]; 1.143 -+ if (cst->state < 4) 1.144 -+ cst->state = 0; 1.145 -+ else if (cst->state < 10) 1.146 -+ cst->state -= 3; 1.147 -+ else 1.148 -+ cst->state -= 6; 1.149 - } 1.150 + cst->state = state[cst->state]; 1.151 +@@ -436,7 +450,8 @@ 1.152 1.153 static inline void INIT process_bit1(struct writer *wr, struct rc *rc, 1.154 struct cstate *cst, uint16_t *p, 1.155 - int pos_state, uint16_t *prob) { 1.156 -- int offset; 1.157 + int pos_state, uint16_t *prob, 1.158 + void(*error)(char *x)) { 1.159 -+ int offset; 1.160 + int offset; 1.161 uint16_t *prob_len; 1.162 int num_bits; 1.163 - int len; 1.164 +@@ -444,7 +459,7 @@ 1.165 1.166 rc_update_bit_1(rc, prob); 1.167 prob = p + LZMA_IS_REP + cst->state; 1.168 @@ -1560,13 +1458,11 @@ 1.169 rc_update_bit_0(rc, prob); 1.170 cst->rep3 = cst->rep2; 1.171 cst->rep2 = cst->rep1; 1.172 -@@ -453,14 +411,14 @@ 1.173 - prob = p + LZMA_LEN_CODER; 1.174 +@@ -454,13 +469,13 @@ 1.175 } else { 1.176 rc_update_bit_1(rc, prob); 1.177 -- prob += LZMA_IS_REP_G0 - LZMA_IS_REP; 1.178 + prob += LZMA_IS_REP_G0 - LZMA_IS_REP; 1.179 - if (rc_is_bit_0(rc, prob)) { 1.180 -+ prob = p + LZMA_IS_REP_G0 + cst->state; 1.181 + if (rc_is_bit_0(rc, prob, error)) { 1.182 rc_update_bit_0(rc, prob); 1.183 prob = (p + LZMA_IS_REP_0_LONG 1.184 @@ -1578,60 +1474,41 @@ 1.185 rc_update_bit_0(rc, prob); 1.186 1.187 cst->state = cst->state < LZMA_NUM_LIT_STATES ? 1.188 -@@ -474,14 +432,14 @@ 1.189 - uint32_t distance; 1.190 +@@ -475,13 +490,13 @@ 1.191 1.192 rc_update_bit_1(rc, prob); 1.193 -- prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0; 1.194 + prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0; 1.195 - if (rc_is_bit_0(rc, prob)) { 1.196 -+ prob = p + LZMA_IS_REP_G1 + cst->state; 1.197 + if (rc_is_bit_0(rc, prob, error)) { 1.198 rc_update_bit_0(rc, prob); 1.199 distance = cst->rep1; 1.200 } else { 1.201 rc_update_bit_1(rc, prob); 1.202 -- prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1; 1.203 + prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1; 1.204 - if (rc_is_bit_0(rc, prob)) { 1.205 -+ prob = p + LZMA_IS_REP_G2 + cst->state; 1.206 + if (rc_is_bit_0(rc, prob, error)) { 1.207 rc_update_bit_0(rc, prob); 1.208 distance = cst->rep2; 1.209 } else { 1.210 -@@ -499,33 +457,33 @@ 1.211 +@@ -499,7 +514,7 @@ 1.212 } 1.213 1.214 prob_len = prob + LZMA_LEN_CHOICE; 1.215 - if (rc_is_bit_0(rc, prob_len)) { 1.216 + if (rc_is_bit_0(rc, prob_len, error)) { 1.217 rc_update_bit_0(rc, prob_len); 1.218 -- prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE 1.219 -+ prob_len = (prob + LZMA_LEN_LOW 1.220 + prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE 1.221 + (pos_state << 1.222 -- LZMA_LEN_NUM_LOW_BITS); 1.223 -+ LZMA_LEN_NUM_LOW_BITS)); 1.224 - offset = 0; 1.225 - num_bits = LZMA_LEN_NUM_LOW_BITS; 1.226 +@@ -509,7 +524,7 @@ 1.227 } else { 1.228 rc_update_bit_1(rc, prob_len); 1.229 -- prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE; 1.230 + prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE; 1.231 - if (rc_is_bit_0(rc, prob_len)) { 1.232 -+ prob_len = prob + LZMA_LEN_CHOICE_2; 1.233 + if (rc_is_bit_0(rc, prob_len, error)) { 1.234 rc_update_bit_0(rc, prob_len); 1.235 -- prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 1.236 -+ prob_len = (prob + LZMA_LEN_MID 1.237 + prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 1.238 + (pos_state << 1.239 -- LZMA_LEN_NUM_MID_BITS); 1.240 -+ LZMA_LEN_NUM_MID_BITS)); 1.241 - offset = 1 << LZMA_LEN_NUM_LOW_BITS; 1.242 - num_bits = LZMA_LEN_NUM_MID_BITS; 1.243 - } else { 1.244 - rc_update_bit_1(rc, prob_len); 1.245 -- prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2; 1.246 -+ prob_len = prob + LZMA_LEN_HIGH; 1.247 - offset = ((1 << LZMA_LEN_NUM_LOW_BITS) 1.248 - + (1 << LZMA_LEN_NUM_MID_BITS)); 1.249 - num_bits = LZMA_LEN_NUM_HIGH_BITS; 1.250 +@@ -525,7 +540,7 @@ 1.251 } 1.252 } 1.253 1.254 @@ -1640,7 +1517,7 @@ 1.255 len += offset; 1.256 1.257 if (cst->state < 4) { 1.258 -@@ -540,7 +498,7 @@ 1.259 +@@ -540,7 +555,7 @@ 1.260 << LZMA_NUM_POS_SLOT_BITS); 1.261 rc_bit_tree_decode(rc, prob, 1.262 LZMA_NUM_POS_SLOT_BITS, 1.263 @@ -1649,7 +1526,7 @@ 1.264 if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { 1.265 int i, mi; 1.266 num_bits = (pos_slot >> 1) - 1; 1.267 -@@ -553,7 +511,7 @@ 1.268 +@@ -553,7 +568,7 @@ 1.269 num_bits -= LZMA_NUM_ALIGN_BITS; 1.270 while (num_bits--) 1.271 cst->rep0 = (cst->rep0 << 1) | 1.272 @@ -1658,7 +1535,7 @@ 1.273 prob = p + LZMA_ALIGN; 1.274 cst->rep0 <<= LZMA_NUM_ALIGN_BITS; 1.275 num_bits = LZMA_NUM_ALIGN_BITS; 1.276 -@@ -561,7 +519,7 @@ 1.277 +@@ -561,7 +576,7 @@ 1.278 i = 1; 1.279 mi = 1; 1.280 while (num_bits--) { 1.281 @@ -1667,7 +1544,7 @@ 1.282 cst->rep0 |= i; 1.283 i <<= 1; 1.284 } 1.285 -@@ -578,15 +536,14 @@ 1.286 +@@ -578,12 +593,12 @@ 1.287 1.288 1.289 1.290 @@ -1681,11 +1558,8 @@ 1.291 + void(*error)(char *x) 1.292 ) 1.293 { 1.294 -- extern int cpio_flush_buffer(void*, unsigned int); 1.295 - struct lzma_header header; 1.296 - int lc, pb, lp; 1.297 - uint32_t pos_state_mask; 1.298 -@@ -600,10 +557,6 @@ 1.299 + extern int cpio_flush_buffer(void*, unsigned int); 1.300 +@@ -600,10 +615,6 @@ 1.301 unsigned char *inbuf; 1.302 int ret = -1; 1.303 1.304 @@ -1696,16 +1570,7 @@ 1.305 if (buf) 1.306 inbuf = buf; 1.307 else 1.308 -@@ -621,16 +574,12 @@ 1.309 - wr.global_pos = 0; 1.310 - wr.previous_byte = 0; 1.311 - wr.buffer_pos = 0; 1.312 -- wr.is_cpio_flush = 0; 1.313 -- if (flush == cpio_flush_buffer) 1.314 -- wr.is_cpio_flush = 1; 1.315 -- wr.buffer_index = NULL; 1.316 - 1.317 - rc_init(&rc, fill, inbuf, in_len); 1.318 +@@ -630,7 +641,7 @@ 1.319 1.320 for (i = 0; i < sizeof(header); i++) { 1.321 if (rc.ptr >= rc.buffer_end) 1.322 @@ -1714,34 +1579,13 @@ 1.323 ((unsigned char *)&header)[i] = *rc.ptr++; 1.324 } 1.325 1.326 -@@ -658,34 +607,34 @@ 1.327 - if (header.dict_size == 0) 1.328 - header.dict_size = 1; 1.329 - 1.330 -- if (output || wr.is_cpio_flush) 1.331 -+ if (output) 1.332 - wr.buffer = output; 1.333 - else { 1.334 - wr.bufsize = MIN(header.dst_size, header.dict_size); 1.335 - wr.buffer = large_malloc(wr.bufsize); 1.336 - } 1.337 -- if (wr.buffer == NULL && !wr.is_cpio_flush) 1.338 -+ if (wr.buffer == NULL) 1.339 - goto exit_1; 1.340 - 1.341 - num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); 1.342 - p = (uint16_t *) large_malloc(num_probs * sizeof(*p)); 1.343 - if (p == 0) 1.344 - goto exit_2; 1.345 -- num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; 1.346 -+ num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp)); 1.347 +@@ -675,17 +686,17 @@ 1.348 for (i = 0; i < num_probs; i++) 1.349 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; 1.350 -- wr.max_index = wr.next_index = 0; 1.351 + wr.max_index = wr.next_index = 0; 1.352 - rc_init_code(&rc); 1.353 ++ rc_init_code(&rc, error); 1.354 1.355 -+ rc_init_code(&rc, error); 1.356 -+ 1.357 while (get_pos(&wr) < header.dst_size) { 1.358 int pos_state = get_pos(&wr) & pos_state_mask; 1.359 uint16_t *prob = p + LZMA_IS_MATCH + 1.360 @@ -1757,35 +1601,7 @@ 1.361 if (cst.rep0 == 0) 1.362 break; 1.363 } 1.364 -@@ -693,25 +642,12 @@ 1.365 - 1.366 - if (posp) 1.367 - *posp = rc.ptr-rc.buffer; 1.368 -- if (wr.is_cpio_flush) { 1.369 -- int i; 1.370 -- for (i = 0; i < wr.next_index -1; i++) { 1.371 -- wr.flush(wr.buffer_index[i], LZMA_IOBUF_SIZE); 1.372 -- large_free(wr.buffer_index[i]); 1.373 -- } 1.374 -- if (i < wr.next_index) { 1.375 -- wr.flush(wr.buffer_index[i], 1.376 -- wr.buffer_pos % LZMA_IOBUF_SIZE); 1.377 -- large_free(wr.buffer_index[i]); 1.378 -- } 1.379 -- large_free(wr.buffer_index); 1.380 -- } 1.381 -- else if (wr.flush) 1.382 -+ if (wr.flush) 1.383 - wr.flush(wr.buffer, wr.buffer_pos); 1.384 - ret = 0; 1.385 - large_free(p); 1.386 - exit_2: 1.387 -- if (!output && !wr.is_cpio_flush) 1.388 -+ if (!output) 1.389 - large_free(wr.buffer); 1.390 - exit_1: 1.391 - if (!buf) 1.392 -@@ -719,5 +655,19 @@ 1.393 +@@ -719,5 +730,19 @@ 1.394 exit_0: 1.395 return ret; 1.396 }