RTEMS: cpukit/include/rtems/untar.h Source File

| RTEMS 5.4-rc2

Loading...
Searching...
No Matches
untar.h
Go to the documentation of this file.
1
9/*
10 * Written by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu>
11 *
12 * The license and distribution terms for this file may be
13 * found in the file LICENSE in this distribution or at
14 * http://www.rtems.org/license/LICENSE.
15 */
16
17#ifndef _RTEMS_UNTAR_H
18#define _RTEMS_UNTAR_H
19
20#include <stdbool.h>
21#include <stddef.h>
22#include <tar.h>
23#include <zlib.h>
24#include <xz.h>
25
26#include <rtems/print.h>
27
34#ifdef __cplusplus
35extern "C" {
36#endif
37
38#define UNTAR_SUCCESSFUL 0
39#define UNTAR_FAIL 1
40#define UNTAR_INVALID_CHECKSUM 2
41#define UNTAR_INVALID_HEADER 3
42
43#define UNTAR_GZ_INFLATE_FAILED 4
44#define UNTAR_GZ_INFLATE_END_FAILED 5
45
46int Untar_FromMemory(void *tar_buf, size_t size);
47int Untar_FromMemory_Print(void *tar_buf, size_t size, const rtems_printer* printer);
48int Untar_FromFile(const char *tar_name);
49int Untar_FromFile_Print(const char *tar_name, const rtems_printer* printer);
50
51#define UNTAR_FILE_NAME_SIZE 100
52
53 typedef struct {
54 char *file_path;
55 char *file_name;
56 char link_name[UNTAR_FILE_NAME_SIZE];
57 unsigned long mode;
58 unsigned long file_size;
59 unsigned long nblocks;
60 unsigned char linkflag;
61 const rtems_printer *printer;
62} Untar_HeaderContext;
63
64 typedef struct {
65 Untar_HeaderContext base;
66
70 char buf[UNTAR_FILE_NAME_SIZE];
71
75 enum {
76 UNTAR_CHUNK_HEADER,
77 UNTAR_CHUNK_SKIP,
78 UNTAR_CHUNK_WRITE,
79 UNTAR_CHUNK_ERROR
80 } state;
81
85 char header[512];
86
90 size_t done_bytes;
91
95 int out_fd;
96} Untar_ChunkContext;
97
98 typedef struct {
102 Untar_ChunkContext base;
103
107 z_stream strm;
108
112 void *inflateBuffer;
113
117 size_t inflateBufferSize;
118
119} Untar_GzChunkContext;
120
121 typedef struct {
125 Untar_ChunkContext base;
126
130 struct xz_dec* strm;
131
135 struct xz_buf buf;
136
140 void *inflateBuffer;
141
145 size_t inflateBufferSize;
146
147} Untar_XzChunkContext;
148
155void Untar_ChunkContext_Init(Untar_ChunkContext *context);
156
157/*
158 * @brief Rips links, directories and files out of a part of a block of memory.
159 *
160 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
161 * @param void *chunk [in] Pointer to a chunk of a TAR buffer.
162 * @param size_t chunk_size [in] Length of the chunk of a TAR buffer.
163 *
164 * @retval UNTAR_SUCCESSFUL (0) on successful completion.
165 * @retval UNTAR_FAIL for a faulty step within the process.
166 * @retval UNTAR_INVALID_CHECKSUM for an invalid header checksum.
167 * @retval UNTAR_INVALID_HEADER for an invalid header.
168 */
169
170int Untar_FromChunk_Print(
171 Untar_ChunkContext *context,
172 void *chunk,
173 size_t chunk_size,
174 const rtems_printer* printer
175);
176
184int Untar_GzChunkContext_Init(
185 Untar_GzChunkContext *ctx,
186 void *inflateBuffer,
187 size_t inflateBufferSize
188);
189
190/*
191 * @brief Untars a GZ compressed POSIX TAR file.
192 *
193 * This is a subroutine used to rip links, directories, and
194 * files out of a tar.gz/tgz file.
195 *
196 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
197 * @param ssize buflen [in] Size of valid bytes in input buffer.
198 * @param z_stream *strm [in] Pointer to the current zlib context.
199 */
200int Untar_FromGzChunk_Print(
201 Untar_GzChunkContext *ctx,
202 void *chunk,
203 size_t chunk_size,
204 const rtems_printer* printer
205);
206
216int Untar_XzChunkContext_Init(
217 Untar_XzChunkContext *ctx,
218 enum xz_mode mode,
219 uint32_t dict_max,
220 void *inflateBuffer,
221 size_t inflateBufferSize
222);
223
224/*
225 * @brief Untars a XZ compressed POSIX TAR file.
226 *
227 * This is a subroutine used to rip links, directories, and
228 * files out of a tar.gz/tgz file.
229 *
230 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
231 * @param ssize buflen [in] Size of valid bytes in input buffer.
232 * @param z_stream *strm [in] Pointer to the current zlib context.
233 */
234int Untar_FromXzChunk_Print(
235 Untar_XzChunkContext *ctx,
236 const void *chunk,
237 size_t chunk_size,
238 const rtems_printer* printer
239);
240
241int Untar_ProcessHeader(Untar_HeaderContext *ctx, const char *bufr);
242
243#ifdef __cplusplus
244}
245#endif
247#endif /* _RTEMS_UNTAR_H */
Untar_XzChunkContext_Init
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:15
Untar_GzChunkContext_Init
int Untar_GzChunkContext_Init(Untar_GzChunkContext *ctx, void *inflateBuffer, size_t inflateBufferSize)
Initializes the Untar_ChunkGzContext.
Definition: untar_tgz.c:23
Untar_ChunkContext_Init
void Untar_ChunkContext_Init(Untar_ChunkContext *context)
Initializes the Untar_ChunkContext files out of a part of a block of memory.
Definition: untar.c:465
print.h
User print interface to the bspIO print plug in.
Untar_ChunkContext
Definition: untar.h:64
Untar_ChunkContext::out_fd
int out_fd
File descriptor of output file.
Definition: untar.h:95
Untar_ChunkContext::done_bytes
size_t done_bytes
Number of bytes of overall length are already processed.
Definition: untar.h:90
Untar_GzChunkContext
Definition: untar.h:98
Untar_GzChunkContext::inflateBuffer
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:112
Untar_GzChunkContext::base
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:102
Untar_GzChunkContext::inflateBufferSize
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:117
Untar_GzChunkContext::strm
z_stream strm
Current zlib context.
Definition: untar.h:107
Untar_HeaderContext
Definition: untar.h:53
Untar_XzChunkContext
Definition: untar.h:121
Untar_XzChunkContext::base
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:125
Untar_XzChunkContext::strm
struct xz_dec * strm
Xz context.
Definition: untar.h:130
Untar_XzChunkContext::inflateBufferSize
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:145
Untar_XzChunkContext::inflateBuffer
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:140
rtems_printer
Definition: printer.h:55
xz_buf
Definition: xz.h:140
xz_dec
Definition: xz_dec_stream.c:26
z_stream_s
Definition: zlib.h:170