RTEMS  5.0.0
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 typedef struct {
55  enum {
56  UNTAR_CHUNK_HEADER,
57  UNTAR_CHUNK_SKIP,
58  UNTAR_CHUNK_WRITE,
59  UNTAR_CHUNK_ERROR
60  } state;
61 
65  char header[512];
66 
70  char fname[100];
71 
75  size_t done_bytes;
76 
80  unsigned long mode;
81 
85  unsigned long todo_bytes;
86 
90  unsigned long todo_blocks;
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 /**************************************************************************
242  * This converts octal ASCII number representations into an
243  * unsigned long. Only support 32-bit numbers for now.
244  *************************************************************************/
245 extern unsigned long
246 _rtems_octal2ulong(const char *octascii, size_t len);
247 
248 /************************************************************************
249  * Compute the TAR checksum and check with the value in
250  * the archive. The checksum is computed over the entire
251  * header, but the checksum field is substituted with blanks.
252  ************************************************************************/
253 extern int
254 _rtems_tar_header_checksum(const char *bufr);
255 
256 #ifdef __cplusplus
257 }
258 #endif
259 
260 #endif /* _RTEMS_UNTAR_H */
size_t done_bytes
Number of bytes of overall length are already processed.
Definition: untar.h:75
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
unsigned long todo_bytes
Overall amount of bytes to be processed.
Definition: untar.h:85
Definition: untar.h:121
int out_fd
File descriptor of output file.
Definition: untar.h:95
void * inflateBuffer
Buffer that contains the inflated data.
Definition: untar.h:112
unsigned long mode
Mode of the file.
Definition: untar.h:80
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:51
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
unsigned long todo_blocks
Overall amount of blocks to be processed.
Definition: untar.h:90
void Untar_ChunkContext_Init(Untar_ChunkContext *context)
Initializes the Untar_ChunkContext files out of a part of a block of memory.
Definition: untar.c:554