1 | /* $Id: tar.h 98325 2023-01-26 16:16:07Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * IPRT - TAR Virtual Filesystem.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2010-2023 Oracle and/or its affiliates.
|
---|
8 | *
|
---|
9 | * This file is part of VirtualBox base platform packages, as
|
---|
10 | * available from https://www.virtualbox.org.
|
---|
11 | *
|
---|
12 | * This program is free software; you can redistribute it and/or
|
---|
13 | * modify it under the terms of the GNU General Public License
|
---|
14 | * as published by the Free Software Foundation, in version 3 of the
|
---|
15 | * License.
|
---|
16 | *
|
---|
17 | * This program is distributed in the hope that it will be useful, but
|
---|
18 | * WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | * General Public License for more details.
|
---|
21 | *
|
---|
22 | * You should have received a copy of the GNU General Public License
|
---|
23 | * along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | *
|
---|
25 | * The contents of this file may alternatively be used under the terms
|
---|
26 | * of the Common Development and Distribution License Version 1.0
|
---|
27 | * (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | * in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | * CDDL are applicable instead of those of the GPL.
|
---|
30 | *
|
---|
31 | * You may elect to license modified versions of this file under the
|
---|
32 | * terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | *
|
---|
34 | * SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | */
|
---|
36 |
|
---|
37 | #ifndef IPRT_INCLUDED_formats_tar_h
|
---|
38 | #define IPRT_INCLUDED_formats_tar_h
|
---|
39 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
40 | # pragma once
|
---|
41 | #endif
|
---|
42 |
|
---|
43 | #include <iprt/assert.h>
|
---|
44 |
|
---|
45 | /** @name RTZIPTARHDRPOSIX::typeflag
|
---|
46 | * @{ */
|
---|
47 | #define RTZIPTAR_TF_OLDNORMAL '\0' /**< Normal disk file, Unix compatible */
|
---|
48 | #define RTZIPTAR_TF_NORMAL '0' /**< Normal disk file */
|
---|
49 | #define RTZIPTAR_TF_LINK '1' /**< Link to previously dumped file */
|
---|
50 | #define RTZIPTAR_TF_SYMLINK '2' /**< Symbolic link */
|
---|
51 | #define RTZIPTAR_TF_CHR '3' /**< Character special file */
|
---|
52 | #define RTZIPTAR_TF_BLK '4' /**< Block special file */
|
---|
53 | #define RTZIPTAR_TF_DIR '5' /**< Directory */
|
---|
54 | #define RTZIPTAR_TF_FIFO '6' /**< FIFO special file */
|
---|
55 | #define RTZIPTAR_TF_CONTIG '7' /**< Contiguous file */
|
---|
56 |
|
---|
57 | #define RTZIPTAR_TF_X_HDR 'x' /**< Extended header. */
|
---|
58 | #define RTZIPTAR_TF_X_GLOBAL 'g' /**< Global extended header. */
|
---|
59 |
|
---|
60 | #define RTZIPTAR_TF_SOLARIS_XHDR 'X'
|
---|
61 |
|
---|
62 | #define RTZIPTAR_TF_GNU_DUMPDIR 'D'
|
---|
63 | #define RTZIPTAR_TF_GNU_LONGLINK 'K' /**< GNU long link header. */
|
---|
64 | #define RTZIPTAR_TF_GNU_LONGNAME 'L' /**< GNU long name header. */
|
---|
65 | #define RTZIPTAR_TF_GNU_MULTIVOL 'M'
|
---|
66 | #define RTZIPTAR_TF_GNU_SPARSE 'S'
|
---|
67 | #define RTZIPTAR_TF_GNU_VOLDHR 'V'
|
---|
68 | /** @} */
|
---|
69 |
|
---|
70 | /** Maximum length of a tar filename, excluding the terminating '\0'. More
|
---|
71 | * does not fit into a tar record. */
|
---|
72 | #define RTZIPTAR_NAME_MAX 99
|
---|
73 |
|
---|
74 |
|
---|
75 | /**
|
---|
76 | * The ancient tar header.
|
---|
77 | *
|
---|
78 | * The posix and gnu headers are compatible with the members up to and including
|
---|
79 | * link name, from there on they differ.
|
---|
80 | */
|
---|
81 | typedef struct RTZIPTARHDRANCIENT
|
---|
82 | {
|
---|
83 | char name[100];
|
---|
84 | char mode[8];
|
---|
85 | char uid[8];
|
---|
86 | char gid[8];
|
---|
87 | char size[12];
|
---|
88 | char mtime[12];
|
---|
89 | char chksum[8];
|
---|
90 | char typeflag;
|
---|
91 | char linkname[100]; /**< Was called linkflag. */
|
---|
92 | char unused[8+64+16+155+12];
|
---|
93 | } RTZIPTARHDRANCIENT;
|
---|
94 | AssertCompileSize(RTZIPTARHDRANCIENT, 512);
|
---|
95 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, name, 0);
|
---|
96 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, mode, 100);
|
---|
97 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, uid, 108);
|
---|
98 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, gid, 116);
|
---|
99 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, size, 124);
|
---|
100 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, mtime, 136);
|
---|
101 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, chksum, 148);
|
---|
102 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, typeflag, 156);
|
---|
103 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, linkname, 157);
|
---|
104 | AssertCompileMemberOffset(RTZIPTARHDRANCIENT, unused, 257);
|
---|
105 |
|
---|
106 |
|
---|
107 | /** The uniform standard tape archive format magic value. */
|
---|
108 | #define RTZIPTAR_USTAR_MAGIC "ustar"
|
---|
109 | /** The ustar version string.
|
---|
110 | * @remarks The terminator character is not part of the field. */
|
---|
111 | #define RTZIPTAR_USTAR_VERSION "00"
|
---|
112 |
|
---|
113 | /** The GNU magic + version value. */
|
---|
114 | #define RTZIPTAR_GNU_MAGIC "ustar "
|
---|
115 |
|
---|
116 |
|
---|
117 | /**
|
---|
118 | * The posix header (according to SuS).
|
---|
119 | */
|
---|
120 | typedef struct RTZIPTARHDRPOSIX
|
---|
121 | {
|
---|
122 | char name[100];
|
---|
123 | char mode[8];
|
---|
124 | char uid[8];
|
---|
125 | char gid[8];
|
---|
126 | char size[12];
|
---|
127 | char mtime[12];
|
---|
128 | char chksum[8];
|
---|
129 | char typeflag;
|
---|
130 | char linkname[100];
|
---|
131 | char magic[6];
|
---|
132 | char version[2];
|
---|
133 | char uname[32];
|
---|
134 | char gname[32];
|
---|
135 | char devmajor[8];
|
---|
136 | char devminor[8];
|
---|
137 | char prefix[155];
|
---|
138 | char unused[12];
|
---|
139 | } RTZIPTARHDRPOSIX;
|
---|
140 | AssertCompileSize(RTZIPTARHDRPOSIX, 512);
|
---|
141 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, name, 0);
|
---|
142 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, mode, 100);
|
---|
143 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, uid, 108);
|
---|
144 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, gid, 116);
|
---|
145 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, size, 124);
|
---|
146 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, mtime, 136);
|
---|
147 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, chksum, 148);
|
---|
148 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, typeflag, 156);
|
---|
149 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, linkname, 157);
|
---|
150 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, magic, 257);
|
---|
151 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, version, 263);
|
---|
152 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, uname, 265);
|
---|
153 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, gname, 297);
|
---|
154 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, devmajor, 329);
|
---|
155 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, devminor, 337);
|
---|
156 | AssertCompileMemberOffset(RTZIPTARHDRPOSIX, prefix, 345);
|
---|
157 |
|
---|
158 | /**
|
---|
159 | * GNU sparse data segment descriptor.
|
---|
160 | */
|
---|
161 | typedef struct RTZIPTARGNUSPARSE
|
---|
162 | {
|
---|
163 | char offset[12]; /**< Absolute offset relative to the start of the file. */
|
---|
164 | char numbytes[12];
|
---|
165 | } RTZIPTARGNUSPARSE;
|
---|
166 | AssertCompileSize(RTZIPTARGNUSPARSE, 24);
|
---|
167 | AssertCompileMemberOffset(RTZIPTARGNUSPARSE, offset, 0);
|
---|
168 | AssertCompileMemberOffset(RTZIPTARGNUSPARSE, numbytes, 12);
|
---|
169 | /** Pointer to a GNU sparse data segment descriptor. */
|
---|
170 | typedef RTZIPTARGNUSPARSE *PRTZIPTARGNUSPARSE;
|
---|
171 | /** Pointer to a const GNU sparse data segment descriptor. */
|
---|
172 | typedef RTZIPTARGNUSPARSE *PCRTZIPTARGNUSPARSE;
|
---|
173 |
|
---|
174 | /**
|
---|
175 | * The GNU header.
|
---|
176 | */
|
---|
177 | typedef struct RTZIPTARHDRGNU
|
---|
178 | {
|
---|
179 | char name[100];
|
---|
180 | char mode[8];
|
---|
181 | char uid[8];
|
---|
182 | char gid[8];
|
---|
183 | char size[12];
|
---|
184 | char mtime[12];
|
---|
185 | char chksum[8];
|
---|
186 | char typeflag;
|
---|
187 | char linkname[100];
|
---|
188 | char magic[8];
|
---|
189 | char uname[32];
|
---|
190 | char gname[32];
|
---|
191 | char devmajor[8];
|
---|
192 | char devminor[8];
|
---|
193 | char atime[12];
|
---|
194 | char ctime[12];
|
---|
195 | char offset[12]; /**< for multi-volume? */
|
---|
196 | char longnames[4]; /**< Seems to be unused. */
|
---|
197 | char unused[1];
|
---|
198 | RTZIPTARGNUSPARSE sparse[4];
|
---|
199 | char isextended; /**< More headers about sparse stuff if binary value 1. */
|
---|
200 | char realsize[12];
|
---|
201 | char unused2[17];
|
---|
202 | } RTZIPTARHDRGNU;
|
---|
203 | AssertCompileSize(RTZIPTARHDRGNU, 512);
|
---|
204 | AssertCompileMemberOffset(RTZIPTARHDRGNU, name, 0);
|
---|
205 | AssertCompileMemberOffset(RTZIPTARHDRGNU, mode, 100);
|
---|
206 | AssertCompileMemberOffset(RTZIPTARHDRGNU, uid, 108);
|
---|
207 | AssertCompileMemberOffset(RTZIPTARHDRGNU, gid, 116);
|
---|
208 | AssertCompileMemberOffset(RTZIPTARHDRGNU, size, 124);
|
---|
209 | AssertCompileMemberOffset(RTZIPTARHDRGNU, mtime, 136);
|
---|
210 | AssertCompileMemberOffset(RTZIPTARHDRGNU, chksum, 148);
|
---|
211 | AssertCompileMemberOffset(RTZIPTARHDRGNU, typeflag, 156);
|
---|
212 | AssertCompileMemberOffset(RTZIPTARHDRGNU, linkname, 157);
|
---|
213 | AssertCompileMemberOffset(RTZIPTARHDRGNU, magic, 257);
|
---|
214 | AssertCompileMemberOffset(RTZIPTARHDRGNU, uname, 265);
|
---|
215 | AssertCompileMemberOffset(RTZIPTARHDRGNU, gname, 297);
|
---|
216 | AssertCompileMemberOffset(RTZIPTARHDRGNU, devmajor, 329);
|
---|
217 | AssertCompileMemberOffset(RTZIPTARHDRGNU, devminor, 337);
|
---|
218 | AssertCompileMemberOffset(RTZIPTARHDRGNU, atime, 345);
|
---|
219 | AssertCompileMemberOffset(RTZIPTARHDRGNU, ctime, 357);
|
---|
220 | AssertCompileMemberOffset(RTZIPTARHDRGNU, offset, 369);
|
---|
221 | AssertCompileMemberOffset(RTZIPTARHDRGNU, longnames, 381);
|
---|
222 | AssertCompileMemberOffset(RTZIPTARHDRGNU, unused, 385);
|
---|
223 | AssertCompileMemberOffset(RTZIPTARHDRGNU, sparse, 386);
|
---|
224 | AssertCompileMemberOffset(RTZIPTARHDRGNU, isextended,482);
|
---|
225 | AssertCompileMemberOffset(RTZIPTARHDRGNU, realsize, 483);
|
---|
226 | AssertCompileMemberOffset(RTZIPTARHDRGNU, unused2, 495);
|
---|
227 |
|
---|
228 |
|
---|
229 | /**
|
---|
230 | * GNU sparse header.
|
---|
231 | */
|
---|
232 | typedef struct RTZIPTARHDRGNUSPARSE
|
---|
233 | {
|
---|
234 | RTZIPTARGNUSPARSE sp[21];
|
---|
235 | char isextended;
|
---|
236 | char unused[7];
|
---|
237 | } RTZIPTARHDRGNUSPARSE;
|
---|
238 | AssertCompileSize(RTZIPTARHDRGNUSPARSE, 512);
|
---|
239 | AssertCompileMemberOffset(RTZIPTARHDRGNUSPARSE, sp, 0);
|
---|
240 | AssertCompileMemberOffset(RTZIPTARHDRGNUSPARSE, isextended, 504);
|
---|
241 | AssertCompileMemberOffset(RTZIPTARHDRGNUSPARSE, unused, 505);
|
---|
242 |
|
---|
243 |
|
---|
244 | /**
|
---|
245 | * The bits common to posix and GNU.
|
---|
246 | */
|
---|
247 | typedef struct RTZIPTARHDRCOMMON
|
---|
248 | {
|
---|
249 | char name[100];
|
---|
250 | char mode[8];
|
---|
251 | char uid[8];
|
---|
252 | char gid[8];
|
---|
253 | char size[12];
|
---|
254 | char mtime[12];
|
---|
255 | char chksum[8];
|
---|
256 | char typeflag;
|
---|
257 | char linkname[100];
|
---|
258 | char magic[6];
|
---|
259 | char version[2];
|
---|
260 | char uname[32];
|
---|
261 | char gname[32];
|
---|
262 | char devmajor[8];
|
---|
263 | char devminor[8];
|
---|
264 | char not_common[155+12];
|
---|
265 | } RTZIPTARHDRCOMMON;
|
---|
266 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, name, RTZIPTARHDRPOSIX, name);
|
---|
267 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, mode, RTZIPTARHDRPOSIX, mode);
|
---|
268 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, uid, RTZIPTARHDRPOSIX, uid);
|
---|
269 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, gid, RTZIPTARHDRPOSIX, gid);
|
---|
270 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, size, RTZIPTARHDRPOSIX, size);
|
---|
271 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, mtime, RTZIPTARHDRPOSIX, mtime);
|
---|
272 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, chksum, RTZIPTARHDRPOSIX, chksum);
|
---|
273 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, typeflag, RTZIPTARHDRPOSIX, typeflag);
|
---|
274 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, linkname, RTZIPTARHDRPOSIX, linkname);
|
---|
275 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, magic, RTZIPTARHDRPOSIX, magic);
|
---|
276 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, version, RTZIPTARHDRPOSIX, version);
|
---|
277 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, uname, RTZIPTARHDRPOSIX, uname);
|
---|
278 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, gname, RTZIPTARHDRPOSIX, gname);
|
---|
279 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, devmajor, RTZIPTARHDRPOSIX, devmajor);
|
---|
280 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, devminor, RTZIPTARHDRPOSIX, devminor);
|
---|
281 |
|
---|
282 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, name, RTZIPTARHDRGNU, name);
|
---|
283 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, mode, RTZIPTARHDRGNU, mode);
|
---|
284 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, uid, RTZIPTARHDRGNU, uid);
|
---|
285 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, gid, RTZIPTARHDRGNU, gid);
|
---|
286 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, size, RTZIPTARHDRGNU, size);
|
---|
287 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, mtime, RTZIPTARHDRGNU, mtime);
|
---|
288 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, chksum, RTZIPTARHDRGNU, chksum);
|
---|
289 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, typeflag, RTZIPTARHDRGNU, typeflag);
|
---|
290 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, linkname, RTZIPTARHDRGNU, linkname);
|
---|
291 | AssertCompileMembersAtSameOffset( RTZIPTARHDRCOMMON, magic, RTZIPTARHDRGNU, magic);
|
---|
292 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, uname, RTZIPTARHDRGNU, uname);
|
---|
293 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, gname, RTZIPTARHDRGNU, gname);
|
---|
294 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, devmajor, RTZIPTARHDRGNU, devmajor);
|
---|
295 | AssertCompileMembersSameSizeAndOffset(RTZIPTARHDRCOMMON, devminor, RTZIPTARHDRGNU, devminor);
|
---|
296 |
|
---|
297 | #endif /* !IPRT_INCLUDED_formats_tar_h */
|
---|
298 |
|
---|