wok diff linux/stuff/linux-unlzma-2.6.30.4.u @ rev 3919
linux: fix build
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Tue Aug 18 19:22:04 2009 +0200 (2009-08-18) |
parents | 3f839259b89c |
children |
line diff
1.1 --- a/linux/stuff/linux-unlzma-2.6.30.4.u Mon Aug 17 16:45:47 2009 +0200 1.2 +++ b/linux/stuff/linux-unlzma-2.6.30.4.u Tue Aug 18 19:22:04 2009 +0200 1.3 @@ -39,42 +39,72 @@ 1.4 if (!wr->flush) { 1.5 int32_t pos; 1.6 while (offs > wr->header->dict_size) 1.7 -@@ -311,6 +323,34 @@ 1.8 +@@ -309,8 +321,41 @@ 1.9 1.10 + } 1.11 + 1.12 ++static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte) 1.13 ++{ 1.14 ++ if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) { 1.15 ++ // if the following large_malloc fails, the initramfs 1.16 ++ // whould not be load with is_cpio_flush forced 0 too. 1.17 ++ // Remember we do not allocate historic buffer. 1.18 ++ // Let's assume it will never fail ! 1.19 ++ if (wr->next_index >= wr->max_index) { 1.20 ++ // realloc wr->buffer_index 1.21 ++ uint8_t **p = wr->buffer_index; 1.22 ++ wr->buffer_index = (uint8_t **) 1.23 ++ large_malloc(LZMA_IOBUF_SIZE + 1.24 ++ sizeof(*p) * wr->max_index); 1.25 ++ if (wr->max_index) { 1.26 ++ memcpy(wr->buffer_index, p, 1.27 ++ sizeof(*p) * wr->max_index); 1.28 ++ free(p); 1.29 ++ } 1.30 ++ wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p); 1.31 ++ } 1.32 ++ wr->buffer_index[wr->next_index++] = 1.33 ++ (uint8_t *) large_malloc(LZMA_IOBUF_SIZE); 1.34 ++ } 1.35 ++ wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE] 1.36 ++ [wr->buffer_pos % LZMA_IOBUF_SIZE] = 1.37 ++ wr->previous_byte = byte; 1.38 ++ wr->buffer_pos++; 1.39 ++} 1.40 ++ 1.41 static inline void INIT write_byte(struct writer *wr, uint8_t byte) 1.42 { 1.43 + if (wr->is_cpio_flush) { 1.44 -+ if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) { 1.45 -+ // if the following large_malloc fails, the initramfs 1.46 -+ // whould not be load with is_cpio_flush forced 0 too. 1.47 -+ // Remember we do not allocate historic buffer. 1.48 -+ // Let's assume it will never fail ! 1.49 -+ if (wr->next_index >= wr->max_index) { 1.50 -+ // realloc wr->buffer_index 1.51 -+ uint8_t **p = wr->buffer_index; 1.52 -+ wr->buffer_index = (uint8_t **) 1.53 -+ large_malloc(LZMA_IOBUF_SIZE + 1.54 -+ sizeof(*p) * wr->max_index); 1.55 -+ if (wr->max_index) { 1.56 -+ memcpy(wr->buffer_index, p, 1.57 -+ sizeof(*p) * wr->max_index); 1.58 -+ free(p); 1.59 -+ } 1.60 -+ wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p); 1.61 -+ } 1.62 -+ wr->buffer_index[wr->next_index++] = 1.63 -+ (uint8_t *) large_malloc(LZMA_IOBUF_SIZE); 1.64 -+ } 1.65 -+ wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE] 1.66 -+ [wr->buffer_pos % LZMA_IOBUF_SIZE] = 1.67 -+ wr->previous_byte = byte; 1.68 -+ wr->buffer_pos++; 1.69 ++ write_byte_if_cpio(wr, byte); 1.70 + return; 1.71 + } 1.72 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; 1.73 if (wr->flush && wr->buffer_pos == wr->header->dict_size) { 1.74 wr->buffer_pos = 0; 1.75 -@@ -339,6 +379,9 @@ 1.76 +@@ -328,7 +373,21 @@ 1.77 + static inline void INIT copy_bytes(struct writer *wr, 1.78 + uint32_t rep0, int len) 1.79 + { 1.80 +- do { 1.81 ++ if (wr->is_cpio_flush) { 1.82 ++ int32_t pos; 1.83 ++ uint32_t offs = rep0; 1.84 ++ while (offs > wr->header->dict_size) 1.85 ++ offs -= wr->header->dict_size; 1.86 ++ pos = wr->buffer_pos - offs; 1.87 ++ do { 1.88 ++ write_byte_if_cpio(wr, 1.89 ++ wr->buffer_index[pos / LZMA_IOBUF_SIZE] 1.90 ++ [pos % LZMA_IOBUF_SIZE]); 1.91 ++ pos++; 1.92 ++ len--; 1.93 ++ } while (len != 0 && wr->buffer_pos < wr->header->dst_size); 1.94 ++ } 1.95 ++ else do { 1.96 + copy_byte(wr, rep0); 1.97 + len--; 1.98 + } while (len != 0 && wr->buffer_pos < wr->header->dst_size); 1.99 +@@ -339,6 +398,9 @@ 1.100 int pos_state, uint16_t *prob, 1.101 int lc, uint32_t literal_pos_mask) { 1.102 int mi = 1; 1.103 @@ -84,7 +114,7 @@ 1.104 rc_update_bit_0(rc, prob); 1.105 prob = (p + LZMA_LITERAL + 1.106 (LZMA_LIT_SIZE 1.107 -@@ -369,18 +412,13 @@ 1.108 +@@ -369,18 +431,13 @@ 1.109 rc_get_bit(rc, prob_lit, &mi); 1.110 } 1.111 write_byte(wr, mi); 1.112 @@ -105,7 +135,7 @@ 1.113 uint16_t *prob_len; 1.114 int num_bits; 1.115 int len; 1.116 -@@ -396,7 +434,7 @@ 1.117 +@@ -396,7 +453,7 @@ 1.118 prob = p + LZMA_LEN_CODER; 1.119 } else { 1.120 rc_update_bit_1(rc, prob); 1.121 @@ -114,7 +144,7 @@ 1.122 if (rc_is_bit_0(rc, prob)) { 1.123 rc_update_bit_0(rc, prob); 1.124 prob = (p + LZMA_IS_REP_0_LONG 1.125 -@@ -417,13 +455,13 @@ 1.126 +@@ -417,13 +474,13 @@ 1.127 uint32_t distance; 1.128 1.129 rc_update_bit_1(rc, prob); 1.130 @@ -130,14 +160,15 @@ 1.131 if (rc_is_bit_0(rc, prob)) { 1.132 rc_update_bit_0(rc, prob); 1.133 distance = cst->rep2; 1.134 -@@ -444,24 +482,24 @@ 1.135 +@@ -444,24 +501,24 @@ 1.136 prob_len = prob + LZMA_LEN_CHOICE; 1.137 if (rc_is_bit_0(rc, prob_len)) { 1.138 rc_update_bit_0(rc, prob_len); 1.139 - prob_len = (prob + LZMA_LEN_LOW 1.140 + prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE 1.141 + (pos_state << 1.142 - LZMA_LEN_NUM_LOW_BITS)); 1.143 +- LZMA_LEN_NUM_LOW_BITS)); 1.144 ++ LZMA_LEN_NUM_LOW_BITS); 1.145 offset = 0; 1.146 num_bits = LZMA_LEN_NUM_LOW_BITS; 1.147 } else { 1.148 @@ -149,7 +180,8 @@ 1.149 - prob_len = (prob + LZMA_LEN_MID 1.150 + prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 1.151 + (pos_state << 1.152 - LZMA_LEN_NUM_MID_BITS)); 1.153 +- LZMA_LEN_NUM_MID_BITS)); 1.154 ++ LZMA_LEN_NUM_MID_BITS); 1.155 offset = 1 << LZMA_LEN_NUM_LOW_BITS; 1.156 num_bits = LZMA_LEN_NUM_MID_BITS; 1.157 } else { 1.158 @@ -159,7 +191,7 @@ 1.159 offset = ((1 << LZMA_LEN_NUM_LOW_BITS) 1.160 + (1 << LZMA_LEN_NUM_MID_BITS)); 1.161 num_bits = LZMA_LEN_NUM_HIGH_BITS; 1.162 -@@ -529,6 +567,7 @@ 1.163 +@@ -529,6 +586,7 @@ 1.164 void(*error_fn)(char *x) 1.165 ) 1.166 { 1.167 @@ -167,7 +199,7 @@ 1.168 struct lzma_header header; 1.169 int lc, pb, lp; 1.170 uint32_t pos_state_mask; 1.171 -@@ -563,6 +602,10 @@ 1.172 +@@ -563,6 +621,10 @@ 1.173 wr.global_pos = 0; 1.174 wr.previous_byte = 0; 1.175 wr.buffer_pos = 0; 1.176 @@ -178,7 +210,7 @@ 1.177 1.178 rc_init(&rc, fill, inbuf, in_len); 1.179 1.180 -@@ -596,23 +639,23 @@ 1.181 +@@ -596,23 +658,23 @@ 1.182 if (header.dict_size == 0) 1.183 header.dict_size = 1; 1.184 1.185 @@ -206,7 +238,7 @@ 1.186 rc_init_code(&rc); 1.187 1.188 while (get_pos(&wr) < header.dst_size) { 1.189 -@@ -631,12 +674,25 @@ 1.190 +@@ -631,12 +693,25 @@ 1.191 1.192 if (posp) 1.193 *posp = rc.ptr-rc.buffer;