wok annotate linux-libre/stuff/linux-libre-unlzma-2.6.37-libre.u @ rev 13452

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