source: rtems/cpukit/libmisc/untar/untar.h @ 1a8fe67a

Last change on this file since 1a8fe67a was 1a8fe67a, checked in by Alexander Krutwig <alexander.krutwig@…>, on Jul 13, 2016 at 7:22:35 AM

Add Untar_FromChunk_Print() + Test

  • Property mode set to 100644
File size: 3.7 KB
Line 
1/**
2 * @file
3 *
4 * @brief Untar an Image
5 *
6 * This file defines the interface to methods which can untar an image.
7 */
8
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
24#include <rtems/print.h>
25
26/**
27 *  @defgroup libmisc_untar_img Untar Image
28 *
29 *  @ingroup libmisc
30 */
31/**@{*/
32#ifdef __cplusplus
33extern "C" {
34#endif
35
36#define UNTAR_SUCCESSFUL         0
37#define UNTAR_FAIL               1
38#define UNTAR_INVALID_CHECKSUM   2
39#define UNTAR_INVALID_HEADER     3
40
41
42int Untar_FromMemory(void *tar_buf, size_t size);
43int Untar_FromMemory_Print(void *tar_buf, size_t size, const rtems_printer* printer);
44int Untar_FromFile(const char *tar_name);
45int Untar_FromFile_Print(const char *tar_name, const rtems_printer* printer);
46
47typedef struct {
48  /**
49   * @brief Current context state.
50   */
51  enum {
52    UNTAR_CHUNK_HEADER,
53    UNTAR_CHUNK_SKIP,
54    UNTAR_CHUNK_WRITE,
55    UNTAR_CHUNK_ERROR
56  } state;
57
58  /**
59   * @brief Header buffer.
60   */
61  char header[512];
62
63  /**
64   * @brief Name buffer.
65   */
66  char fname[100];
67
68  /**
69   * @brief Number of bytes of overall length are already processed.
70   */
71  size_t done_bytes;
72
73  /**
74   * @brief Overall amount of bytes to be processed.
75   */
76  long unsigned todo_bytes;
77
78  /**
79   * @brief Overall amount of blocks to be processed.
80   */
81  unsigned long todo_blocks;
82
83  /**
84   * @brief File descriptor of output file.
85   */
86  int out_fd;
87} Untar_ChunkContext;
88
89typedef struct {
90  /**
91   * @brief Instance of Chunk Context needed for tar decompression.
92   */
93  Untar_ChunkContext base;
94
95  /**
96   * @brief Current zlib context.
97   */
98  z_stream strm;
99
100  /**
101   * @brief Buffer that contains the inflated data.
102   */
103  void *inflateBuffer;
104
105  /**
106   * @brief Size of buffer that contains the inflated data.
107   */
108  size_t inflateBufferSize;
109
110} Untar_GzChunkContext;
111
112/**
113 * @brief Initializes the Untar_ChunkContext files out of a part of a block of
114 * memory.
115 *
116 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
117 */
118void Untar_ChunkContext_Init(Untar_ChunkContext *context);
119
120/*
121 * @brief Rips links, directories and files out of a part of a block of memory.
122 *
123 * @param Untar_ChunkContext *context [in] Pointer to a context structure.
124 * @param void *chunk [in] Pointer to a chunk of a TAR buffer.
125 * @param size_t chunk_size [in] Length of the chunk of a TAR buffer.
126 *
127 * @retval UNTAR_SUCCESSFUL (0)    on successful completion.
128 * @retval UNTAR_FAIL              for a faulty step within the process.
129 * @retval UNTAR_INVALID_CHECKSUM  for an invalid header checksum.
130 * @retval UNTAR_INVALID_HEADER    for an invalid header.
131 */
132
133int Untar_FromChunk_Print(
134  Untar_ChunkContext *context,
135  void *chunk,
136  size_t chunk_size,
137  const rtems_printer* printer
138);
139
140/**************************************************************************
141 * This converts octal ASCII number representations into an
142 * unsigned long.  Only support 32-bit numbers for now.
143 *************************************************************************/
144extern unsigned long
145_rtems_octal2ulong(const char *octascii, size_t len);
146
147/************************************************************************
148 * Compute the TAR checksum and check with the value in
149 * the archive.  The checksum is computed over the entire
150 * header, but the checksum field is substituted with blanks.
151 ************************************************************************/
152extern int
153_rtems_tar_header_checksum(const char *bufr);
154
155#ifdef __cplusplus
156}
157#endif
158/**@}*/
159#endif  /* _RTEMS_UNTAR_H */
Note: See TracBrowser for help on using the repository browser.