• Home
  • Raw
  • Download

Lines Matching refs:s

157 static bool fill_temp(struct xz_dec *s, struct xz_buf *b)  in fill_temp()  argument
160 b->in_size - b->in_pos, s->temp.size - s->temp.pos); in fill_temp()
162 memcpy(s->temp.buf + s->temp.pos, b->in + b->in_pos, copy_size); in fill_temp()
164 s->temp.pos += copy_size; in fill_temp()
166 if (s->temp.pos == s->temp.size) { in fill_temp()
167 s->temp.pos = 0; in fill_temp()
175 static enum xz_ret dec_vli(struct xz_dec *s, const uint8_t *in, in dec_vli() argument
180 if (s->pos == 0) in dec_vli()
181 s->vli = 0; in dec_vli()
187 s->vli |= (vli_type)(byte & 0x7F) << s->pos; in dec_vli()
191 if (byte == 0 && s->pos != 0) in dec_vli()
194 s->pos = 0; in dec_vli()
198 s->pos += 7; in dec_vli()
199 if (s->pos == 7 * VLI_BYTES_MAX) in dec_vli()
218 static enum xz_ret dec_block(struct xz_dec *s, struct xz_buf *b) in dec_block() argument
222 s->in_start = b->in_pos; in dec_block()
223 s->out_start = b->out_pos; in dec_block()
226 if (s->bcj_active) in dec_block()
227 ret = xz_dec_bcj_run(s->bcj, s->lzma2, b); in dec_block()
230 ret = xz_dec_lzma2_run(s->lzma2, b); in dec_block()
232 s->block.compressed += b->in_pos - s->in_start; in dec_block()
233 s->block.uncompressed += b->out_pos - s->out_start; in dec_block()
239 if (s->block.compressed > s->block_header.compressed in dec_block()
240 || s->block.uncompressed in dec_block()
241 > s->block_header.uncompressed) in dec_block()
244 if (s->check_type == XZ_CHECK_CRC32) in dec_block()
245 s->crc32 = xz_crc32(b->out + s->out_start, in dec_block()
246 b->out_pos - s->out_start, s->crc32); in dec_block()
249 if (s->block_header.compressed != VLI_UNKNOWN in dec_block()
250 && s->block_header.compressed in dec_block()
251 != s->block.compressed) in dec_block()
254 if (s->block_header.uncompressed != VLI_UNKNOWN in dec_block()
255 && s->block_header.uncompressed in dec_block()
256 != s->block.uncompressed) in dec_block()
259 s->block.hash.unpadded += s->block_header.size in dec_block()
260 + s->block.compressed; in dec_block()
263 s->block.hash.unpadded += check_sizes[s->check_type]; in dec_block()
265 if (s->check_type == XZ_CHECK_CRC32) in dec_block()
266 s->block.hash.unpadded += 4; in dec_block()
269 s->block.hash.uncompressed += s->block.uncompressed; in dec_block()
270 s->block.hash.crc32 = xz_crc32( in dec_block()
271 (const uint8_t *)&s->block.hash, in dec_block()
272 sizeof(s->block.hash), s->block.hash.crc32); in dec_block()
274 ++s->block.count; in dec_block()
281 static void index_update(struct xz_dec *s, const struct xz_buf *b) in index_update() argument
283 size_t in_used = b->in_pos - s->in_start; in index_update()
284 s->index.size += in_used; in index_update()
285 s->crc32 = xz_crc32(b->in + s->in_start, in_used, s->crc32); in index_update()
296 static enum xz_ret dec_index(struct xz_dec *s, struct xz_buf *b) in dec_index() argument
301 ret = dec_vli(s, b->in, &b->in_pos, b->in_size); in dec_index()
303 index_update(s, b); in dec_index()
307 switch (s->index.sequence) { in dec_index()
309 s->index.count = s->vli; in dec_index()
316 if (s->index.count != s->block.count) in dec_index()
319 s->index.sequence = SEQ_INDEX_UNPADDED; in dec_index()
323 s->index.hash.unpadded += s->vli; in dec_index()
324 s->index.sequence = SEQ_INDEX_UNCOMPRESSED; in dec_index()
328 s->index.hash.uncompressed += s->vli; in dec_index()
329 s->index.hash.crc32 = xz_crc32( in dec_index()
330 (const uint8_t *)&s->index.hash, in dec_index()
331 sizeof(s->index.hash), in dec_index()
332 s->index.hash.crc32); in dec_index()
333 --s->index.count; in dec_index()
334 s->index.sequence = SEQ_INDEX_UNPADDED; in dec_index()
337 } while (s->index.count > 0); in dec_index()
346 static enum xz_ret crc32_validate(struct xz_dec *s, struct xz_buf *b) in crc32_validate() argument
352 if (((s->crc32 >> s->pos) & 0xFF) != b->in[b->in_pos++]) in crc32_validate()
355 s->pos += 8; in crc32_validate()
357 } while (s->pos < 32); in crc32_validate()
359 s->crc32 = 0; in crc32_validate()
360 s->pos = 0; in crc32_validate()
370 static bool check_skip(struct xz_dec *s, struct xz_buf *b) in check_skip() argument
372 while (s->pos < check_sizes[s->check_type]) { in check_skip()
377 ++s->pos; in check_skip()
380 s->pos = 0; in check_skip()
387 static enum xz_ret dec_stream_header(struct xz_dec *s) in dec_stream_header() argument
389 if (!memeq(s->temp.buf, HEADER_MAGIC, HEADER_MAGIC_SIZE)) in dec_stream_header()
392 if (xz_crc32(s->temp.buf + HEADER_MAGIC_SIZE, 2, 0) in dec_stream_header()
393 != get_le32(s->temp.buf + HEADER_MAGIC_SIZE + 2)) in dec_stream_header()
396 if (s->temp.buf[HEADER_MAGIC_SIZE] != 0) in dec_stream_header()
405 if (s->temp.buf[HEADER_MAGIC_SIZE + 1] > XZ_CHECK_MAX) in dec_stream_header()
408 s->check_type = s->temp.buf[HEADER_MAGIC_SIZE + 1]; in dec_stream_header()
411 if (s->check_type > XZ_CHECK_CRC32) in dec_stream_header()
414 if (s->check_type > XZ_CHECK_CRC32) in dec_stream_header()
422 static enum xz_ret dec_stream_footer(struct xz_dec *s) in dec_stream_footer() argument
424 if (!memeq(s->temp.buf + 10, FOOTER_MAGIC, FOOTER_MAGIC_SIZE)) in dec_stream_footer()
427 if (xz_crc32(s->temp.buf + 4, 6, 0) != get_le32(s->temp.buf)) in dec_stream_footer()
435 if ((s->index.size >> 2) != get_le32(s->temp.buf + 4)) in dec_stream_footer()
438 if (s->temp.buf[8] != 0 || s->temp.buf[9] != s->check_type) in dec_stream_footer()
449 static enum xz_ret dec_block_header(struct xz_dec *s) in dec_block_header() argument
457 s->temp.size -= 4; in dec_block_header()
458 if (xz_crc32(s->temp.buf, s->temp.size, 0) in dec_block_header()
459 != get_le32(s->temp.buf + s->temp.size)) in dec_block_header()
462 s->temp.pos = 2; in dec_block_header()
469 if (s->temp.buf[1] & 0x3E) in dec_block_header()
471 if (s->temp.buf[1] & 0x3F) in dec_block_header()
476 if (s->temp.buf[1] & 0x40) { in dec_block_header()
477 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) in dec_block_header()
481 s->block_header.compressed = s->vli; in dec_block_header()
483 s->block_header.compressed = VLI_UNKNOWN; in dec_block_header()
487 if (s->temp.buf[1] & 0x80) { in dec_block_header()
488 if (dec_vli(s, s->temp.buf, &s->temp.pos, s->temp.size) in dec_block_header()
492 s->block_header.uncompressed = s->vli; in dec_block_header()
494 s->block_header.uncompressed = VLI_UNKNOWN; in dec_block_header()
499 s->bcj_active = s->temp.buf[1] & 0x01; in dec_block_header()
500 if (s->bcj_active) { in dec_block_header()
501 if (s->temp.size - s->temp.pos < 2) in dec_block_header()
504 ret = xz_dec_bcj_reset(s->bcj, s->temp.buf[s->temp.pos++]); in dec_block_header()
512 if (s->temp.buf[s->temp.pos++] != 0x00) in dec_block_header()
518 if (s->temp.size - s->temp.pos < 2) in dec_block_header()
522 if (s->temp.buf[s->temp.pos++] != 0x21) in dec_block_header()
526 if (s->temp.buf[s->temp.pos++] != 0x01) in dec_block_header()
530 if (s->temp.size - s->temp.pos < 1) in dec_block_header()
533 ret = xz_dec_lzma2_reset(s->lzma2, s->temp.buf[s->temp.pos++]); in dec_block_header()
538 while (s->temp.pos < s->temp.size) in dec_block_header()
539 if (s->temp.buf[s->temp.pos++] != 0x00) in dec_block_header()
542 s->temp.pos = 0; in dec_block_header()
543 s->block.compressed = 0; in dec_block_header()
544 s->block.uncompressed = 0; in dec_block_header()
549 static enum xz_ret dec_main(struct xz_dec *s, struct xz_buf *b) in dec_main() argument
557 s->in_start = b->in_pos; in dec_main()
560 switch (s->sequence) { in dec_main()
570 if (!fill_temp(s, b)) in dec_main()
580 s->sequence = SEQ_BLOCK_START; in dec_main()
582 ret = dec_stream_header(s); in dec_main()
595 s->in_start = b->in_pos++; in dec_main()
596 s->sequence = SEQ_INDEX; in dec_main()
604 s->block_header.size in dec_main()
607 s->temp.size = s->block_header.size; in dec_main()
608 s->temp.pos = 0; in dec_main()
609 s->sequence = SEQ_BLOCK_HEADER; in dec_main()
614 if (!fill_temp(s, b)) in dec_main()
617 ret = dec_block_header(s); in dec_main()
621 s->sequence = SEQ_BLOCK_UNCOMPRESS; in dec_main()
626 ret = dec_block(s, b); in dec_main()
630 s->sequence = SEQ_BLOCK_PADDING; in dec_main()
642 while (s->block.compressed & 3) { in dec_main()
649 ++s->block.compressed; in dec_main()
652 s->sequence = SEQ_BLOCK_CHECK; in dec_main()
657 if (s->check_type == XZ_CHECK_CRC32) { in dec_main()
658 ret = crc32_validate(s, b); in dec_main()
663 else if (!check_skip(s, b)) { in dec_main()
668 s->sequence = SEQ_BLOCK_START; in dec_main()
672 ret = dec_index(s, b); in dec_main()
676 s->sequence = SEQ_INDEX_PADDING; in dec_main()
681 while ((s->index.size + (b->in_pos - s->in_start)) in dec_main()
684 index_update(s, b); in dec_main()
693 index_update(s, b); in dec_main()
696 if (!memeq(&s->block.hash, &s->index.hash, in dec_main()
697 sizeof(s->block.hash))) in dec_main()
700 s->sequence = SEQ_INDEX_CRC32; in dec_main()
705 ret = crc32_validate(s, b); in dec_main()
709 s->temp.size = STREAM_HEADER_SIZE; in dec_main()
710 s->sequence = SEQ_STREAM_FOOTER; in dec_main()
715 if (!fill_temp(s, b)) in dec_main()
718 return dec_stream_footer(s); in dec_main()
750 XZ_EXTERN enum xz_ret xz_dec_run(struct xz_dec *s, struct xz_buf *b) in xz_dec_run() argument
756 if (DEC_IS_SINGLE(s->mode)) in xz_dec_run()
757 xz_dec_reset(s); in xz_dec_run()
761 ret = dec_main(s, b); in xz_dec_run()
763 if (DEC_IS_SINGLE(s->mode)) { in xz_dec_run()
775 if (s->allow_buf_error) in xz_dec_run()
778 s->allow_buf_error = true; in xz_dec_run()
780 s->allow_buf_error = false; in xz_dec_run()
788 struct xz_dec *s = kmalloc(sizeof(*s), GFP_KERNEL); in xz_dec_init() local
789 if (s == NULL) in xz_dec_init()
792 s->mode = mode; in xz_dec_init()
795 s->bcj = xz_dec_bcj_create(DEC_IS_SINGLE(mode)); in xz_dec_init()
796 if (s->bcj == NULL) in xz_dec_init()
800 s->lzma2 = xz_dec_lzma2_create(mode, dict_max); in xz_dec_init()
801 if (s->lzma2 == NULL) in xz_dec_init()
804 xz_dec_reset(s); in xz_dec_init()
805 return s; in xz_dec_init()
809 xz_dec_bcj_end(s->bcj); in xz_dec_init()
812 kfree(s); in xz_dec_init()
816 XZ_EXTERN void xz_dec_reset(struct xz_dec *s) in xz_dec_reset() argument
818 s->sequence = SEQ_STREAM_HEADER; in xz_dec_reset()
819 s->allow_buf_error = false; in xz_dec_reset()
820 s->pos = 0; in xz_dec_reset()
821 s->crc32 = 0; in xz_dec_reset()
822 memzero(&s->block, sizeof(s->block)); in xz_dec_reset()
823 memzero(&s->index, sizeof(s->index)); in xz_dec_reset()
824 s->temp.pos = 0; in xz_dec_reset()
825 s->temp.size = STREAM_HEADER_SIZE; in xz_dec_reset()
828 XZ_EXTERN void xz_dec_end(struct xz_dec *s) in xz_dec_end() argument
830 if (s != NULL) { in xz_dec_end()
831 xz_dec_lzma2_end(s->lzma2); in xz_dec_end()
833 xz_dec_bcj_end(s->bcj); in xz_dec_end()
835 kfree(s); in xz_dec_end()