wok-stable diff linux/stuff/linux-unlzma-2.6.37.u @ rev 11439

up: putty 0.62
author Antoine Bodin <gokhlayeh@slitaz.org>
date Fri Dec 16 15:42:01 2011 +0100 (2011-12-16)
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/linux/stuff/linux-unlzma-2.6.37.u	Fri Dec 16 15:42:01 2011 +0100
     1.3 @@ -0,0 +1,268 @@
     1.4 +--- linux-2.6.30.4/init/initramfs.c
     1.5 ++++ linux-2.6.30.4/init/initramfs.c
     1.6 +@@ -425,7 +425,8 @@
     1.7 + 	return len - count;
     1.8 + }
     1.9 + 
    1.10 +-static int __init flush_buffer(void *bufv, unsigned len)
    1.11 ++#define flush_buffer cpio_flush_buffer
    1.12 ++int __init flush_buffer(void *bufv, unsigned len)
    1.13 + {
    1.14 + 	char *buf = (char *) bufv;
    1.15 + 	int written;
    1.16 +
    1.17 +--- linux-2.6.30.4/lib/decompress_unlzma.c
    1.18 ++++ linux-2.6.30.4/lib/decompress_unlzma.c
    1.19 +@@ -278,6 +278,10 @@
    1.20 + 	size_t global_pos;
    1.21 + 	int(*flush)(void*, unsigned int);
    1.22 + 	struct lzma_header *header;
    1.23 ++	int is_cpio_flush;
    1.24 ++	uint8_t **buffer_index;
    1.25 ++	int next_index;
    1.26 ++	int max_index;
    1.27 + };
    1.28 + 
    1.29 + struct cstate {
    1.30 +@@ -294,6 +298,14 @@
    1.31 + static inline uint8_t INIT peek_old_byte(struct writer *wr,
    1.32 + 						uint32_t offs)
    1.33 + {
    1.34 ++	if (wr->is_cpio_flush) {
    1.35 ++		int32_t pos;
    1.36 ++		while (offs > wr->header->dict_size)
    1.37 ++			offs -= wr->header->dict_size;
    1.38 ++		pos = wr->buffer_pos - offs;
    1.39 ++		return wr->buffer_index[pos / LZMA_IOBUF_SIZE]
    1.40 ++				       [pos % LZMA_IOBUF_SIZE];
    1.41 ++	}
    1.42 + 	if (!wr->flush) {
    1.43 + 		int32_t pos;
    1.44 + 		while (offs > wr->header->dict_size)
    1.45 +@@ -309,8 +321,41 @@
    1.46 + 
    1.47 + }
    1.48 + 
    1.49 ++static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte)
    1.50 ++{
    1.51 ++	if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) {
    1.52 ++		// if the following large_malloc fails, the initramfs
    1.53 ++		// whould not be load with is_cpio_flush forced 0 too.
    1.54 ++		// Remember we do not allocate historic buffer.
    1.55 ++		// Let's assume it will never fail !
    1.56 ++		if (wr->next_index >= wr->max_index) {
    1.57 ++			// realloc wr->buffer_index
    1.58 ++			uint8_t **p = wr->buffer_index;
    1.59 ++			wr->buffer_index = (uint8_t **) 
    1.60 ++				large_malloc(LZMA_IOBUF_SIZE + 
    1.61 ++					    sizeof(*p) * wr->max_index);
    1.62 ++			if (wr->max_index) {
    1.63 ++				memcpy(wr->buffer_index, p,
    1.64 ++				       sizeof(*p) * wr->max_index);
    1.65 ++				free(p);
    1.66 ++			}
    1.67 ++			wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p);
    1.68 ++		}
    1.69 ++		wr->buffer_index[wr->next_index++] =
    1.70 ++			(uint8_t *) large_malloc(LZMA_IOBUF_SIZE);
    1.71 ++	}
    1.72 ++	wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE]
    1.73 ++			[wr->buffer_pos % LZMA_IOBUF_SIZE] =
    1.74 ++		wr->previous_byte = byte;
    1.75 ++	wr->buffer_pos++;
    1.76 ++}
    1.77 ++
    1.78 + static inline void INIT write_byte(struct writer *wr, uint8_t byte)
    1.79 + {
    1.80 ++	if (wr->is_cpio_flush) {
    1.81 ++		write_byte_if_cpio(wr, byte);
    1.82 ++		return;
    1.83 ++	}
    1.84 + 	wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
    1.85 + 	if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
    1.86 + 		wr->buffer_pos = 0;
    1.87 +@@ -328,7 +373,21 @@
    1.88 + static inline void INIT copy_bytes(struct writer *wr,
    1.89 + 					 uint32_t rep0, int len)
    1.90 + {
    1.91 +-	do {
    1.92 ++	if (wr->is_cpio_flush) {
    1.93 ++		int32_t pos;
    1.94 ++		uint32_t offs = rep0;
    1.95 ++		while (offs > wr->header->dict_size)
    1.96 ++			offs -= wr->header->dict_size;
    1.97 ++		pos = wr->buffer_pos - offs;
    1.98 ++		do {
    1.99 ++			write_byte_if_cpio(wr, 
   1.100 ++				wr->buffer_index[pos / LZMA_IOBUF_SIZE]
   1.101 ++						[pos % LZMA_IOBUF_SIZE]);
   1.102 ++			pos++;
   1.103 ++			len--;
   1.104 ++		} while (len != 0 && wr->buffer_pos < wr->header->dst_size);
   1.105 ++	}
   1.106 ++	else do {
   1.107 + 		copy_byte(wr, rep0);
   1.108 + 		len--;
   1.109 + 	} while (len != 0 && wr->buffer_pos < wr->header->dst_size);
   1.110 +@@ -339,6 +398,9 @@
   1.111 + 				     int pos_state, uint16_t *prob,
   1.112 + 				     int lc, uint32_t literal_pos_mask) {
   1.113 + 	int mi = 1;
   1.114 ++	static const int state[LZMA_NUM_STATES] = 
   1.115 ++		{ 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
   1.116 ++
   1.117 + 	rc_update_bit_0(rc, prob);
   1.118 + 	prob = (p + LZMA_LITERAL +
   1.119 + 		(LZMA_LIT_SIZE
   1.120 +@@ -369,18 +431,13 @@
   1.121 + 		rc_get_bit(rc, prob_lit, &mi);
   1.122 + 	}
   1.123 + 	write_byte(wr, mi);
   1.124 +-	if (cst->state < 4)
   1.125 +-		cst->state = 0;
   1.126 +-	else if (cst->state < 10)
   1.127 +-		cst->state -= 3;
   1.128 +-	else
   1.129 +-		cst->state -= 6;
   1.130 ++	cst->state = state[cst->state];
   1.131 + }
   1.132 + 
   1.133 + static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
   1.134 + 					    struct cstate *cst, uint16_t *p,
   1.135 + 					    int pos_state, uint16_t *prob) {
   1.136 +-  int offset;
   1.137 ++	int offset;
   1.138 + 	uint16_t *prob_len;
   1.139 + 	int num_bits;
   1.140 + 	int len;
   1.141 +@@ -396,7 +453,7 @@
   1.142 + 		prob = p + LZMA_LEN_CODER;
   1.143 + 	} else {
   1.144 + 		rc_update_bit_1(rc, prob);
   1.145 +-		prob = p + LZMA_IS_REP_G0 + cst->state;
   1.146 ++		prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
   1.147 + 		if (rc_is_bit_0(rc, prob)) {
   1.148 + 			rc_update_bit_0(rc, prob);
   1.149 + 			prob = (p + LZMA_IS_REP_0_LONG
   1.150 +@@ -417,13 +474,13 @@
   1.151 + 			uint32_t distance;
   1.152 + 
   1.153 + 			rc_update_bit_1(rc, prob);
   1.154 +-			prob = p + LZMA_IS_REP_G1 + cst->state;
   1.155 ++			prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
   1.156 + 			if (rc_is_bit_0(rc, prob)) {
   1.157 + 				rc_update_bit_0(rc, prob);
   1.158 + 				distance = cst->rep1;
   1.159 + 			} else {
   1.160 + 				rc_update_bit_1(rc, prob);
   1.161 +-				prob = p + LZMA_IS_REP_G2 + cst->state;
   1.162 ++				prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
   1.163 + 				if (rc_is_bit_0(rc, prob)) {
   1.164 + 					rc_update_bit_0(rc, prob);
   1.165 + 					distance = cst->rep2;
   1.166 +@@ -444,24 +501,24 @@
   1.167 + 	prob_len = prob + LZMA_LEN_CHOICE;
   1.168 + 	if (rc_is_bit_0(rc, prob_len)) {
   1.169 + 		rc_update_bit_0(rc, prob_len);
   1.170 +-		prob_len = (prob + LZMA_LEN_LOW
   1.171 ++		prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
   1.172 + 			    + (pos_state <<
   1.173 +-			       LZMA_LEN_NUM_LOW_BITS));
   1.174 ++			       LZMA_LEN_NUM_LOW_BITS);
   1.175 + 		offset = 0;
   1.176 + 		num_bits = LZMA_LEN_NUM_LOW_BITS;
   1.177 + 	} else {
   1.178 + 		rc_update_bit_1(rc, prob_len);
   1.179 +-		prob_len = prob + LZMA_LEN_CHOICE_2;
   1.180 ++		prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
   1.181 + 		if (rc_is_bit_0(rc, prob_len)) {
   1.182 + 			rc_update_bit_0(rc, prob_len);
   1.183 +-			prob_len = (prob + LZMA_LEN_MID
   1.184 ++			prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
   1.185 + 				    + (pos_state <<
   1.186 +-				       LZMA_LEN_NUM_MID_BITS));
   1.187 ++				       LZMA_LEN_NUM_MID_BITS);
   1.188 + 			offset = 1 << LZMA_LEN_NUM_LOW_BITS;
   1.189 + 			num_bits = LZMA_LEN_NUM_MID_BITS;
   1.190 + 		} else {
   1.191 + 			rc_update_bit_1(rc, prob_len);
   1.192 +-			prob_len = prob + LZMA_LEN_HIGH;
   1.193 ++			prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
   1.194 + 			offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
   1.195 + 				  + (1 << LZMA_LEN_NUM_MID_BITS));
   1.196 + 			num_bits = LZMA_LEN_NUM_HIGH_BITS;
   1.197 +@@ -529,6 +586,7 @@
   1.198 + 			      void(*error_fn)(char *x)
   1.199 + 	)
   1.200 + {
   1.201 ++	extern int cpio_flush_buffer(void*, unsigned int);
   1.202 + 	struct lzma_header header;
   1.203 + 	int lc, pb, lp;
   1.204 + 	uint32_t pos_state_mask;
   1.205 +@@ -563,6 +621,10 @@
   1.206 + 	wr.global_pos = 0;
   1.207 + 	wr.previous_byte = 0;
   1.208 + 	wr.buffer_pos = 0;
   1.209 ++	wr.is_cpio_flush = 0;
   1.210 ++	if (flush == cpio_flush_buffer)
   1.211 ++		wr.is_cpio_flush = 1;
   1.212 ++	wr.buffer_index = NULL;
   1.213 + 
   1.214 + 	rc_init(&rc, fill, inbuf, in_len);
   1.215 + 
   1.216 +@@ -596,23 +658,23 @@
   1.217 + 	if (header.dict_size == 0)
   1.218 + 		header.dict_size = 1;
   1.219 + 
   1.220 +-	if (output)
   1.221 ++	if (output || wr.is_cpio_flush)
   1.222 + 		wr.buffer = output;
   1.223 + 	else {
   1.224 + 		wr.bufsize = MIN(header.dst_size, header.dict_size);
   1.225 + 		wr.buffer = large_malloc(wr.bufsize);
   1.226 + 	}
   1.227 +-	if (wr.buffer == NULL)
   1.228 ++	if (wr.buffer == NULL && !wr.is_cpio_flush)
   1.229 + 		goto exit_1;
   1.230 + 
   1.231 + 	num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
   1.232 + 	p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
   1.233 + 	if (p == 0)
   1.234 + 		goto exit_2;
   1.235 +-	num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
   1.236 ++	num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
   1.237 + 	for (i = 0; i < num_probs; i++)
   1.238 + 		p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
   1.239 +-
   1.240 ++	wr.max_index = wr.next_index = 0;
   1.241 + 	rc_init_code(&rc);
   1.242 + 
   1.243 + 	while (get_pos(&wr) < header.dst_size) {
   1.244 +@@ -631,12 +693,25 @@
   1.245 + 
   1.246 + 	if (posp)
   1.247 + 		*posp = rc.ptr-rc.buffer;
   1.248 +-	if (wr.flush)
   1.249 ++	if (wr.is_cpio_flush) {
   1.250 ++		int i;
   1.251 ++		for (i = 0; i < wr.next_index -1; i++) {
   1.252 ++			wr.flush(wr.buffer_index[i], LZMA_IOBUF_SIZE);
   1.253 ++			large_free(wr.buffer_index[i]);
   1.254 ++		}
   1.255 ++		if (i < wr.next_index) {
   1.256 ++			wr.flush(wr.buffer_index[i], 
   1.257 ++				 wr.buffer_pos % LZMA_IOBUF_SIZE);
   1.258 ++			large_free(wr.buffer_index[i]);
   1.259 ++		}
   1.260 ++		large_free(wr.buffer_index);
   1.261 ++	}
   1.262 ++	else if (wr.flush)
   1.263 + 		wr.flush(wr.buffer, wr.buffer_pos);
   1.264 + 	ret = 0;
   1.265 + 	large_free(p);
   1.266 + exit_2:
   1.267 +-	if (!output)
   1.268 ++	if (!output && !wr.is_cpio_flush)
   1.269 + 		large_free(wr.buffer);
   1.270 + exit_1:
   1.271 + 	if (!buf)