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