This source file includes following definitions.
- tar_represent_uintmax
1
2 #ifndef MC__VFS_TAR_INTERNAL_H
3 #define MC__VFS_TAR_INTERNAL_H
4
5 #include <inttypes.h>
6 #include <limits.h>
7 #include <sys/stat.h>
8 #include <sys/types.h>
9
10 #ifdef HAVE_STDCKDINT_H
11 #include <stdckdint.h>
12 #else
13 #include "lib/stdckdint.h"
14 #endif
15 #include "lib/intprops.h"
16 #include "lib/idx.h"
17 #include "lib/vfs/xdirentry.h"
18
19
20
21
22 #define BLOCKSIZE 512
23
24 #define DEFAULT_BLOCKING 20
25
26
27
28
29
30
31
32
33
34
35 #define SPARSES_IN_EXTRA_HEADER 16
36 #define SPARSES_IN_OLDGNU_HEADER 4
37 #define SPARSES_IN_SPARSE_HEADER 21
38
39 #define SPARSES_IN_STAR_HEADER 4
40 #define SPARSES_IN_STAR_EXT_HEADER 21
41
42
43
44
45
46
47
48
49
50
51
52
53 #define GNUTYPE_DUMPDIR 'D'
54
55
56 #define GNUTYPE_LONGLINK 'K'
57
58
59 #define GNUTYPE_LONGNAME 'L'
60
61
62 #define SOLARIS_XHDTYPE 'X'
63
64 #define GNUTYPE_SPARSE 'S'
65
66 #define OFF_FROM_HEADER(where) off_from_header (where, sizeof (where))
67
68
69
70
71
72
73 struct posix_header
74 {
75 char name[100];
76 char mode[8];
77 char uid[8];
78 char gid[8];
79 char size[12];
80 char mtime[12];
81 char chksum[8];
82 char typeflag;
83 char linkname[100];
84 char magic[6];
85 char version[2];
86 char uname[32];
87 char gname[32];
88 char devmajor[8];
89 char devminor[8];
90 char prefix[155];
91
92 };
93
94
95 struct sparse
96 {
97 char offset[12];
98 char numbytes[12];
99
100 };
101
102
103
104
105
106 struct sparse_header
107 {
108 struct sparse sp[SPARSES_IN_SPARSE_HEADER];
109
110 char isextended;
111
112 };
113
114
115
116
117
118
119
120
121 struct oldgnu_header
122 {
123 char unused_pad1[345];
124 char atime[12];
125 char ctime[12];
126 char offset[12];
127 char longnames[4];
128 char unused_pad2;
129 struct sparse sp[SPARSES_IN_OLDGNU_HEADER];
130
131 char isextended;
132 char realsize[12];
133
134 };
135
136
137 struct star_header
138 {
139 char name[100];
140 char mode[8];
141 char uid[8];
142 char gid[8];
143 char size[12];
144 char mtime[12];
145 char chksum[8];
146 char typeflag;
147 char linkname[100];
148 char magic[6];
149 char version[2];
150 char uname[32];
151 char gname[32];
152 char devmajor[8];
153 char devminor[8];
154 char prefix[131];
155 char atime[12];
156 char ctime[12];
157
158 };
159
160 struct star_in_header
161 {
162 char fill[345];
163 char prefix[1];
164 char fill2;
165 char fill3[8];
166 char isextended;
167 struct sparse sp[SPARSES_IN_STAR_HEADER];
168 char realsize[12];
169 char offset[12];
170 char atime[12];
171 char ctime[12];
172 char mfill[8];
173 char xmagic[4];
174 };
175
176 struct star_ext_header
177 {
178 struct sparse sp[SPARSES_IN_STAR_EXT_HEADER];
179 char isextended;
180 };
181
182
183 union block
184 {
185 char buffer[BLOCKSIZE];
186 struct posix_header header;
187 struct star_header star_header;
188 struct oldgnu_header oldgnu_header;
189 struct sparse_header sparse_header;
190 struct star_in_header star_in_header;
191 struct star_ext_header star_ext_header;
192 };
193
194
195 struct sp_array
196 {
197 off_t offset;
198 off_t numbytes;
199 off_t arch_offset;
200 };
201
202 enum dump_status
203 {
204 dump_status_ok,
205 dump_status_short,
206 dump_status_fail,
207 dump_status_not_implemented
208 };
209
210 enum archive_format
211 {
212 TAR_UNKNOWN = 0,
213 TAR_V7,
214 TAR_OLDGNU,
215 TAR_USTAR,
216 TAR_POSIX,
217 TAR_STAR,
218 TAR_GNU
219 };
220
221 typedef struct
222 {
223 struct vfs_s_super base;
224
225 int fd;
226 struct stat st;
227 enum archive_format type;
228 union block *record_start;
229 } tar_super_t;
230
231 struct xheader
232 {
233 size_t size;
234 char *buffer;
235 };
236
237 struct tar_stat_info
238 {
239 char *orig_file_name;
240 char *file_name;
241 char *link_name;
242 #if 0
243 char *uname;
244 char *gname;
245 #endif
246 struct stat stat;
247
248
249
250 struct timespec atime;
251 struct timespec mtime;
252 struct timespec ctime;
253
254 off_t archive_file_size;
255
256 gboolean is_sparse;
257
258
259 intmax_t sparse_major;
260 intmax_t sparse_minor;
261 GArray *sparse_map;
262
263 off_t real_size;
264 gboolean real_size_set;
265
266 gboolean
267 sparse_name_done;
268
269
270
271 struct xheader xhdr;
272
273
274 gboolean is_dumpdir;
275 gboolean skipped;
276 char *dumpdir;
277 };
278
279
280
281 extern const idx_t blocking_factor;
282 extern const idx_t record_size;
283
284 extern union block *record_end;
285 extern union block *current_block;
286 extern off_t record_start_block;
287
288 extern union block *current_header;
289
290
291 extern gboolean hit_eof;
292
293 extern struct tar_stat_info current_stat_info;
294
295
296
297
298 gboolean is_octal_digit (char c);
299 void tar_assign_string (char **string, char *value);
300 void tar_assign_string_dup (char **string, const char *value);
301 void tar_assign_string_dup_n (char **string, const char *value, size_t n);
302 intmax_t stoint (const char *arg, char **arglim, gboolean *overflow, intmax_t minval,
303 uintmax_t maxval);
304 intmax_t tar_from_header (const char *where0, size_t digs, char const *type, intmax_t minval,
305 uintmax_t maxval, gboolean octal_only);
306 off_t off_from_header (const char *p, size_t s);
307 union block *tar_find_next_block (tar_super_t *archive);
308 gboolean tar_set_next_block_after (union block *block);
309 off_t tar_current_block_ordinal (const tar_super_t *archive);
310 gboolean tar_skip_file (tar_super_t *archive, off_t size);
311
312
313 gboolean tar_sparse_member_p (tar_super_t *archive, struct tar_stat_info *st);
314 gboolean tar_sparse_fixup_header (tar_super_t *archive, struct tar_stat_info *st);
315 enum dump_status tar_sparse_skip_file (tar_super_t *archive, struct tar_stat_info *st);
316
317
318 gboolean tar_xheader_decode (struct tar_stat_info *st);
319 gboolean tar_xheader_read (tar_super_t *archive, struct xheader *xhdr, union block *header,
320 off_t size);
321 gboolean tar_xheader_decode_global (struct xheader *xhdr);
322 void tar_xheader_destroy (struct xheader *xhdr);
323
324
325
326
327
328
329
330 #if !(UINTMAX_MAX / 2 <= INTMAX_MAX)
331 #error "tar_represent_uintmax() returns intmax_t to represent uintmax_t"
332 #endif
333 static inline intmax_t
334 tar_represent_uintmax (uintmax_t n)
335 {
336 intmax_t nd;
337
338 if (n <= INTMAX_MAX)
339 return n;
340
341
342 nd = n - INTMAX_MIN;
343 return nd + INTMAX_MIN;
344 }
345
346 #endif