]>
Commit | Line | Data |
---|---|---|
eaae26f3 TK |
1 | /*- |
2 | * Copyright (c) 2003-2007 Tim Kientzle | |
3 | * All rights reserved. | |
4 | * | |
5 | * Redistribution and use in source and binary forms, with or without | |
6 | * modification, are permitted provided that the following conditions | |
7 | * are met: | |
8 | * 1. Redistributions of source code must retain the above copyright | |
9 | * notice, this list of conditions and the following disclaimer. | |
10 | * 2. Redistributions in binary form must reproduce the above copyright | |
11 | * notice, this list of conditions and the following disclaimer in the | |
12 | * documentation and/or other materials provided with the distribution. | |
13 | * | |
14 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR | |
15 | * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |
16 | * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. | |
17 | * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, | |
18 | * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT | |
19 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
20 | * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
21 | * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
22 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | |
23 | * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
24 | * | |
25 | * $FreeBSD: src/lib/libarchive/archive.h.in,v 1.50 2008/05/26 17:00:22 kientzle Exp $ | |
26 | */ | |
27 | ||
28 | #ifndef ARCHIVE_H_INCLUDED | |
29 | #define ARCHIVE_H_INCLUDED | |
30 | ||
31 | /* | |
32 | * Note: archive.h is for use outside of libarchive; the configuration | |
33 | * headers (config.h, archive_platform.h, etc.) are purely internal. | |
34 | * Do NOT use HAVE_XXX configuration macros to control the behavior of | |
35 | * this header! If you must conditionalize, use predefined compiler and/or | |
36 | * platform macros. | |
37 | */ | |
38 | ||
39 | #include <sys/types.h> /* Linux requires this for off_t */ | |
40 | #if !defined(__WATCOMC__) && !defined(_MSC_VER) | |
41 | /* Header unavailable on Watcom C or MS Visual C++. */ | |
42 | #include <inttypes.h> /* int64_t, etc. */ | |
43 | #endif | |
44 | #include <stdio.h> /* For FILE * */ | |
45 | ||
46 | /* Get appropriate definitions of standard POSIX-style types. */ | |
47 | /* These should match the types used in 'struct stat' */ | |
48 | #ifdef _WIN32 | |
07be984c | 49 | #define __LA_INT64_T __int64 |
b05b5e14 TK |
50 | # if defined(_WIN64) |
51 | # define __LA_SSIZE_T __int64 | |
52 | # else | |
53 | # define __LA_SSIZE_T long | |
54 | # endif | |
eaae26f3 TK |
55 | #define __LA_UID_T unsigned int |
56 | #define __LA_GID_T unsigned int | |
57 | #else | |
58 | #include <unistd.h> /* ssize_t, uid_t, and gid_t */ | |
07be984c | 59 | #define __LA_INT64_T int64_t |
eaae26f3 TK |
60 | #define __LA_SSIZE_T ssize_t |
61 | #define __LA_UID_T uid_t | |
62 | #define __LA_GID_T gid_t | |
63 | #endif | |
64 | ||
65 | /* | |
66 | * On Windows, define LIBARCHIVE_STATIC if you're building or using a | |
67 | * .lib. The default here assumes you're building a DLL. Only | |
68 | * libarchive source should ever define __LIBARCHIVE_BUILD. | |
69 | */ | |
70 | #if ((defined __WIN32__) || (defined _WIN32)) && (!defined LIBARCHIVE_STATIC) | |
71 | # ifdef __LIBARCHIVE_BUILD | |
72 | # ifdef __GNUC__ | |
73 | # define __LA_DECL __attribute__((dllexport)) extern | |
74 | # else | |
75 | # define __LA_DECL __declspec(dllexport) | |
76 | # endif | |
77 | # else | |
78 | # ifdef __GNUC__ | |
79 | # define __LA_DECL __attribute__((dllimport)) extern | |
80 | # else | |
81 | # define __LA_DECL __declspec(dllimport) | |
82 | # endif | |
83 | # endif | |
84 | #else | |
85 | /* Static libraries or non-Windows needs no special declaration. */ | |
86 | # define __LA_DECL | |
87 | #endif | |
88 | ||
eaae26f3 TK |
89 | #ifdef __cplusplus |
90 | extern "C" { | |
91 | #endif | |
92 | ||
93 | /* | |
94 | * The version number is provided as both a macro and a function. | |
95 | * The macro identifies the installed header; the function identifies | |
96 | * the library version (which may not be the same if you're using a | |
97 | * dynamically-linked version of the library). Of course, if the | |
98 | * header and library are very different, you should expect some | |
99 | * strangeness. Don't do that. | |
100 | */ | |
101 | ||
102 | /* | |
103 | * The version number is expressed as a single integer that makes it | |
104 | * easy to compare versions at build time: for version a.b.c, the | |
105 | * version number is printf("%d%03d%03d",a,b,c). For example, if you | |
106 | * know your application requires version 2.12.108 or later, you can | |
107 | * assert that ARCHIVE_VERSION >= 2012108. | |
108 | * | |
109 | * This single-number format was introduced with libarchive 1.9.0 in | |
110 | * the libarchive 1.x family and libarchive 2.2.4 in the libarchive | |
111 | * 2.x family. The following may be useful if you really want to do | |
112 | * feature detection for earlier libarchive versions (which defined | |
113 | * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead): | |
114 | * | |
115 | * #ifndef ARCHIVE_VERSION_NUMBER | |
116 | * #define ARCHIVE_VERSION_NUMBER \ | |
117 | * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) | |
118 | * #endif | |
119 | */ | |
03bba7f9 | 120 | #define ARCHIVE_VERSION_NUMBER 2006900 |
eaae26f3 TK |
121 | __LA_DECL int archive_version_number(void); |
122 | ||
123 | /* | |
124 | * Textual name/version of the library, useful for version displays. | |
125 | */ | |
03bba7f9 | 126 | #define ARCHIVE_VERSION_STRING "libarchive 2.6.900a" |
eaae26f3 TK |
127 | __LA_DECL const char * archive_version_string(void); |
128 | ||
129 | #if ARCHIVE_VERSION_NUMBER < 3000000 | |
130 | /* | |
131 | * Deprecated; these are older names that will be removed in favor of | |
132 | * the simpler definitions above. | |
133 | */ | |
134 | #define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER | |
135 | __LA_DECL int archive_version_stamp(void); | |
136 | #define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING | |
137 | __LA_DECL const char * archive_version(void); | |
138 | #define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000) | |
139 | __LA_DECL int archive_api_version(void); | |
140 | #define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000) | |
141 | __LA_DECL int archive_api_feature(void); | |
142 | #endif | |
143 | ||
144 | #if ARCHIVE_VERSION_NUMBER < 3000000 | |
145 | /* This should never have been here in the first place. */ | |
146 | /* Legacy of old tar assumptions, will be removed in libarchive 3.0. */ | |
147 | #define ARCHIVE_BYTES_PER_RECORD 512 | |
148 | #define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240 | |
149 | #endif | |
150 | ||
151 | /* Declare our basic types. */ | |
152 | struct archive; | |
153 | struct archive_entry; | |
154 | ||
155 | /* | |
156 | * Error codes: Use archive_errno() and archive_error_string() | |
157 | * to retrieve details. Unless specified otherwise, all functions | |
158 | * that return 'int' use these codes. | |
159 | */ | |
160 | #define ARCHIVE_EOF 1 /* Found end of archive. */ | |
161 | #define ARCHIVE_OK 0 /* Operation was successful. */ | |
162 | #define ARCHIVE_RETRY (-10) /* Retry might succeed. */ | |
163 | #define ARCHIVE_WARN (-20) /* Partial success. */ | |
164 | /* For example, if write_header "fails", then you can't push data. */ | |
165 | #define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ | |
166 | /* But if write_header is "fatal," then this archive is dead and useless. */ | |
167 | #define ARCHIVE_FATAL (-30) /* No more operations are possible. */ | |
168 | ||
169 | /* | |
170 | * As far as possible, archive_errno returns standard platform errno codes. | |
171 | * Of course, the details vary by platform, so the actual definitions | |
172 | * here are stored in "archive_platform.h". The symbols are listed here | |
173 | * for reference; as a rule, clients should not need to know the exact | |
174 | * platform-dependent error code. | |
175 | */ | |
176 | /* Unrecognized or invalid file format. */ | |
177 | /* #define ARCHIVE_ERRNO_FILE_FORMAT */ | |
178 | /* Illegal usage of the library. */ | |
179 | /* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ | |
180 | /* Unknown or unclassified error. */ | |
181 | /* #define ARCHIVE_ERRNO_MISC */ | |
182 | ||
183 | /* | |
184 | * Callbacks are invoked to automatically read/skip/write/open/close the | |
185 | * archive. You can provide your own for complex tasks (like breaking | |
186 | * archives across multiple tapes) or use standard ones built into the | |
187 | * library. | |
188 | */ | |
189 | ||
190 | /* Returns pointer and size of next block of data from archive. */ | |
fc95189e TK |
191 | typedef __LA_SSIZE_T archive_read_callback(struct archive *, |
192 | void *_client_data, const void **_buffer); | |
193 | ||
eaae26f3 TK |
194 | /* Skips at most request bytes from archive and returns the skipped amount */ |
195 | #if ARCHIVE_VERSION_NUMBER < 2000000 | |
fc95189e TK |
196 | /* Libarchive 1.0 used ssize_t for the return, which is only 32 bits |
197 | * on most 32-bit platforms; not large enough. */ | |
198 | typedef __LA_SSIZE_T archive_skip_callback(struct archive *, | |
199 | void *_client_data, size_t request); | |
200 | #elif ARCHIVE_VERSION_NUMBER < 3000000 | |
201 | /* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a | |
202 | * few other platforms where off_t varies with build settings. */ | |
203 | typedef off_t archive_skip_callback(struct archive *, | |
204 | void *_client_data, off_t request); | |
eaae26f3 | 205 | #else |
fc95189e TK |
206 | /* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be |
207 | * 64 bits on every platform. */ | |
208 | typedef __LA_INT64_T archive_skip_callback(struct archive *, | |
209 | void *_client_data, __LA_INT64_T request); | |
eaae26f3 | 210 | #endif |
fc95189e | 211 | |
eaae26f3 | 212 | /* Returns size actually written, zero on EOF, -1 on error. */ |
fc95189e TK |
213 | typedef __LA_SSIZE_T archive_write_callback(struct archive *, |
214 | void *_client_data, | |
215 | const void *_buffer, size_t _length); | |
216 | ||
217 | #if ARCHIVE_VERSION_NUMBER < 3000000 | |
218 | /* Open callback is actually never needed; remove it in libarchive 3.0. */ | |
eaae26f3 | 219 | typedef int archive_open_callback(struct archive *, void *_client_data); |
fc95189e TK |
220 | #endif |
221 | ||
eaae26f3 TK |
222 | typedef int archive_close_callback(struct archive *, void *_client_data); |
223 | ||
224 | /* | |
225 | * Codes for archive_compression. | |
226 | */ | |
227 | #define ARCHIVE_COMPRESSION_NONE 0 | |
228 | #define ARCHIVE_COMPRESSION_GZIP 1 | |
229 | #define ARCHIVE_COMPRESSION_BZIP2 2 | |
230 | #define ARCHIVE_COMPRESSION_COMPRESS 3 | |
231 | #define ARCHIVE_COMPRESSION_PROGRAM 4 | |
b1ab1b26 | 232 | #define ARCHIVE_COMPRESSION_LZMA 5 |
eaae26f3 TK |
233 | |
234 | /* | |
235 | * Codes returned by archive_format. | |
236 | * | |
237 | * Top 16 bits identifies the format family (e.g., "tar"); lower | |
238 | * 16 bits indicate the variant. This is updated by read_next_header. | |
239 | * Note that the lower 16 bits will often vary from entry to entry. | |
240 | * In some cases, this variation occurs as libarchive learns more about | |
241 | * the archive (for example, later entries might utilize extensions that | |
242 | * weren't necessary earlier in the archive; in this case, libarchive | |
243 | * will change the format code to indicate the extended format that | |
244 | * was used). In other cases, it's because different tools have | |
245 | * modified the archive and so different parts of the archive | |
246 | * actually have slightly different formts. (Both tar and cpio store | |
247 | * format codes in each entry, so it is quite possible for each | |
248 | * entry to be in a different format.) | |
249 | */ | |
250 | #define ARCHIVE_FORMAT_BASE_MASK 0xff0000 | |
251 | #define ARCHIVE_FORMAT_CPIO 0x10000 | |
252 | #define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) | |
253 | #define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) | |
254 | #define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) | |
255 | #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) | |
256 | #define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) | |
257 | #define ARCHIVE_FORMAT_SHAR 0x20000 | |
258 | #define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) | |
259 | #define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) | |
260 | #define ARCHIVE_FORMAT_TAR 0x30000 | |
261 | #define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) | |
262 | #define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) | |
263 | #define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) | |
264 | #define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) | |
265 | #define ARCHIVE_FORMAT_ISO9660 0x40000 | |
266 | #define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) | |
267 | #define ARCHIVE_FORMAT_ZIP 0x50000 | |
268 | #define ARCHIVE_FORMAT_EMPTY 0x60000 | |
269 | #define ARCHIVE_FORMAT_AR 0x70000 | |
270 | #define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) | |
271 | #define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) | |
272 | #define ARCHIVE_FORMAT_MTREE 0x80000 | |
eaae26f3 TK |
273 | |
274 | /*- | |
275 | * Basic outline for reading an archive: | |
276 | * 1) Ask archive_read_new for an archive reader object. | |
277 | * 2) Update any global properties as appropriate. | |
278 | * In particular, you'll certainly want to call appropriate | |
279 | * archive_read_support_XXX functions. | |
280 | * 3) Call archive_read_open_XXX to open the archive | |
281 | * 4) Repeatedly call archive_read_next_header to get information about | |
282 | * successive archive entries. Call archive_read_data to extract | |
283 | * data for entries of interest. | |
284 | * 5) Call archive_read_finish to end processing. | |
285 | */ | |
286 | __LA_DECL struct archive *archive_read_new(void); | |
287 | ||
288 | /* | |
289 | * The archive_read_support_XXX calls enable auto-detect for this | |
290 | * archive handle. They also link in the necessary support code. | |
291 | * For example, if you don't want bzlib linked in, don't invoke | |
292 | * support_compression_bzip2(). The "all" functions provide the | |
293 | * obvious shorthand. | |
294 | */ | |
295 | __LA_DECL int archive_read_support_compression_all(struct archive *); | |
296 | __LA_DECL int archive_read_support_compression_bzip2(struct archive *); | |
297 | __LA_DECL int archive_read_support_compression_compress(struct archive *); | |
298 | __LA_DECL int archive_read_support_compression_gzip(struct archive *); | |
07be984c | 299 | __LA_DECL int archive_read_support_compression_lzma(struct archive *); |
eaae26f3 TK |
300 | __LA_DECL int archive_read_support_compression_none(struct archive *); |
301 | __LA_DECL int archive_read_support_compression_program(struct archive *, | |
302 | const char *command); | |
303 | ||
304 | __LA_DECL int archive_read_support_format_all(struct archive *); | |
305 | __LA_DECL int archive_read_support_format_ar(struct archive *); | |
306 | __LA_DECL int archive_read_support_format_cpio(struct archive *); | |
307 | __LA_DECL int archive_read_support_format_empty(struct archive *); | |
308 | __LA_DECL int archive_read_support_format_gnutar(struct archive *); | |
309 | __LA_DECL int archive_read_support_format_iso9660(struct archive *); | |
310 | __LA_DECL int archive_read_support_format_mtree(struct archive *); | |
311 | __LA_DECL int archive_read_support_format_tar(struct archive *); | |
312 | __LA_DECL int archive_read_support_format_zip(struct archive *); | |
313 | ||
314 | ||
315 | /* Open the archive using callbacks for archive I/O. */ | |
316 | __LA_DECL int archive_read_open(struct archive *, void *_client_data, | |
317 | archive_open_callback *, archive_read_callback *, | |
318 | archive_close_callback *); | |
319 | __LA_DECL int archive_read_open2(struct archive *, void *_client_data, | |
320 | archive_open_callback *, archive_read_callback *, | |
321 | archive_skip_callback *, archive_close_callback *); | |
322 | ||
323 | /* | |
324 | * A variety of shortcuts that invoke archive_read_open() with | |
325 | * canned callbacks suitable for common situations. The ones that | |
326 | * accept a block size handle tape blocking correctly. | |
327 | */ | |
328 | /* Use this if you know the filename. Note: NULL indicates stdin. */ | |
329 | __LA_DECL int archive_read_open_filename(struct archive *, | |
330 | const char *_filename, size_t _block_size); | |
331 | /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ | |
332 | __LA_DECL int archive_read_open_file(struct archive *, | |
333 | const char *_filename, size_t _block_size); | |
334 | /* Read an archive that's stored in memory. */ | |
335 | __LA_DECL int archive_read_open_memory(struct archive *, | |
336 | void * buff, size_t size); | |
337 | /* A more involved version that is only used for internal testing. */ | |
338 | __LA_DECL int archive_read_open_memory2(struct archive *a, void *buff, | |
339 | size_t size, size_t read_size); | |
340 | /* Read an archive that's already open, using the file descriptor. */ | |
341 | __LA_DECL int archive_read_open_fd(struct archive *, int _fd, | |
342 | size_t _block_size); | |
343 | /* Read an archive that's already open, using a FILE *. */ | |
344 | /* Note: DO NOT use this with tape drives. */ | |
345 | __LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); | |
346 | ||
347 | /* Parses and returns next entry header. */ | |
348 | __LA_DECL int archive_read_next_header(struct archive *, | |
349 | struct archive_entry **); | |
350 | ||
351 | /* | |
352 | * Retrieve the byte offset in UNCOMPRESSED data where last-read | |
353 | * header started. | |
354 | */ | |
07be984c | 355 | __LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); |
eaae26f3 TK |
356 | |
357 | /* Read data from the body of an entry. Similar to read(2). */ | |
fc95189e TK |
358 | __LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, |
359 | void *, size_t); | |
360 | ||
eaae26f3 TK |
361 | /* |
362 | * A zero-copy version of archive_read_data that also exposes the file offset | |
363 | * of each returned block. Note that the client has no way to specify | |
364 | * the desired size of the block. The API does guarantee that offsets will | |
365 | * be strictly increasing and that returned blocks will not overlap. | |
366 | */ | |
fc95189e TK |
367 | #if ARCHIVE_VERSION_NUMBER < 3000000 |
368 | __LA_DECL int archive_read_data_block(struct archive *a, | |
369 | const void **buff, size_t *size, off_t *offset); | |
370 | #else | |
eaae26f3 | 371 | __LA_DECL int archive_read_data_block(struct archive *a, |
fc95189e TK |
372 | const void **buff, size_t *size, |
373 | __LA_INT64_T *offset); | |
374 | #endif | |
eaae26f3 TK |
375 | |
376 | /*- | |
377 | * Some convenience functions that are built on archive_read_data: | |
378 | * 'skip': skips entire entry | |
379 | * 'into_buffer': writes data into memory buffer that you provide | |
380 | * 'into_fd': writes data to specified filedes | |
381 | */ | |
382 | __LA_DECL int archive_read_data_skip(struct archive *); | |
fc95189e TK |
383 | __LA_DECL int archive_read_data_into_buffer(struct archive *, |
384 | void *buffer, __LA_SSIZE_T len); | |
eaae26f3 TK |
385 | __LA_DECL int archive_read_data_into_fd(struct archive *, int fd); |
386 | ||
387 | /*- | |
388 | * Convenience function to recreate the current entry (whose header | |
389 | * has just been read) on disk. | |
390 | * | |
391 | * This does quite a bit more than just copy data to disk. It also: | |
392 | * - Creates intermediate directories as required. | |
393 | * - Manages directory permissions: non-writable directories will | |
394 | * be initially created with write permission enabled; when the | |
395 | * archive is closed, dir permissions are edited to the values specified | |
396 | * in the archive. | |
397 | * - Checks hardlinks: hardlinks will not be extracted unless the | |
398 | * linked-to file was also extracted within the same session. (TODO) | |
399 | */ | |
400 | ||
401 | /* The "flags" argument selects optional behavior, 'OR' the flags you want. */ | |
402 | ||
403 | /* Default: Do not try to set owner/group. */ | |
404 | #define ARCHIVE_EXTRACT_OWNER (0x0001) | |
405 | /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ | |
406 | #define ARCHIVE_EXTRACT_PERM (0x0002) | |
407 | /* Default: Do not restore mtime/atime. */ | |
408 | #define ARCHIVE_EXTRACT_TIME (0x0004) | |
409 | /* Default: Replace existing files. */ | |
410 | #define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) | |
411 | /* Default: Try create first, unlink only if create fails with EEXIST. */ | |
412 | #define ARCHIVE_EXTRACT_UNLINK (0x0010) | |
413 | /* Default: Do not restore ACLs. */ | |
414 | #define ARCHIVE_EXTRACT_ACL (0x0020) | |
415 | /* Default: Do not restore fflags. */ | |
416 | #define ARCHIVE_EXTRACT_FFLAGS (0x0040) | |
417 | /* Default: Do not restore xattrs. */ | |
418 | #define ARCHIVE_EXTRACT_XATTR (0x0080) | |
419 | /* Default: Do not try to guard against extracts redirected by symlinks. */ | |
420 | /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ | |
421 | #define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) | |
422 | /* Default: Do not reject entries with '..' as path elements. */ | |
423 | #define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) | |
424 | /* Default: Create parent directories as needed. */ | |
425 | #define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) | |
426 | /* Default: Overwrite files, even if one on disk is newer. */ | |
427 | #define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) | |
428 | /* Detect blocks of 0 and write holes instead. */ | |
429 | #define ARCHIVE_EXTRACT_SPARSE (0x1000) | |
430 | ||
431 | __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, | |
432 | int flags); | |
433 | __LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, | |
434 | struct archive * /* dest */); | |
435 | __LA_DECL void archive_read_extract_set_progress_callback(struct archive *, | |
436 | void (*_progress_func)(void *), void *_user_data); | |
437 | ||
438 | /* Record the dev/ino of a file that will not be written. This is | |
439 | * generally set to the dev/ino of the archive being read. */ | |
440 | __LA_DECL void archive_read_extract_set_skip_file(struct archive *, | |
441 | dev_t, ino_t); | |
442 | ||
443 | /* Close the file and release most resources. */ | |
444 | __LA_DECL int archive_read_close(struct archive *); | |
445 | /* Release all resources and destroy the object. */ | |
446 | /* Note that archive_read_finish will call archive_read_close for you. */ | |
fc95189e | 447 | #if ARCHIVE_VERSION_NUMBER < 2000000 |
eaae26f3 TK |
448 | /* Erroneously declared to return void in libarchive 1.x */ |
449 | __LA_DECL void archive_read_finish(struct archive *); | |
fc95189e TK |
450 | #else |
451 | __LA_DECL int archive_read_finish(struct archive *); | |
eaae26f3 TK |
452 | #endif |
453 | ||
454 | /*- | |
455 | * To create an archive: | |
456 | * 1) Ask archive_write_new for a archive writer object. | |
457 | * 2) Set any global properties. In particular, you should set | |
458 | * the compression and format to use. | |
459 | * 3) Call archive_write_open to open the file (most people | |
460 | * will use archive_write_open_file or archive_write_open_fd, | |
461 | * which provide convenient canned I/O callbacks for you). | |
462 | * 4) For each entry: | |
463 | * - construct an appropriate struct archive_entry structure | |
464 | * - archive_write_header to write the header | |
465 | * - archive_write_data to write the entry data | |
466 | * 5) archive_write_close to close the output | |
467 | * 6) archive_write_finish to cleanup the writer and release resources | |
468 | */ | |
469 | __LA_DECL struct archive *archive_write_new(void); | |
470 | __LA_DECL int archive_write_set_bytes_per_block(struct archive *, | |
471 | int bytes_per_block); | |
472 | __LA_DECL int archive_write_get_bytes_per_block(struct archive *); | |
473 | /* XXX This is badly misnamed; suggestions appreciated. XXX */ | |
474 | __LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, | |
475 | int bytes_in_last_block); | |
476 | __LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); | |
477 | ||
478 | /* The dev/ino of a file that won't be archived. This is used | |
479 | * to avoid recursively adding an archive to itself. */ | |
480 | __LA_DECL int archive_write_set_skip_file(struct archive *, dev_t, ino_t); | |
481 | ||
482 | __LA_DECL int archive_write_set_compression_bzip2(struct archive *); | |
483 | __LA_DECL int archive_write_set_compression_compress(struct archive *); | |
484 | __LA_DECL int archive_write_set_compression_gzip(struct archive *); | |
485 | __LA_DECL int archive_write_set_compression_none(struct archive *); | |
486 | __LA_DECL int archive_write_set_compression_program(struct archive *, | |
487 | const char *cmd); | |
488 | /* A convenience function to set the format based on the code or name. */ | |
489 | __LA_DECL int archive_write_set_format(struct archive *, int format_code); | |
490 | __LA_DECL int archive_write_set_format_by_name(struct archive *, | |
491 | const char *name); | |
492 | /* To minimize link pollution, use one or more of the following. */ | |
493 | __LA_DECL int archive_write_set_format_ar_bsd(struct archive *); | |
494 | __LA_DECL int archive_write_set_format_ar_svr4(struct archive *); | |
495 | __LA_DECL int archive_write_set_format_cpio(struct archive *); | |
496 | __LA_DECL int archive_write_set_format_cpio_newc(struct archive *); | |
cedb073b | 497 | __LA_DECL int archive_write_set_format_mtree(struct archive *); |
eaae26f3 TK |
498 | /* TODO: int archive_write_set_format_old_tar(struct archive *); */ |
499 | __LA_DECL int archive_write_set_format_pax(struct archive *); | |
500 | __LA_DECL int archive_write_set_format_pax_restricted(struct archive *); | |
501 | __LA_DECL int archive_write_set_format_shar(struct archive *); | |
502 | __LA_DECL int archive_write_set_format_shar_dump(struct archive *); | |
503 | __LA_DECL int archive_write_set_format_ustar(struct archive *); | |
504 | __LA_DECL int archive_write_open(struct archive *, void *, | |
505 | archive_open_callback *, archive_write_callback *, | |
506 | archive_close_callback *); | |
507 | __LA_DECL int archive_write_open_fd(struct archive *, int _fd); | |
508 | __LA_DECL int archive_write_open_filename(struct archive *, const char *_file); | |
509 | /* A deprecated synonym for archive_write_open_filename() */ | |
510 | __LA_DECL int archive_write_open_file(struct archive *, const char *_file); | |
511 | __LA_DECL int archive_write_open_FILE(struct archive *, FILE *); | |
512 | /* _buffSize is the size of the buffer, _used refers to a variable that | |
513 | * will be updated after each write into the buffer. */ | |
514 | __LA_DECL int archive_write_open_memory(struct archive *, | |
515 | void *_buffer, size_t _buffSize, size_t *_used); | |
516 | ||
517 | /* | |
518 | * Note that the library will truncate writes beyond the size provided | |
519 | * to archive_write_header or pad if the provided data is short. | |
520 | */ | |
521 | __LA_DECL int archive_write_header(struct archive *, | |
522 | struct archive_entry *); | |
fc95189e | 523 | #if ARCHIVE_VERSION_NUMBER < 2000000 |
eaae26f3 | 524 | /* This was erroneously declared to return "int" in libarchive 1.x. */ |
fc95189e TK |
525 | __LA_DECL int archive_write_data(struct archive *, |
526 | const void *, size_t); | |
527 | #else | |
528 | /* Libarchive 2.0 and later return ssize_t here. */ | |
529 | __LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, | |
530 | const void *, size_t); | |
531 | #endif | |
532 | ||
533 | #if ARCHIVE_VERSION_NUMBER < 3000000 | |
534 | /* Libarchive 1.x and 2.x use off_t for the argument, but that's not | |
535 | * stable on Linux. */ | |
536 | __LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, | |
537 | const void *, size_t, off_t); | |
538 | #else | |
539 | /* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */ | |
540 | __LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, | |
541 | const void *, size_t, __LA_INT64_T); | |
eaae26f3 | 542 | #endif |
eaae26f3 TK |
543 | __LA_DECL int archive_write_finish_entry(struct archive *); |
544 | __LA_DECL int archive_write_close(struct archive *); | |
fc95189e | 545 | #if ARCHIVE_VERSION_NUMBER < 2000000 |
eaae26f3 TK |
546 | /* Return value was incorrect in libarchive 1.x. */ |
547 | __LA_DECL void archive_write_finish(struct archive *); | |
fc95189e TK |
548 | #else |
549 | /* Libarchive 2.x and later returns an error if this fails. */ | |
550 | /* It can fail if the archive wasn't already closed, in which case | |
551 | * archive_write_finish() will implicitly call archive_write_close(). */ | |
552 | __LA_DECL int archive_write_finish(struct archive *); | |
eaae26f3 TK |
553 | #endif |
554 | ||
555 | /*- | |
556 | * To create objects on disk: | |
557 | * 1) Ask archive_write_disk_new for a new archive_write_disk object. | |
558 | * 2) Set any global properties. In particular, you should set | |
559 | * the compression and format to use. | |
560 | * 3) For each entry: | |
561 | * - construct an appropriate struct archive_entry structure | |
562 | * - archive_write_header to create the file/dir/etc on disk | |
563 | * - archive_write_data to write the entry data | |
564 | * 4) archive_write_finish to cleanup the writer and release resources | |
565 | * | |
566 | * In particular, you can use this in conjunction with archive_read() | |
567 | * to pull entries out of an archive and create them on disk. | |
568 | */ | |
569 | __LA_DECL struct archive *archive_write_disk_new(void); | |
570 | /* This file will not be overwritten. */ | |
571 | __LA_DECL int archive_write_disk_set_skip_file(struct archive *, | |
572 | dev_t, ino_t); | |
573 | /* Set flags to control how the next item gets created. */ | |
574 | __LA_DECL int archive_write_disk_set_options(struct archive *, | |
575 | int flags); | |
576 | /* | |
577 | * The lookup functions are given uname/uid (or gname/gid) pairs and | |
578 | * return a uid (gid) suitable for this system. These are used for | |
579 | * restoring ownership and for setting ACLs. The default functions | |
580 | * are naive, they just return the uid/gid. These are small, so reasonable | |
581 | * for applications that don't need to preserve ownership; they | |
582 | * are probably also appropriate for applications that are doing | |
583 | * same-system backup and restore. | |
584 | */ | |
585 | /* | |
586 | * The "standard" lookup functions use common system calls to lookup | |
587 | * the uname/gname, falling back to the uid/gid if the names can't be | |
588 | * found. They cache lookups and are reasonably fast, but can be very | |
589 | * large, so they are not used unless you ask for them. In | |
590 | * particular, these match the specifications of POSIX "pax" and old | |
591 | * POSIX "tar". | |
592 | */ | |
593 | __LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); | |
594 | /* | |
595 | * If neither the default (naive) nor the standard (big) functions suit | |
596 | * your needs, you can write your own and register them. Be sure to | |
597 | * include a cleanup function if you have allocated private data. | |
598 | */ | |
599 | __LA_DECL int archive_write_disk_set_group_lookup(struct archive *, | |
600 | void * /* private_data */, | |
601 | __LA_GID_T (*)(void *, const char *, __LA_GID_T), | |
602 | void (* /* cleanup */)(void *)); | |
603 | __LA_DECL int archive_write_disk_set_user_lookup(struct archive *, | |
604 | void * /* private_data */, | |
605 | __LA_UID_T (*)(void *, const char *, __LA_UID_T), | |
606 | void (* /* cleanup */)(void *)); | |
607 | ||
608 | /* | |
609 | * Accessor functions to read/set various information in | |
610 | * the struct archive object: | |
611 | */ | |
612 | /* Bytes written after compression or read before decompression. */ | |
07be984c | 613 | __LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); |
eaae26f3 | 614 | /* Bytes written to compressor or read from decompressor. */ |
07be984c | 615 | __LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); |
eaae26f3 TK |
616 | |
617 | __LA_DECL const char *archive_compression_name(struct archive *); | |
618 | __LA_DECL int archive_compression(struct archive *); | |
619 | __LA_DECL int archive_errno(struct archive *); | |
620 | __LA_DECL const char *archive_error_string(struct archive *); | |
621 | __LA_DECL const char *archive_format_name(struct archive *); | |
622 | __LA_DECL int archive_format(struct archive *); | |
623 | __LA_DECL void archive_clear_error(struct archive *); | |
624 | __LA_DECL void archive_set_error(struct archive *, int _err, | |
625 | const char *fmt, ...); | |
626 | __LA_DECL void archive_copy_error(struct archive *dest, | |
627 | struct archive *src); | |
628 | ||
629 | #ifdef __cplusplus | |
630 | } | |
631 | #endif | |
632 | ||
1ca7365e | 633 | /* These are meaningless outside of this header. */ |
eaae26f3 | 634 | #undef __LA_DECL |
fa9a301c | 635 | #undef __LA_GID_T |
fa9a301c | 636 | #undef __LA_UID_T |
eaae26f3 | 637 | |
1ca7365e TK |
638 | /* These need to remain defined because they're used in the |
639 | * callback type definitions. XXX Fix this. This is ugly. XXX */ | |
640 | /* #undef __LA_INT64_T */ | |
641 | /* #undef __LA_SSIZE_T */ | |
642 | ||
eaae26f3 | 643 | #endif /* !ARCHIVE_H_INCLUDED */ |