wok-6.x annotate linux-libre/stuff/linux-libre-unlzma-2.6.37-gnu.u @ rev 20411

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