RTEMS
6.3
Toggle main menu visibility
Loading...
Searching...
No Matches
cpukit
include
rtems
untar.h
Go to the documentation of this file.
1
/* SPDX-License-Identifier: BSD-2-Clause */
2
10
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
54
extern
"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
65
int
Untar_FromMemory(
void
*tar_buf,
size_t
size);
66
int
Untar_FromMemory_Print(
void
*tar_buf,
size_t
size,
const
rtems_printer
* printer);
67
int
Untar_FromFile(
const
char
*tar_name);
68
int
Untar_FromFile_Print(
const
char
*tar_name,
const
rtems_printer
* printer);
69
70
#define UNTAR_FILE_NAME_SIZE 100
71
72
typedef
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;
81
}
Untar_HeaderContext
;
82
83
typedef
struct
{
84
Untar_HeaderContext
base;
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
109
size_t
done_bytes
;
110
114
int
out_fd
;
115
}
Untar_ChunkContext
;
116
117
typedef
struct
{
121
Untar_ChunkContext
base
;
122
126
z_stream
strm
;
127
131
void
*
inflateBuffer
;
132
136
size_t
inflateBufferSize
;
137
138
}
Untar_GzChunkContext
;
139
140
typedef
struct
{
144
Untar_ChunkContext
base
;
145
149
struct
xz_dec
*
strm
;
150
154
struct
xz_buf
buf
;
155
159
void
*
inflateBuffer
;
160
164
size_t
inflateBufferSize
;
165
166
}
Untar_XzChunkContext
;
167
174
void
Untar_ChunkContext_Init
(
Untar_ChunkContext
*
context
);
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
189
int
Untar_FromChunk_Print(
190
Untar_ChunkContext
*
context
,
191
void
*chunk,
192
size_t
chunk_size,
193
const
rtems_printer
* printer
194
);
195
203
int
Untar_GzChunkContext_Init
(
204
Untar_GzChunkContext
*ctx,
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
*/
219
int
Untar_FromGzChunk_Print(
220
Untar_GzChunkContext
*ctx,
221
void
*chunk,
222
size_t
chunk_size,
223
const
rtems_printer
* printer
224
);
225
235
int
Untar_XzChunkContext_Init
(
236
Untar_XzChunkContext
*ctx,
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
*/
253
int
Untar_FromXzChunk_Print(
254
Untar_XzChunkContext
*ctx,
255
const
void
*chunk,
256
size_t
chunk_size,
257
const
rtems_printer
* printer
258
);
259
260
int
Untar_ProcessHeader(
Untar_HeaderContext
*ctx,
const
char
*bufr);
261
262
#ifdef __cplusplus
263
}
264
#endif
266
#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:34
Untar_GzChunkContext_Init
int Untar_GzChunkContext_Init(Untar_GzChunkContext *ctx, void *inflateBuffer, size_t inflateBufferSize)
Initializes the Untar_ChunkGzContext.
Definition
untar_tgz.c:36
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:497
print.h
User print interface to the bspIO print plug in.
Untar_ChunkContext
Definition
untar.h:83
Untar_ChunkContext::out_fd
int out_fd
File descriptor of output file.
Definition
untar.h:114
Untar_ChunkContext::header
char header[512]
Header buffer.
Definition
untar.h:104
Untar_ChunkContext::done_bytes
size_t done_bytes
Number of bytes of overall length are already processed.
Definition
untar.h:109
Untar_ChunkContext::buf
char buf[UNTAR_FILE_NAME_SIZE]
File path buffer.
Definition
untar.h:89
Untar_GzChunkContext
Definition
untar.h:117
Untar_GzChunkContext::inflateBuffer
void * inflateBuffer
Buffer that contains the inflated data.
Definition
untar.h:131
Untar_GzChunkContext::base
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition
untar.h:121
Untar_GzChunkContext::inflateBufferSize
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition
untar.h:136
Untar_GzChunkContext::strm
z_stream strm
Current zlib context.
Definition
untar.h:126
Untar_HeaderContext
Definition
untar.h:72
Untar_XzChunkContext
Definition
untar.h:140
Untar_XzChunkContext::base
Untar_ChunkContext base
Instance of Chunk Context needed for tar decompression.
Definition
untar.h:144
Untar_XzChunkContext::strm
struct xz_dec * strm
Xz context.
Definition
untar.h:149
Untar_XzChunkContext::inflateBufferSize
size_t inflateBufferSize
Size of buffer that contains the inflated data.
Definition
untar.h:164
Untar_XzChunkContext::inflateBuffer
void * inflateBuffer
Buffer that contains the inflated data.
Definition
untar.h:159
Untar_XzChunkContext::buf
struct xz_buf buf
Xz buffer.
Definition
untar.h:154
rtems_printer
Definition
printer.h:76
xz_buf
Definition
xz.h:140
xz_dec
Definition
xz_dec_stream.c:26
context
unsigned context
Definition
tlb.h:1
Generated by
1.18.0