RTEMS 6.1-rc1
untar.h
Go to the documentation of this file.
1/* SPDX-License-Identifier: BSD-2-Clause */
2
11/*
12 * Written by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
13 *
14 * Redistribution and use in source and binary forms, with or without
15 * modification, are permitted provided that the following conditions
16 * are met:
17 * 1. Redistributions of source code must retain the above copyright
18 * notice, this list of conditions and the following disclaimer.
19 * 2. Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the distribution.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
27 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33 * POSSIBILITY OF SUCH DAMAGE.
34 */
35
36#ifndef _RTEMS_UNTAR_H
37#define _RTEMS_UNTAR_H
38
39#include <stdbool.h>
40#include <stddef.h>
41#include <tar.h>
42#include <zlib.h>
43#include <xz.h>
44
45#include <rtems/print.h>
46
53#ifdef __cplusplus
54extern "C" {
55#endif
56
57#define UNTAR_SUCCESSFUL 0
58#define UNTAR_FAIL 1
59#define UNTAR_INVALID_CHECKSUM 2
60#define UNTAR_INVALID_HEADER 3
61
62#define UNTAR_GZ_INFLATE_FAILED 4
63#define UNTAR_GZ_INFLATE_END_FAILED 5
64
65int Untar_FromMemory(void *tar_buf, size_t size);
66int Untar_FromMemory_Print(void *tar_buf, size_t size, const rtems_printer* printer);
67int Untar_FromFile(const char *tar_name);
68int Untar_FromFile_Print(const char *tar_name, const rtems_printer* printer);
69
70#define UNTAR_FILE_NAME_SIZE 100
71
72typedef struct {
73 char *file_path;
74 char *file_name;
75 char link_name[UNTAR_FILE_NAME_SIZE];
76 unsigned long mode;
77 unsigned long file_size;
78 unsigned long nblocks;
79 unsigned char linkflag;
80 const rtems_printer *printer;
82
83typedef struct {
85
89 char buf[UNTAR_FILE_NAME_SIZE];
90
94 enum {
95 UNTAR_CHUNK_HEADER,
96 UNTAR_CHUNK_SKIP,
97 UNTAR_CHUNK_WRITE,
98 UNTAR_CHUNK_ERROR
99 } state;
100
104 char header[512];
105
110
116
117typedef struct {
122
127
132
137
139
140typedef struct {
145
149 struct xz_dec* strm;
150
154 struct xz_buf buf;
155
160
165
167
175
176/*
177 * @brief Rips links, directories and files out of a part of a block of memory.
178 *
179 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
180 * @param void *chunk [in] Pointer to a chunk of a TAR buffer.
181 * @param size_t chunk_size [in] Length of the chunk of a TAR buffer.
182 *
183 * @retval UNTAR_SUCCESSFUL (0) on successful completion.
184 * @retval UNTAR_FAIL for a faulty step within the process.
185 * @retval UNTAR_INVALID_CHECKSUM for an invalid header checksum.
186 * @retval UNTAR_INVALID_HEADER for an invalid header.
187 */
188
189int Untar_FromChunk_Print(
191 void *chunk,
192 size_t chunk_size,
193 const rtems_printer* printer
194);
195
205 void *inflateBuffer,
206 size_t inflateBufferSize
207);
208
209/*
210 * @brief Untars a GZ compressed POSIX TAR file.
211 *
212 * This is a subroutine used to rip links, directories, and
213 * files out of a tar.gz/tgz file.
214 *
215 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
216 * @param ssize buflen [in] Size of valid bytes in input buffer.
217 * @param z_stream *strm [in] Pointer to the current zlib context.
218 */
219int Untar_FromGzChunk_Print(
221 void *chunk,
222 size_t chunk_size,
223 const rtems_printer* printer
224);
225
237 enum xz_mode mode,
238 uint32_t dict_max,
239 void *inflateBuffer,
240 size_t inflateBufferSize
241);
242
243/*
244 * @brief Untars a XZ compressed POSIX TAR file.
245 *
246 * This is a subroutine used to rip links, directories, and
247 * files out of a tar.gz/tgz file.
248 *
249 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
250 * @param ssize buflen [in] Size of valid bytes in input buffer.
251 * @param z_stream *strm [in] Pointer to the current zlib context.
252 */
253int Untar_FromXzChunk_Print(
255 const void *chunk,
256 size_t chunk_size,
257 const rtems_printer* printer
258);
259
260int Untar_ProcessHeader(Untar_HeaderContext *ctx, const char *bufr);
261
262#ifdef __cplusplus
263}
264#endif
266#endif /* _RTEMS_UNTAR_H */
int Untar_XzChunkContext_Init(Untar_XzChunkContext *ctx, enum xz_mode mode, uint32_t dict_max, void *inflateBuffer, size_t inflateBufferSize)
Initializes the Untar_ChunkXzContext.
Definition: untar_txz.c:34
int Untar_GzChunkContext_Init(Untar_GzChunkContext *ctx, void *inflateBuffer, size_t inflateBufferSize)
Initializes the Untar_ChunkGzContext.
Definition: untar_tgz.c:36
void Untar_ChunkContext_Init(Untar_ChunkContext *context)
Initializes the Untar_ChunkContext files out of a part of a block of memory.
Definition: untar.c:497
User print interface to the bspIO print plug in.
rtems_termios_device_context * context
Definition: console-config.c:62
Definition: untar.h:83
int out_fd
File descriptor of output file.
Definition: untar.h:114
size_t done_bytes
Number of bytes of overall length are already processed.
Definition: untar.h:109
Definition: untar.h:117
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:131
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:121
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:136
z_stream strm
Current zlib context.
Definition: untar.h:126
Definition: untar.h:72
Definition: untar.h:140
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:144
struct xz_dec * strm
Xz context.
Definition: untar.h:149
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:164
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:159
Definition: printer.h:76
Definition: xz.h:140
Definition: xz_dec_stream.c:26
Definition: zlib.h:170
unsigned size
Definition: tte.h:1