RTEMS  5.1
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
35 extern "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 
46 int Untar_FromMemory(void *tar_buf, size_t size);
47 int Untar_FromMemory_Print(void *tar_buf, size_t size, const rtems_printer* printer);
48 int Untar_FromFile(const char *tar_name);
49 int 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;
63 
64 typedef struct {
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;
97 
98 typedef struct {
103 
108 
113 
118 
120 
121 typedef struct {
126 
130  struct xz_dec* strm;
131 
135  struct xz_buf buf;
136 
141 
146 
148 
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 
170 int Untar_FromChunk_Print(
172  void *chunk,
173  size_t chunk_size,
174  const rtems_printer* printer
175 );
176 
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  */
200 int Untar_FromGzChunk_Print(
202  void *chunk,
203  size_t chunk_size,
204  const rtems_printer* printer
205 );
206 
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  */
234 int Untar_FromXzChunk_Print(
236  const void *chunk,
237  size_t chunk_size,
238  const rtems_printer* printer
239 );
240 
241 int Untar_ProcessHeader(Untar_HeaderContext *ctx, const char *bufr);
242 
243 #ifdef __cplusplus
244 }
245 #endif
246 
247 #endif /* _RTEMS_UNTAR_H */
size_t done_bytes
Number of bytes of overall length are already processed.
Definition: untar.h:90
Definition: xz.h:140
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:145
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition: untar.h:117
Definition: printer.h:55
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:125
Definition: xz_dec_stream.c:26
Definition: untar.h:121
Definition: untar.h:53
int out_fd
File descriptor of output file.
Definition: untar.h:95
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:112
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
struct xz_dec * strm
Xz context.
Definition: untar.h:130
int Untar_GzChunkContext_Init(Untar_GzChunkContext *ctx, void *inflateBuffer, size_t inflateBufferSize)
Initializes the Untar_ChunkGzContext.
Definition: untar_tgz.c:23
unsigned context
Definition: tlb.h:108
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition: untar.h:102
Definition: untar.h:64
Definition: untar.h:98
unsigned size
Definition: tte.h:74
z_stream strm
Current zlib context.
Definition: untar.h:107
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:140
Definition: zlib.h:170
void Untar_ChunkContext_Init(Untar_ChunkContext *context)
Initializes the Untar_ChunkContext files out of a part of a block of memory.
Definition: untar.c:448