wok annotate linux/stuff/linux-unlzma-2.6.30.6.u @ rev 4785

python: back to 2.5.1. Unwanted commit.
author Eric Joseph-Alexandre <erjo@slitaz.org>
date Sat Jan 16 23:07:49 2010 +0100 (2010-01-16)
parents
children
rev   line source
pankso@4056 1 --- linux-2.6.30.4/init/initramfs.c
pankso@4056 2 +++ linux-2.6.30.4/init/initramfs.c
pankso@4056 3 @@ -425,7 +425,8 @@
pankso@4056 4 return len - count;
pankso@4056 5 }
pankso@4056 6
pankso@4056 7 -static int __init flush_buffer(void *bufv, unsigned len)
pankso@4056 8 +#define flush_buffer cpio_flush_buffer
pankso@4056 9 +int __init flush_buffer(void *bufv, unsigned len)
pankso@4056 10 {
pankso@4056 11 char *buf = (char *) bufv;
pankso@4056 12 int written;
pankso@4056 13
pankso@4056 14 --- linux-2.6.30.4/lib/decompress_unlzma.c
pankso@4056 15 +++ linux-2.6.30.4/lib/decompress_unlzma.c
pankso@4056 16 @@ -278,6 +278,10 @@
pankso@4056 17 size_t global_pos;
pankso@4056 18 int(*flush)(void*, unsigned int);
pankso@4056 19 struct lzma_header *header;
pankso@4056 20 + int is_cpio_flush;
pankso@4056 21 + uint8_t **buffer_index;
pankso@4056 22 + int next_index;
pankso@4056 23 + int max_index;
pankso@4056 24 };
pankso@4056 25
pankso@4056 26 struct cstate {
pankso@4056 27 @@ -294,6 +298,14 @@
pankso@4056 28 static inline uint8_t INIT peek_old_byte(struct writer *wr,
pankso@4056 29 uint32_t offs)
pankso@4056 30 {
pankso@4056 31 + if (wr->is_cpio_flush) {
pankso@4056 32 + int32_t pos;
pankso@4056 33 + while (offs > wr->header->dict_size)
pankso@4056 34 + offs -= wr->header->dict_size;
pankso@4056 35 + pos = wr->buffer_pos - offs;
pankso@4056 36 + return wr->buffer_index[pos / LZMA_IOBUF_SIZE]
pankso@4056 37 + [pos % LZMA_IOBUF_SIZE];
pankso@4056 38 + }
pankso@4056 39 if (!wr->flush) {
pankso@4056 40 int32_t pos;
pankso@4056 41 while (offs > wr->header->dict_size)
pankso@4056 42 @@ -309,8 +321,41 @@
pankso@4056 43
pankso@4056 44 }
pankso@4056 45
pankso@4056 46 +static inline void INIT write_byte_if_cpio(struct writer *wr, uint8_t byte)
pankso@4056 47 +{
pankso@4056 48 + if (wr->buffer_pos % LZMA_IOBUF_SIZE == 0) {
pankso@4056 49 + // if the following large_malloc fails, the initramfs
pankso@4056 50 + // whould not be load with is_cpio_flush forced 0 too.
pankso@4056 51 + // Remember we do not allocate historic buffer.
pankso@4056 52 + // Let's assume it will never fail !
pankso@4056 53 + if (wr->next_index >= wr->max_index) {
pankso@4056 54 + // realloc wr->buffer_index
pankso@4056 55 + uint8_t **p = wr->buffer_index;
pankso@4056 56 + wr->buffer_index = (uint8_t **)
pankso@4056 57 + large_malloc(LZMA_IOBUF_SIZE +
pankso@4056 58 + sizeof(*p) * wr->max_index);
pankso@4056 59 + if (wr->max_index) {
pankso@4056 60 + memcpy(wr->buffer_index, p,
pankso@4056 61 + sizeof(*p) * wr->max_index);
pankso@4056 62 + free(p);
pankso@4056 63 + }
pankso@4056 64 + wr->max_index += LZMA_IOBUF_SIZE / sizeof(*p);
pankso@4056 65 + }
pankso@4056 66 + wr->buffer_index[wr->next_index++] =
pankso@4056 67 + (uint8_t *) large_malloc(LZMA_IOBUF_SIZE);
pankso@4056 68 + }
pankso@4056 69 + wr->buffer_index[wr->buffer_pos / LZMA_IOBUF_SIZE]
pankso@4056 70 + [wr->buffer_pos % LZMA_IOBUF_SIZE] =
pankso@4056 71 + wr->previous_byte = byte;
pankso@4056 72 + wr->buffer_pos++;
pankso@4056 73 +}
pankso@4056 74 +
pankso@4056 75 static inline void INIT write_byte(struct writer *wr, uint8_t byte)
pankso@4056 76 {
pankso@4056 77 + if (wr->is_cpio_flush) {
pankso@4056 78 + write_byte_if_cpio(wr, byte);
pankso@4056 79 + return;
pankso@4056 80 + }
pankso@4056 81 wr->buffer[wr->buffer_pos++] = wr->previous_byte = byte;
pankso@4056 82 if (wr->flush && wr->buffer_pos == wr->header->dict_size) {
pankso@4056 83 wr->buffer_pos = 0;
pankso@4056 84 @@ -328,7 +373,21 @@
pankso@4056 85 static inline void INIT copy_bytes(struct writer *wr,
pankso@4056 86 uint32_t rep0, int len)
pankso@4056 87 {
pankso@4056 88 - do {
pankso@4056 89 + if (wr->is_cpio_flush) {
pankso@4056 90 + int32_t pos;
pankso@4056 91 + uint32_t offs = rep0;
pankso@4056 92 + while (offs > wr->header->dict_size)
pankso@4056 93 + offs -= wr->header->dict_size;
pankso@4056 94 + pos = wr->buffer_pos - offs;
pankso@4056 95 + do {
pankso@4056 96 + write_byte_if_cpio(wr,
pankso@4056 97 + wr->buffer_index[pos / LZMA_IOBUF_SIZE]
pankso@4056 98 + [pos % LZMA_IOBUF_SIZE]);
pankso@4056 99 + pos++;
pankso@4056 100 + len--;
pankso@4056 101 + } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
pankso@4056 102 + }
pankso@4056 103 + else do {
pankso@4056 104 copy_byte(wr, rep0);
pankso@4056 105 len--;
pankso@4056 106 } while (len != 0 && wr->buffer_pos < wr->header->dst_size);
pankso@4056 107 @@ -339,6 +398,9 @@
pankso@4056 108 int pos_state, uint16_t *prob,
pankso@4056 109 int lc, uint32_t literal_pos_mask) {
pankso@4056 110 int mi = 1;
pankso@4056 111 + static const int state[LZMA_NUM_STATES] =
pankso@4056 112 + { 0, 0, 0, 0, 1, 2, 3, 4, 5, 6, 4, 5 };
pankso@4056 113 +
pankso@4056 114 rc_update_bit_0(rc, prob);
pankso@4056 115 prob = (p + LZMA_LITERAL +
pankso@4056 116 (LZMA_LIT_SIZE
pankso@4056 117 @@ -369,18 +431,13 @@
pankso@4056 118 rc_get_bit(rc, prob_lit, &mi);
pankso@4056 119 }
pankso@4056 120 write_byte(wr, mi);
pankso@4056 121 - if (cst->state < 4)
pankso@4056 122 - cst->state = 0;
pankso@4056 123 - else if (cst->state < 10)
pankso@4056 124 - cst->state -= 3;
pankso@4056 125 - else
pankso@4056 126 - cst->state -= 6;
pankso@4056 127 + cst->state = state[cst->state];
pankso@4056 128 }
pankso@4056 129
pankso@4056 130 static inline void INIT process_bit1(struct writer *wr, struct rc *rc,
pankso@4056 131 struct cstate *cst, uint16_t *p,
pankso@4056 132 int pos_state, uint16_t *prob) {
pankso@4056 133 - int offset;
pankso@4056 134 + int offset;
pankso@4056 135 uint16_t *prob_len;
pankso@4056 136 int num_bits;
pankso@4056 137 int len;
pankso@4056 138 @@ -396,7 +453,7 @@
pankso@4056 139 prob = p + LZMA_LEN_CODER;
pankso@4056 140 } else {
pankso@4056 141 rc_update_bit_1(rc, prob);
pankso@4056 142 - prob = p + LZMA_IS_REP_G0 + cst->state;
pankso@4056 143 + prob += LZMA_IS_REP_G0 - LZMA_IS_REP;
pankso@4056 144 if (rc_is_bit_0(rc, prob)) {
pankso@4056 145 rc_update_bit_0(rc, prob);
pankso@4056 146 prob = (p + LZMA_IS_REP_0_LONG
pankso@4056 147 @@ -417,13 +474,13 @@
pankso@4056 148 uint32_t distance;
pankso@4056 149
pankso@4056 150 rc_update_bit_1(rc, prob);
pankso@4056 151 - prob = p + LZMA_IS_REP_G1 + cst->state;
pankso@4056 152 + prob += LZMA_IS_REP_G1 - LZMA_IS_REP_G0;
pankso@4056 153 if (rc_is_bit_0(rc, prob)) {
pankso@4056 154 rc_update_bit_0(rc, prob);
pankso@4056 155 distance = cst->rep1;
pankso@4056 156 } else {
pankso@4056 157 rc_update_bit_1(rc, prob);
pankso@4056 158 - prob = p + LZMA_IS_REP_G2 + cst->state;
pankso@4056 159 + prob += LZMA_IS_REP_G2 - LZMA_IS_REP_G1;
pankso@4056 160 if (rc_is_bit_0(rc, prob)) {
pankso@4056 161 rc_update_bit_0(rc, prob);
pankso@4056 162 distance = cst->rep2;
pankso@4056 163 @@ -444,24 +501,24 @@
pankso@4056 164 prob_len = prob + LZMA_LEN_CHOICE;
pankso@4056 165 if (rc_is_bit_0(rc, prob_len)) {
pankso@4056 166 rc_update_bit_0(rc, prob_len);
pankso@4056 167 - prob_len = (prob + LZMA_LEN_LOW
pankso@4056 168 + prob_len += LZMA_LEN_LOW - LZMA_LEN_CHOICE
pankso@4056 169 + (pos_state <<
pankso@4056 170 - LZMA_LEN_NUM_LOW_BITS));
pankso@4056 171 + LZMA_LEN_NUM_LOW_BITS);
pankso@4056 172 offset = 0;
pankso@4056 173 num_bits = LZMA_LEN_NUM_LOW_BITS;
pankso@4056 174 } else {
pankso@4056 175 rc_update_bit_1(rc, prob_len);
pankso@4056 176 - prob_len = prob + LZMA_LEN_CHOICE_2;
pankso@4056 177 + prob_len += LZMA_LEN_CHOICE_2 - LZMA_LEN_CHOICE;
pankso@4056 178 if (rc_is_bit_0(rc, prob_len)) {
pankso@4056 179 rc_update_bit_0(rc, prob_len);
pankso@4056 180 - prob_len = (prob + LZMA_LEN_MID
pankso@4056 181 + prob_len += LZMA_LEN_MID - LZMA_LEN_CHOICE_2
pankso@4056 182 + (pos_state <<
pankso@4056 183 - LZMA_LEN_NUM_MID_BITS));
pankso@4056 184 + LZMA_LEN_NUM_MID_BITS);
pankso@4056 185 offset = 1 << LZMA_LEN_NUM_LOW_BITS;
pankso@4056 186 num_bits = LZMA_LEN_NUM_MID_BITS;
pankso@4056 187 } else {
pankso@4056 188 rc_update_bit_1(rc, prob_len);
pankso@4056 189 - prob_len = prob + LZMA_LEN_HIGH;
pankso@4056 190 + prob_len += LZMA_LEN_HIGH - LZMA_LEN_CHOICE_2;
pankso@4056 191 offset = ((1 << LZMA_LEN_NUM_LOW_BITS)
pankso@4056 192 + (1 << LZMA_LEN_NUM_MID_BITS));
pankso@4056 193 num_bits = LZMA_LEN_NUM_HIGH_BITS;
pankso@4056 194 @@ -529,6 +586,7 @@
pankso@4056 195 void(*error_fn)(char *x)
pankso@4056 196 )
pankso@4056 197 {
pankso@4056 198 + extern int cpio_flush_buffer(void*, unsigned int);
pankso@4056 199 struct lzma_header header;
pankso@4056 200 int lc, pb, lp;
pankso@4056 201 uint32_t pos_state_mask;
pankso@4056 202 @@ -563,6 +621,10 @@
pankso@4056 203 wr.global_pos = 0;
pankso@4056 204 wr.previous_byte = 0;
pankso@4056 205 wr.buffer_pos = 0;
pankso@4056 206 + wr.is_cpio_flush = 0;
pankso@4056 207 + if (flush == cpio_flush_buffer)
pankso@4056 208 + wr.is_cpio_flush = 1;
pankso@4056 209 + wr.buffer_index = NULL;
pankso@4056 210
pankso@4056 211 rc_init(&rc, fill, inbuf, in_len);
pankso@4056 212
pankso@4056 213 @@ -596,23 +658,23 @@
pankso@4056 214 if (header.dict_size == 0)
pankso@4056 215 header.dict_size = 1;
pankso@4056 216
pankso@4056 217 - if (output)
pankso@4056 218 + if (output || wr.is_cpio_flush)
pankso@4056 219 wr.buffer = output;
pankso@4056 220 else {
pankso@4056 221 wr.bufsize = MIN(header.dst_size, header.dict_size);
pankso@4056 222 wr.buffer = large_malloc(wr.bufsize);
pankso@4056 223 }
pankso@4056 224 - if (wr.buffer == NULL)
pankso@4056 225 + if (wr.buffer == NULL && !wr.is_cpio_flush)
pankso@4056 226 goto exit_1;
pankso@4056 227
pankso@4056 228 num_probs = LZMA_BASE_SIZE + (LZMA_LIT_SIZE << (lc + lp));
pankso@4056 229 p = (uint16_t *) large_malloc(num_probs * sizeof(*p));
pankso@4056 230 if (p == 0)
pankso@4056 231 goto exit_2;
pankso@4056 232 - num_probs = LZMA_LITERAL + (LZMA_LIT_SIZE << (lc + lp));
pankso@4056 233 + num_probs += LZMA_LITERAL - LZMA_BASE_SIZE;
pankso@4056 234 for (i = 0; i < num_probs; i++)
pankso@4056 235 p[i] = (1 << RC_MODEL_TOTAL_BITS) >> 1;
pankso@4056 236 -
pankso@4056 237 + wr.max_index = wr.next_index = 0;
pankso@4056 238 rc_init_code(&rc);
pankso@4056 239
pankso@4056 240 while (get_pos(&wr) < header.dst_size) {
pankso@4056 241 @@ -631,12 +693,25 @@
pankso@4056 242
pankso@4056 243 if (posp)
pankso@4056 244 *posp = rc.ptr-rc.buffer;
pankso@4056 245 - if (wr.flush)
pankso@4056 246 + if (wr.is_cpio_flush) {
pankso@4056 247 + int i;
pankso@4056 248 + for (i = 0; i < wr.next_index -1; i++) {
pankso@4056 249 + wr.flush(wr.buffer_index[i], LZMA_IOBUF_SIZE);
pankso@4056 250 + large_free(wr.buffer_index[i]);
pankso@4056 251 + }
pankso@4056 252 + if (i < wr.next_index) {
pankso@4056 253 + wr.flush(wr.buffer_index[i],
pankso@4056 254 + wr.buffer_pos % LZMA_IOBUF_SIZE);
pankso@4056 255 + large_free(wr.buffer_index[i]);
pankso@4056 256 + }
pankso@4056 257 + large_free(wr.buffer_index);
pankso@4056 258 + }
pankso@4056 259 + else if (wr.flush)
pankso@4056 260 wr.flush(wr.buffer, wr.buffer_pos);
pankso@4056 261 ret = 0;
pankso@4056 262 large_free(p);
pankso@4056 263 exit_2:
pankso@4056 264 - if (!output)
pankso@4056 265 + if (!output && !wr.is_cpio_flush)
pankso@4056 266 large_free(wr.buffer);
pankso@4056 267 exit_1:
pankso@4056 268 if (!buf)