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