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