# HG changeset patch # User Pascal Bellard # Date 1268089763 -3600 # Node ID 6359032279ef941e1129277b7300a9bcc985f8cf # Parent 68b326a153e2d05ec36a83dbd1a7b037f4450052 linux: squashfs & lzma patches should be compatible diff -r 68b326a153e2 -r 6359032279ef linux/stuff/linux-squashfs-lzma-2.6.30.6.u --- a/linux/stuff/linux-squashfs-lzma-2.6.30.6.u Mon Mar 08 13:52:48 2010 +0000 +++ b/linux/stuff/linux-squashfs-lzma-2.6.30.6.u Tue Mar 09 00:09:23 2010 +0100 @@ -1355,7 +1355,7 @@ */ -static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p) +static inline uint32_t INIT rc_is_bit_0_helper(struct rc *rc, uint16_t *p, -+ void (*error)(char *x)) ++ void (*error)(char *x)) { - rc_normalize(rc); + rc_normalize(rc, error); @@ -1411,98 +1411,7 @@ *symbol -= 1 << num_levels; } -@@ -278,10 +291,6 @@ - size_t global_pos; - int(*flush)(void*, unsigned int); - struct lzma_header *header; -- int is_cpio_flush; -- uint8_t **buffer_index; -- int next_index; -- int max_index; - }; - - struct cstate { -@@ -298,14 +307,6 @@ - static inline uint8_t INIT peek_old_byte(struct writer *wr, - uint32_t offs) - { -- if (wr->is_cpio_flush) { -- int32_t pos; -- while (offs > wr->header->dict_size) -- offs -= wr->header->dict_size; -- pos = wr->buffer_pos - offs; -- return wr->buffer_index[pos / LZMA_IOBUF_SIZE] -- [pos % LZMA_IOBUF_SIZE]; -- } - if (!wr->flush) { - int32_t pos; - while (offs > wr->header->dict_size) -@@ -321,41 +322,8 @@ - - } - --static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte) --{ -- if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) { -- // if the following large_malloc fails, the initramfs -- // whould not be load with is_cpio_flush forced 0 too. -- // Remember we do not allocate historic buffer. -- // Let's assume it will never fail ! -- if (wr->next_index >= wr->max_index) { -- // realloc wr->buffer_index -- uint8_t **p = wr->buffer_index; -- wr->buffer_index = (uint8_t **) -- large_malloc(LZMA_IOBUF_SIZE + -- sizeof(*p) * wr->max_index); -- if (wr->max_index) { -- memcpy(wr->buffer_index, p, -- sizeof(*p) * wr->max_index); -- free(p); -- } -- wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p); -- } -- wr->buffer_index[wr->next_index++] = -- (uint8_t *) large_malloc(LZMA_IOBUF_SIZE); -- } -- wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE] -- [wr->buffer_pos % LZMA_IOBUF_SIZE] = -- wr->previous_byte = byte; -- wr->buffer_pos++; --} -- - static inline void INIT write_byte(struct writer *wr, uint8_t byte) - { -- if (wr->is_cpio_flush) { -- write_byte_if_cpio(wr, byte); -- return; -- } - wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte; - if (wr->flush && wr->buffer_pos == wr->header->dict_size) { - wr->buffer_pos = 0; -@@ -373,21 +341,7 @@ - static inline void INIT copy_bytes(struct writer *wr, - uint32_t rep0, int len) - { -- if (wr->is_cpio_flush) { -- int32_t pos; -- uint32_t offs = rep0; -- while (offs > wr->header->dict_size) -- offs -= wr->header->dict_size; -- pos = wr->buffer_pos - offs; -- do { -- write_byte_if_cpio(wr, -- wr->buffer_index[pos / LZMA_IOBUF_SIZE] -- [pos % LZMA_IOBUF_SIZE]); -- pos++; -- len--; -- } while (len != 0 && wr->buffer_pos < wr->header->dst_size); -- } -- else do { -+ do { - copy_byte(wr, rep0); - len--; - } while (len != 0 && wr->buffer_pos < wr->header->dst_size); -@@ -396,11 +350,9 @@ +@@ -396,7 +409,8 @@ static inline void INIT process_bit0(struct writer *wr, struct rc *rc, struct cstate *cst, uint16_t *p, int pos_state, uint16_t *prob, @@ -1510,13 +1419,9 @@ + int lc, uint32_t literal_pos_mask, + void(*error)(char *x)) { int mi = 1; -- static const int state[LZMA_NUM_STATES] = -- { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; -- - rc_update_bit_0(rc, prob); - prob = (p + LZMA_LITERAL + - (LZMA_LIT_SIZE -@@ -417,7 +369,7 @@ + static const int state[LZMA_NUM_STATES] = + { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 }; +@@ -417,7 +431,7 @@ match_byte <<= 1; bit = match_byte & 0x100; prob_lit = prob + 0x100 + bit + mi; @@ -1525,7 +1430,7 @@ if (!bit) break; } else { -@@ -428,23 +380,29 @@ +@@ -428,7 +442,7 @@ } while (mi < 0x100) { uint16_t *prob_lit = prob + mi; @@ -1533,25 +1438,18 @@ + rc_get_bit(rc, prob_lit, &mi, error); } write_byte(wr, mi); -- cst->state = state[cst->state]; -+ if (cst->state < 4) -+ cst->state = 0; -+ else if (cst->state < 10) -+ cst->state -= 3; -+ else -+ cst->state -= 6; - } + cst->state = state[cst->state]; +@@ -436,7 +450,8 @@ static inline void INIT process_bit1(struct writer *wr, struct rc *rc, struct cstate *cst, uint16_t *p, - int pos_state, uint16_t *prob) { -- int offset; + int pos_state, uint16_t *prob, + void(*error)(char *x)) { -+ int offset; + int offset; uint16_t *prob_len; int num_bits; - int len; +@@ -444,7 +459,7 @@ rc_update_bit_1(rc, prob); prob = p + LZMA_IS_REP + cst->state; @@ -1560,13 +1458,11 @@ rc_update_bit_0(rc, prob); cst->rep3 = cst->rep2; cst->rep2 = cst->rep1; -@@ -453,14 +411,14 @@ - prob = p + LZMA_LEN_CODER; +@@ -454,13 +469,13 @@ } else { rc_update_bit_1(rc, prob); -- prob += LZMA_IS_REP_G0 - LZMA_IS_REP; + prob += LZMA_IS_REP_G0 - LZMA_IS_REP; - if (rc_is_bit_0(rc, prob)) { -+ prob = p + LZMA_IS_REP_G0 + cst->state; + if (rc_is_bit_0(rc, prob, error)) { rc_update_bit_0(rc, prob); prob = (p + LZMA_IS_REP_0_LONG @@ -1578,60 +1474,41 @@ rc_update_bit_0(rc, prob); cst->state = cst->state < LZMA_NUM_LIT_STATES ? -@@ -474,14 +432,14 @@ - uint32_t distance; +@@ -475,13 +490,13 @@ rc_update_bit_1(rc, prob); -- prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0; + prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0; - if (rc_is_bit_0(rc, prob)) { -+ prob = p + LZMA_IS_REP_G1 + cst->state; + if (rc_is_bit_0(rc, prob, error)) { rc_update_bit_0(rc, prob); distance = cst->rep1; } else { rc_update_bit_1(rc, prob); -- prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1; + prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1; - if (rc_is_bit_0(rc, prob)) { -+ prob = p + LZMA_IS_REP_G2 + cst->state; + if (rc_is_bit_0(rc, prob, error)) { rc_update_bit_0(rc, prob); distance = cst->rep2; } else { -@@ -499,33 +457,33 @@ +@@ -499,7 +514,7 @@ } prob_len = prob + LZMA_LEN_CHOICE; - if (rc_is_bit_0(rc, prob_len)) { + if (rc_is_bit_0(rc, prob_len, error)) { rc_update_bit_0(rc, prob_len); -- prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE -+ prob_len = (prob + LZMA_LEN_LOW + prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE + (pos_state << -- LZMA_LEN_NUM_LOW_BITS); -+ LZMA_LEN_NUM_LOW_BITS)); - offset = 0; - num_bits = LZMA_LEN_NUM_LOW_BITS; +@@ -509,7 +524,7 @@ } else { rc_update_bit_1(rc, prob_len); -- prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE; + prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE; - if (rc_is_bit_0(rc, prob_len)) { -+ prob_len = prob + LZMA_LEN_CHOICE_2; + if (rc_is_bit_0(rc, prob_len, error)) { rc_update_bit_0(rc, prob_len); -- prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 -+ prob_len = (prob + LZMA_LEN_MID + prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2 + (pos_state << -- LZMA_LEN_NUM_MID_BITS); -+ LZMA_LEN_NUM_MID_BITS)); - offset = 1 << LZMA_LEN_NUM_LOW_BITS; - num_bits = LZMA_LEN_NUM_MID_BITS; - } else { - rc_update_bit_1(rc, prob_len); -- prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2; -+ prob_len = prob + LZMA_LEN_HIGH; - offset = ((1 << LZMA_LEN_NUM_LOW_BITS) - + (1 << LZMA_LEN_NUM_MID_BITS)); - num_bits = LZMA_LEN_NUM_HIGH_BITS; +@@ -525,7 +540,7 @@ } } @@ -1640,7 +1517,7 @@ len += offset; if (cst->state < 4) { -@@ -540,7 +498,7 @@ +@@ -540,7 +555,7 @@ << LZMA_NUM_POS_SLOT_BITS); rc_bit_tree_decode(rc, prob, LZMA_NUM_POS_SLOT_BITS, @@ -1649,7 +1526,7 @@ if (pos_slot >= LZMA_START_POS_MODEL_INDEX) { int i, mi; num_bits = (pos_slot >> 1) - 1; -@@ -553,7 +511,7 @@ +@@ -553,7 +568,7 @@ num_bits -= LZMA_NUM_ALIGN_BITS; while (num_bits--) cst->rep0 = (cst->rep0 << 1) | @@ -1658,7 +1535,7 @@ prob = p + LZMA_ALIGN; cst->rep0 <<= LZMA_NUM_ALIGN_BITS; num_bits = LZMA_NUM_ALIGN_BITS; -@@ -561,7 +519,7 @@ +@@ -561,7 +576,7 @@ i = 1; mi = 1; while (num_bits--) { @@ -1667,7 +1544,7 @@ cst->rep0 |= i; i <<= 1; } -@@ -578,15 +536,14 @@ +@@ -578,12 +593,12 @@ @@ -1681,11 +1558,8 @@ + void(*error)(char *x) ) { -- extern int cpio_flush_buffer(void*, unsigned int); - struct lzma_header header; - int lc, pb, lp; - uint32_t pos_state_mask; -@@ -600,10 +557,6 @@ + extern int cpio_flush_buffer(void*, unsigned int); +@@ -600,10 +615,6 @@ unsigned char *inbuf; int ret = -1; @@ -1696,16 +1570,7 @@ if (buf) inbuf = buf; else -@@ -621,16 +574,12 @@ - wr.global_pos = 0; - wr.previous_byte = 0; - wr.buffer_pos = 0; -- wr.is_cpio_flush = 0; -- if (flush == cpio_flush_buffer) -- wr.is_cpio_flush = 1; -- wr.buffer_index = NULL; - - rc_init(&rc, fill, inbuf, in_len); +@@ -630,7 +641,7 @@ for (i = 0; i < sizeof(header); i++) { if (rc.ptr >= rc.buffer_end) @@ -1714,34 +1579,13 @@ ((unsigned char *)&header)[i] = *rc.ptr++; } -@@ -658,34 +607,34 @@ - if (header.dict_size == 0) - header.dict_size = 1; - -- if (output || wr.is_cpio_flush) -+ if (output) - wr.buffer = output; - else { - wr.bufsize = MIN(header.dst_size, header.dict_size); - wr.buffer = large_malloc(wr.bufsize); - } -- if (wr.buffer == NULL && !wr.is_cpio_flush) -+ if (wr.buffer == NULL) - goto exit_1; - - num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp)); - p = (uint16_t *) large_malloc(num_probs * sizeof(*p)); - if (p == 0) - goto exit_2; -- num_probs += LZMA_LITERAL - LZMA_BASE_SIZE; -+ num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp)); +@@ -675,17 +686,17 @@ for (i = 0; i < num_probs; i++) p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1; -- wr.max_index = wr.next_index = 0; + wr.max_index = wr.next_index = 0; - rc_init_code(&rc); ++ rc_init_code(&rc, error); -+ rc_init_code(&rc, error); -+ while (get_pos(&wr) < header.dst_size) { int pos_state = get_pos(&wr) & pos_state_mask; uint16_t *prob = p + LZMA_IS_MATCH + @@ -1757,35 +1601,7 @@ if (cst.rep0 == 0) break; } -@@ -693,25 +642,12 @@ - - if (posp) - *posp = rc.ptr-rc.buffer; -- if (wr.is_cpio_flush) { -- int i; -- for (i = 0; i < wr.next_index -1; i++) { -- wr.flush(wr.buffer_index[i], LZMA_IOBUF_SIZE); -- large_free(wr.buffer_index[i]); -- } -- if (i < wr.next_index) { -- wr.flush(wr.buffer_index[i], -- wr.buffer_pos % LZMA_IOBUF_SIZE); -- large_free(wr.buffer_index[i]); -- } -- large_free(wr.buffer_index); -- } -- else if (wr.flush) -+ if (wr.flush) - wr.flush(wr.buffer, wr.buffer_pos); - ret = 0; - large_free(p); - exit_2: -- if (!output && !wr.is_cpio_flush) -+ if (!output) - large_free(wr.buffer); - exit_1: - if (!buf) -@@ -719,5 +655,19 @@ +@@ -719,5 +730,19 @@ exit_0: return ret; }