File indexing completed on 2025-05-11 08:24:20
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028 #ifdef HAVE_CONFIG_H
0029 #include "config.h"
0030 #endif
0031
0032 #include <rtems/untar.h>
0033
0034 int Untar_XzChunkContext_Init(
0035 Untar_XzChunkContext *ctx,
0036 enum xz_mode mode,
0037 uint32_t dict_max,
0038 void *inflateBuffer,
0039 size_t inflateBufferSize
0040 )
0041 {
0042 int status = UNTAR_SUCCESSFUL;
0043
0044 xz_crc32_init();
0045
0046 Untar_ChunkContext_Init(&ctx->base);
0047 ctx->inflateBuffer = inflateBuffer;
0048 ctx->inflateBufferSize = inflateBufferSize;
0049 ctx->strm = xz_dec_init(mode, dict_max);
0050 if (ctx->strm == NULL) {
0051 status = UNTAR_FAIL;
0052 }
0053
0054 return status;
0055 }
0056
0057 int Untar_FromXzChunk_Print(
0058 Untar_XzChunkContext *ctx,
0059 const void *chunk,
0060 size_t chunk_size,
0061 const rtems_printer *printer
0062 )
0063 {
0064 int untar_status = UNTAR_SUCCESSFUL;
0065 enum xz_ret status = XZ_OK;
0066
0067 if (ctx->strm == NULL)
0068 return UNTAR_FAIL;
0069
0070 ctx->buf.in = (const uint8_t*) chunk;
0071 ctx->buf.in_pos = 0;
0072 ctx->buf.in_size = chunk_size;
0073 ctx->buf.out = (uint8_t *) ctx->inflateBuffer;
0074
0075
0076 do {
0077 ctx->buf.out_pos = 0;
0078 ctx->buf.out_size = ctx->inflateBufferSize;
0079 status = xz_dec_run(ctx->strm, &ctx->buf);
0080 if (status == XZ_OPTIONS_ERROR)
0081 status = XZ_OK;
0082 if (status == XZ_OK && ctx->buf.out_pos != 0) {
0083 untar_status = Untar_FromChunk_Print(&ctx->base,
0084 ctx->inflateBuffer,
0085 ctx->buf.out_pos,
0086 NULL);
0087 if (untar_status != UNTAR_SUCCESSFUL) {
0088 break;
0089 }
0090 }
0091 } while (ctx->buf.in_pos != ctx->buf.in_size && status == XZ_OK);
0092
0093 if (status != XZ_OK) {
0094 xz_dec_end(ctx->strm);
0095 ctx->strm = NULL;
0096 if (untar_status == UNTAR_SUCCESSFUL) {
0097 switch (status) {
0098 case XZ_OK:
0099 case XZ_STREAM_END:
0100 break;
0101 case XZ_UNSUPPORTED_CHECK:
0102 rtems_printf(printer, "XZ unsupported check\n");
0103 break;
0104 case XZ_MEM_ERROR:
0105 rtems_printf(printer, "XZ memory allocation error\n");
0106 break;
0107 case XZ_MEMLIMIT_ERROR:
0108 rtems_printf(printer, "XZ memory usage limit reached\n");
0109 break;
0110 case XZ_FORMAT_ERROR:
0111 rtems_printf(printer, "Not a XZ file\n");
0112 break;
0113 case XZ_OPTIONS_ERROR:
0114 rtems_printf(printer, "Unsupported options in XZ header\n");
0115 break;
0116 case XZ_DATA_ERROR:
0117 rtems_printf(printer, "XZ file is corrupt (data)\n");
0118 break;
0119 case XZ_BUF_ERROR:
0120 rtems_printf(printer, "XZ file is corrupt (buffer)\n");
0121 break;
0122 }
0123 untar_status = UNTAR_FAIL;
0124 }
0125 }
0126
0127 return untar_status;
0128 }