]> git.ipfire.org Git - thirdparty/libarchive.git/blame - libarchive/archive.h
Support z for (s)size_t.
[thirdparty/libarchive.git] / libarchive / archive.h
CommitLineData
eaae26f3 1/*-
911dc2bf 2 * Copyright (c) 2003-2010 Tim Kientzle
eaae26f3
TK
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 */
f828fbc1
BK
38#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
39# define __LA_STDINT_H <stdint.h>
40#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__)
41# define __LA_STDINT_H <inttypes.h>
42#endif
eaae26f3 43
a8ac0b18 44#include <sys/stat.h>
73f39d90
TK
45#if ARCHIVE_VERSION_NUMBER < 3000000
46#include <sys/types.h> /* Linux needs this for off_t; 3.0+ doesn't need it */
47#endif
f828fbc1
BK
48#ifdef __LA_STDINT_H
49# include __LA_STDINT_H /* int64_t, etc. */
eaae26f3
TK
50#endif
51#include <stdio.h> /* For FILE * */
52
53/* Get appropriate definitions of standard POSIX-style types. */
54/* These should match the types used in 'struct stat' */
44f9eb57 55#if defined(_WIN32) && !defined(__CYGWIN__)
07be984c 56#define __LA_INT64_T __int64
e0f0abf0
BK
57# if defined(_SSIZE_T_DEFINED)
58# define __LA_SSIZE_T ssize_t
59# elif defined(_WIN64)
b05b5e14
TK
60# define __LA_SSIZE_T __int64
61# else
62# define __LA_SSIZE_T long
63# endif
2566a7ab
BK
64# if defined(__BORLANDC__)
65# define __LA_UID_T uid_t
66# define __LA_GID_T gid_t
67# else
68# define __LA_UID_T short
69# define __LA_GID_T short
70# endif
eaae26f3
TK
71#else
72#include <unistd.h> /* ssize_t, uid_t, and gid_t */
07be984c 73#define __LA_INT64_T int64_t
eaae26f3
TK
74#define __LA_SSIZE_T ssize_t
75#define __LA_UID_T uid_t
76#define __LA_GID_T gid_t
77#endif
78
79/*
80 * On Windows, define LIBARCHIVE_STATIC if you're building or using a
81 * .lib. The default here assumes you're building a DLL. Only
82 * libarchive source should ever define __LIBARCHIVE_BUILD.
83 */
44f9eb57 84#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
eaae26f3
TK
85# ifdef __LIBARCHIVE_BUILD
86# ifdef __GNUC__
87# define __LA_DECL __attribute__((dllexport)) extern
88# else
89# define __LA_DECL __declspec(dllexport)
90# endif
91# else
92# ifdef __GNUC__
93# define __LA_DECL __attribute__((dllimport)) extern
94# else
95# define __LA_DECL __declspec(dllimport)
96# endif
97# endif
98#else
99/* Static libraries or non-Windows needs no special declaration. */
100# define __LA_DECL
101#endif
102
eaae26f3
TK
103#ifdef __cplusplus
104extern "C" {
105#endif
106
107/*
108 * The version number is provided as both a macro and a function.
109 * The macro identifies the installed header; the function identifies
110 * the library version (which may not be the same if you're using a
111 * dynamically-linked version of the library). Of course, if the
112 * header and library are very different, you should expect some
113 * strangeness. Don't do that.
114 */
115
116/*
117 * The version number is expressed as a single integer that makes it
118 * easy to compare versions at build time: for version a.b.c, the
119 * version number is printf("%d%03d%03d",a,b,c). For example, if you
120 * know your application requires version 2.12.108 or later, you can
121 * assert that ARCHIVE_VERSION >= 2012108.
122 *
123 * This single-number format was introduced with libarchive 1.9.0 in
124 * the libarchive 1.x family and libarchive 2.2.4 in the libarchive
125 * 2.x family. The following may be useful if you really want to do
126 * feature detection for earlier libarchive versions (which defined
127 * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead):
128 *
129 * #ifndef ARCHIVE_VERSION_NUMBER
130 * #define ARCHIVE_VERSION_NUMBER \
131 * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000)
132 * #endif
133 */
911dc2bf 134#define ARCHIVE_VERSION_NUMBER 3000000
eaae26f3
TK
135__LA_DECL int archive_version_number(void);
136
137/*
138 * Textual name/version of the library, useful for version displays.
139 */
911dc2bf 140#define ARCHIVE_VERSION_STRING "libarchive 3.0.0a"
eaae26f3
TK
141__LA_DECL const char * archive_version_string(void);
142
143#if ARCHIVE_VERSION_NUMBER < 3000000
144/*
145 * Deprecated; these are older names that will be removed in favor of
146 * the simpler definitions above.
147 */
148#define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER
149__LA_DECL int archive_version_stamp(void);
150#define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING
151__LA_DECL const char * archive_version(void);
152#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000)
153__LA_DECL int archive_api_version(void);
154#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000)
155__LA_DECL int archive_api_feature(void);
156#endif
157
158#if ARCHIVE_VERSION_NUMBER < 3000000
159/* This should never have been here in the first place. */
160/* Legacy of old tar assumptions, will be removed in libarchive 3.0. */
161#define ARCHIVE_BYTES_PER_RECORD 512
162#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240
163#endif
164
165/* Declare our basic types. */
166struct archive;
167struct archive_entry;
168
169/*
170 * Error codes: Use archive_errno() and archive_error_string()
171 * to retrieve details. Unless specified otherwise, all functions
172 * that return 'int' use these codes.
173 */
174#define ARCHIVE_EOF 1 /* Found end of archive. */
175#define ARCHIVE_OK 0 /* Operation was successful. */
176#define ARCHIVE_RETRY (-10) /* Retry might succeed. */
177#define ARCHIVE_WARN (-20) /* Partial success. */
178/* For example, if write_header "fails", then you can't push data. */
179#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */
180/* But if write_header is "fatal," then this archive is dead and useless. */
181#define ARCHIVE_FATAL (-30) /* No more operations are possible. */
182
183/*
184 * As far as possible, archive_errno returns standard platform errno codes.
185 * Of course, the details vary by platform, so the actual definitions
186 * here are stored in "archive_platform.h". The symbols are listed here
187 * for reference; as a rule, clients should not need to know the exact
188 * platform-dependent error code.
189 */
190/* Unrecognized or invalid file format. */
191/* #define ARCHIVE_ERRNO_FILE_FORMAT */
192/* Illegal usage of the library. */
193/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */
194/* Unknown or unclassified error. */
195/* #define ARCHIVE_ERRNO_MISC */
196
197/*
198 * Callbacks are invoked to automatically read/skip/write/open/close the
199 * archive. You can provide your own for complex tasks (like breaking
200 * archives across multiple tapes) or use standard ones built into the
201 * library.
202 */
203
204/* Returns pointer and size of next block of data from archive. */
fc95189e
TK
205typedef __LA_SSIZE_T archive_read_callback(struct archive *,
206 void *_client_data, const void **_buffer);
207
eaae26f3 208/* Skips at most request bytes from archive and returns the skipped amount */
afea1b2b 209#if ARCHIVE_VERSION_NUMBER < 3000000
fc95189e
TK
210/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a
211 * few other platforms where off_t varies with build settings. */
212typedef off_t archive_skip_callback(struct archive *,
213 void *_client_data, off_t request);
eaae26f3 214#else
fc95189e
TK
215/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be
216 * 64 bits on every platform. */
217typedef __LA_INT64_T archive_skip_callback(struct archive *,
218 void *_client_data, __LA_INT64_T request);
eaae26f3 219#endif
fc95189e 220
eaae26f3 221/* Returns size actually written, zero on EOF, -1 on error. */
fc95189e
TK
222typedef __LA_SSIZE_T archive_write_callback(struct archive *,
223 void *_client_data,
224 const void *_buffer, size_t _length);
225
eaae26f3 226typedef int archive_open_callback(struct archive *, void *_client_data);
fc95189e 227
eaae26f3
TK
228typedef int archive_close_callback(struct archive *, void *_client_data);
229
230/*
911dc2bf 231 * Codes to identify various stream filters.
eaae26f3 232 */
911dc2bf
TK
233#define ARCHIVE_FILTER_NONE 0
234#define ARCHIVE_FILTER_GZIP 1
235#define ARCHIVE_FILTER_BZIP2 2
236#define ARCHIVE_FILTER_COMPRESS 3
237#define ARCHIVE_FILTER_PROGRAM 4
238#define ARCHIVE_FILTER_LZMA 5
239#define ARCHIVE_FILTER_XZ 6
240#define ARCHIVE_FILTER_UU 7
241#define ARCHIVE_FILTER_RPM 8
242
243#if ARCHIVE_VERSION_NUMBER < 4000000
244#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE
245#define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP
246#define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2
247#define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS
248#define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM
249#define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA
250#define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ
251#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU
252#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM
253#endif
eaae26f3
TK
254
255/*
256 * Codes returned by archive_format.
257 *
258 * Top 16 bits identifies the format family (e.g., "tar"); lower
259 * 16 bits indicate the variant. This is updated by read_next_header.
260 * Note that the lower 16 bits will often vary from entry to entry.
261 * In some cases, this variation occurs as libarchive learns more about
262 * the archive (for example, later entries might utilize extensions that
263 * weren't necessary earlier in the archive; in this case, libarchive
264 * will change the format code to indicate the extended format that
265 * was used). In other cases, it's because different tools have
266 * modified the archive and so different parts of the archive
267 * actually have slightly different formts. (Both tar and cpio store
268 * format codes in each entry, so it is quite possible for each
269 * entry to be in a different format.)
270 */
271#define ARCHIVE_FORMAT_BASE_MASK 0xff0000
272#define ARCHIVE_FORMAT_CPIO 0x10000
273#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1)
274#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2)
275#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3)
276#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4)
277#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5)
19cc1b68 278#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6)
eaae26f3
TK
279#define ARCHIVE_FORMAT_SHAR 0x20000
280#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1)
281#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2)
282#define ARCHIVE_FORMAT_TAR 0x30000
283#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1)
284#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2)
285#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3)
286#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4)
287#define ARCHIVE_FORMAT_ISO9660 0x40000
288#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1)
289#define ARCHIVE_FORMAT_ZIP 0x50000
290#define ARCHIVE_FORMAT_EMPTY 0x60000
291#define ARCHIVE_FORMAT_AR 0x70000
292#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1)
293#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2)
294#define ARCHIVE_FORMAT_MTREE 0x80000
ccdb0318 295#define ARCHIVE_FORMAT_RAW 0x90000
d2c0930d 296#define ARCHIVE_FORMAT_XAR 0xA0000
eaae26f3
TK
297
298/*-
299 * Basic outline for reading an archive:
300 * 1) Ask archive_read_new for an archive reader object.
301 * 2) Update any global properties as appropriate.
302 * In particular, you'll certainly want to call appropriate
303 * archive_read_support_XXX functions.
304 * 3) Call archive_read_open_XXX to open the archive
305 * 4) Repeatedly call archive_read_next_header to get information about
306 * successive archive entries. Call archive_read_data to extract
307 * data for entries of interest.
308 * 5) Call archive_read_finish to end processing.
309 */
310__LA_DECL struct archive *archive_read_new(void);
311
312/*
313 * The archive_read_support_XXX calls enable auto-detect for this
314 * archive handle. They also link in the necessary support code.
315 * For example, if you don't want bzlib linked in, don't invoke
316 * support_compression_bzip2(). The "all" functions provide the
317 * obvious shorthand.
318 */
911dc2bf
TK
319/* TODO: Rename 'compression' here to 'filter' for libarchive 3.0, deprecate
320 * the old names. */
321
322__LA_DECL int archive_read_support_compression_all(struct archive *);
323__LA_DECL int archive_read_support_compression_bzip2(struct archive *);
324__LA_DECL int archive_read_support_compression_compress(struct archive *);
325__LA_DECL int archive_read_support_compression_gzip(struct archive *);
326__LA_DECL int archive_read_support_compression_lzma(struct archive *);
327__LA_DECL int archive_read_support_compression_none(struct archive *);
328__LA_DECL int archive_read_support_compression_program(struct archive *,
eaae26f3 329 const char *command);
911dc2bf
TK
330__LA_DECL int archive_read_support_compression_program_signature
331 (struct archive *, const char *,
21062430 332 const void * /* match */, size_t);
71aa143d 333
911dc2bf
TK
334__LA_DECL int archive_read_support_compression_rpm(struct archive *);
335__LA_DECL int archive_read_support_compression_uu(struct archive *);
336__LA_DECL int archive_read_support_compression_xz(struct archive *);
eaae26f3 337
911dc2bf
TK
338__LA_DECL int archive_read_support_format_all(struct archive *);
339__LA_DECL int archive_read_support_format_ar(struct archive *);
340__LA_DECL int archive_read_support_format_cpio(struct archive *);
341__LA_DECL int archive_read_support_format_empty(struct archive *);
342__LA_DECL int archive_read_support_format_gnutar(struct archive *);
343__LA_DECL int archive_read_support_format_iso9660(struct archive *);
344__LA_DECL int archive_read_support_format_mtree(struct archive *);
345__LA_DECL int archive_read_support_format_raw(struct archive *);
346__LA_DECL int archive_read_support_format_tar(struct archive *);
347__LA_DECL int archive_read_support_format_xar(struct archive *);
348__LA_DECL int archive_read_support_format_zip(struct archive *);
eaae26f3
TK
349
350
351/* Open the archive using callbacks for archive I/O. */
911dc2bf 352__LA_DECL int archive_read_open(struct archive *, void *_client_data,
eaae26f3
TK
353 archive_open_callback *, archive_read_callback *,
354 archive_close_callback *);
911dc2bf 355__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
eaae26f3
TK
356 archive_open_callback *, archive_read_callback *,
357 archive_skip_callback *, archive_close_callback *);
358
359/*
360 * A variety of shortcuts that invoke archive_read_open() with
361 * canned callbacks suitable for common situations. The ones that
362 * accept a block size handle tape blocking correctly.
363 */
364/* Use this if you know the filename. Note: NULL indicates stdin. */
911dc2bf 365__LA_DECL int archive_read_open_filename(struct archive *,
eaae26f3
TK
366 const char *_filename, size_t _block_size);
367/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
911dc2bf 368__LA_DECL int archive_read_open_file(struct archive *,
eaae26f3
TK
369 const char *_filename, size_t _block_size);
370/* Read an archive that's stored in memory. */
911dc2bf 371__LA_DECL int archive_read_open_memory(struct archive *,
eaae26f3
TK
372 void * buff, size_t size);
373/* A more involved version that is only used for internal testing. */
911dc2bf 374__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff,
eaae26f3
TK
375 size_t size, size_t read_size);
376/* Read an archive that's already open, using the file descriptor. */
911dc2bf 377__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
eaae26f3
TK
378 size_t _block_size);
379/* Read an archive that's already open, using a FILE *. */
380/* Note: DO NOT use this with tape drives. */
911dc2bf 381__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
eaae26f3
TK
382
383/* Parses and returns next entry header. */
911dc2bf 384__LA_DECL int archive_read_next_header(struct archive *,
eaae26f3
TK
385 struct archive_entry **);
386
ff12dfa8 387/* Parses and returns next entry header using the archive_entry passed in */
911dc2bf 388__LA_DECL int archive_read_next_header2(struct archive *,
ff12dfa8
TK
389 struct archive_entry *);
390
eaae26f3
TK
391/*
392 * Retrieve the byte offset in UNCOMPRESSED data where last-read
393 * header started.
394 */
07be984c 395__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *);
eaae26f3
TK
396
397/* Read data from the body of an entry. Similar to read(2). */
fc95189e
TK
398__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *,
399 void *, size_t);
400
eaae26f3
TK
401/*
402 * A zero-copy version of archive_read_data that also exposes the file offset
403 * of each returned block. Note that the client has no way to specify
404 * the desired size of the block. The API does guarantee that offsets will
405 * be strictly increasing and that returned blocks will not overlap.
406 */
fc95189e 407#if ARCHIVE_VERSION_NUMBER < 3000000
911dc2bf
TK
408__LA_DECL int archive_read_data_block(struct archive *a,
409 const void **buff, size_t *size, off_t *offset);
fc95189e 410#else
911dc2bf
TK
411__LA_DECL int archive_read_data_block(struct archive *a,
412 const void **buff, size_t *size, __LA_INT64_T *offset);
fc95189e 413#endif
eaae26f3
TK
414
415/*-
416 * Some convenience functions that are built on archive_read_data:
417 * 'skip': skips entire entry
418 * 'into_buffer': writes data into memory buffer that you provide
419 * 'into_fd': writes data to specified filedes
420 */
911dc2bf
TK
421__LA_DECL int archive_read_data_skip(struct archive *);
422__LA_DECL int archive_read_data_into_buffer(struct archive *,
fc95189e 423 void *buffer, __LA_SSIZE_T len);
911dc2bf 424__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
eaae26f3 425
6943997e
MN
426/*
427 * Set read options.
428 */
429/* Apply option string to the format only. */
911dc2bf 430__LA_DECL int archive_read_set_format_options(struct archive *_a,
6943997e
MN
431 const char *s);
432/* Apply option string to the filter only. */
911dc2bf 433__LA_DECL int archive_read_set_filter_options(struct archive *_a,
6943997e
MN
434 const char *s);
435/* Apply option string to both the format and the filter. */
911dc2bf 436__LA_DECL int archive_read_set_options(struct archive *_a,
6943997e
MN
437 const char *s);
438
eaae26f3
TK
439/*-
440 * Convenience function to recreate the current entry (whose header
441 * has just been read) on disk.
442 *
443 * This does quite a bit more than just copy data to disk. It also:
444 * - Creates intermediate directories as required.
445 * - Manages directory permissions: non-writable directories will
446 * be initially created with write permission enabled; when the
447 * archive is closed, dir permissions are edited to the values specified
448 * in the archive.
449 * - Checks hardlinks: hardlinks will not be extracted unless the
450 * linked-to file was also extracted within the same session. (TODO)
451 */
452
453/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
454
455/* Default: Do not try to set owner/group. */
456#define ARCHIVE_EXTRACT_OWNER (0x0001)
457/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
458#define ARCHIVE_EXTRACT_PERM (0x0002)
459/* Default: Do not restore mtime/atime. */
460#define ARCHIVE_EXTRACT_TIME (0x0004)
461/* Default: Replace existing files. */
462#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
463/* Default: Try create first, unlink only if create fails with EEXIST. */
464#define ARCHIVE_EXTRACT_UNLINK (0x0010)
465/* Default: Do not restore ACLs. */
466#define ARCHIVE_EXTRACT_ACL (0x0020)
467/* Default: Do not restore fflags. */
468#define ARCHIVE_EXTRACT_FFLAGS (0x0040)
469/* Default: Do not restore xattrs. */
470#define ARCHIVE_EXTRACT_XATTR (0x0080)
471/* Default: Do not try to guard against extracts redirected by symlinks. */
472/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
473#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
474/* Default: Do not reject entries with '..' as path elements. */
475#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
476/* Default: Create parent directories as needed. */
477#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
478/* Default: Overwrite files, even if one on disk is newer. */
479#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
480/* Detect blocks of 0 and write holes instead. */
481#define ARCHIVE_EXTRACT_SPARSE (0x1000)
482
911dc2bf 483__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
eaae26f3 484 int flags);
911dc2bf 485__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
eaae26f3
TK
486 struct archive * /* dest */);
487__LA_DECL void archive_read_extract_set_progress_callback(struct archive *,
488 void (*_progress_func)(void *), void *_user_data);
489
490/* Record the dev/ino of a file that will not be written. This is
491 * generally set to the dev/ino of the archive being read. */
73f39d90 492#if ARCHIVE_VERSION_NUMBER < 3000000
eaae26f3
TK
493__LA_DECL void archive_read_extract_set_skip_file(struct archive *,
494 dev_t, ino_t);
73f39d90
TK
495#else
496__LA_DECL void archive_read_extract_set_skip_file(struct archive *,
497 __LA_INT64_T, __LA_INT64_T);
498#endif
eaae26f3
TK
499
500/* Close the file and release most resources. */
501__LA_DECL int archive_read_close(struct archive *);
502/* Release all resources and destroy the object. */
9890b31f
TK
503/* Note that archive_read_free will call archive_read_close for you. */
504__LA_DECL int archive_read_free(struct archive *);
505#if ARCHIVE_VERSION_NUMBER < 4000000
506/* Synonym for archive_read_free() for backwards compatibility. */
fc95189e 507__LA_DECL int archive_read_finish(struct archive *);
9890b31f 508#endif
eaae26f3
TK
509
510/*-
511 * To create an archive:
512 * 1) Ask archive_write_new for a archive writer object.
513 * 2) Set any global properties. In particular, you should set
514 * the compression and format to use.
515 * 3) Call archive_write_open to open the file (most people
516 * will use archive_write_open_file or archive_write_open_fd,
517 * which provide convenient canned I/O callbacks for you).
518 * 4) For each entry:
519 * - construct an appropriate struct archive_entry structure
520 * - archive_write_header to write the header
521 * - archive_write_data to write the entry data
522 * 5) archive_write_close to close the output
9890b31f 523 * 6) archive_write_free to cleanup the writer and release resources
eaae26f3
TK
524 */
525__LA_DECL struct archive *archive_write_new(void);
911dc2bf 526__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
eaae26f3 527 int bytes_per_block);
911dc2bf 528__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
eaae26f3 529/* XXX This is badly misnamed; suggestions appreciated. XXX */
911dc2bf 530__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
eaae26f3 531 int bytes_in_last_block);
911dc2bf 532__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
eaae26f3
TK
533
534/* The dev/ino of a file that won't be archived. This is used
535 * to avoid recursively adding an archive to itself. */
73f39d90 536#if ARCHIVE_VERSION_NUMBER < 3000000
911dc2bf 537__LA_DECL int archive_write_set_skip_file(struct archive *, dev_t, ino_t);
73f39d90
TK
538#else
539__LA_DECL int archive_write_set_skip_file(struct archive *,
540 __LA_INT64_T, __LA_INT64_T);
541#endif
911dc2bf
TK
542
543#if ARCHIVE_VERSION_NUMBER < 4000000
544__LA_DECL int archive_write_set_compression_bzip2(struct archive *);
545__LA_DECL int archive_write_set_compression_compress(struct archive *);
546__LA_DECL int archive_write_set_compression_gzip(struct archive *);
547__LA_DECL int archive_write_set_compression_lzma(struct archive *);
548__LA_DECL int archive_write_set_compression_none(struct archive *);
549__LA_DECL int archive_write_set_compression_program(struct archive *,
550 const char *cmd);
551__LA_DECL int archive_write_set_compression_xz(struct archive *);
552#endif
553
554__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
555__LA_DECL int archive_write_add_filter_compress(struct archive *);
556__LA_DECL int archive_write_add_filter_gzip(struct archive *);
557__LA_DECL int archive_write_add_filter_lzma(struct archive *);
558__LA_DECL int archive_write_add_filter_none(struct archive *);
559__LA_DECL int archive_write_add_filter_program(struct archive *,
eaae26f3 560 const char *cmd);
911dc2bf
TK
561__LA_DECL int archive_write_add_filter_xz(struct archive *);
562
563
eaae26f3 564/* A convenience function to set the format based on the code or name. */
911dc2bf
TK
565__LA_DECL int archive_write_set_format(struct archive *, int format_code);
566__LA_DECL int archive_write_set_format_by_name(struct archive *,
eaae26f3
TK
567 const char *name);
568/* To minimize link pollution, use one or more of the following. */
911dc2bf
TK
569__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
570__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
571__LA_DECL int archive_write_set_format_cpio(struct archive *);
572__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
9d72ea76 573__LA_DECL int archive_write_set_format_iso9660(struct archive *);
911dc2bf 574__LA_DECL int archive_write_set_format_mtree(struct archive *);
eaae26f3 575/* TODO: int archive_write_set_format_old_tar(struct archive *); */
911dc2bf
TK
576__LA_DECL int archive_write_set_format_pax(struct archive *);
577__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
578__LA_DECL int archive_write_set_format_shar(struct archive *);
579__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
580__LA_DECL int archive_write_set_format_ustar(struct archive *);
581__LA_DECL int archive_write_set_format_zip(struct archive *);
582__LA_DECL int archive_write_open(struct archive *, void *,
eaae26f3
TK
583 archive_open_callback *, archive_write_callback *,
584 archive_close_callback *);
911dc2bf
TK
585__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
586__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
eaae26f3 587/* A deprecated synonym for archive_write_open_filename() */
911dc2bf
TK
588__LA_DECL int archive_write_open_file(struct archive *, const char *_file);
589__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
eaae26f3
TK
590/* _buffSize is the size of the buffer, _used refers to a variable that
591 * will be updated after each write into the buffer. */
911dc2bf 592__LA_DECL int archive_write_open_memory(struct archive *,
eaae26f3
TK
593 void *_buffer, size_t _buffSize, size_t *_used);
594
595/*
596 * Note that the library will truncate writes beyond the size provided
597 * to archive_write_header or pad if the provided data is short.
598 */
911dc2bf 599__LA_DECL int archive_write_header(struct archive *,
eaae26f3 600 struct archive_entry *);
911dc2bf 601__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *,
fc95189e 602 const void *, size_t);
fc95189e
TK
603
604#if ARCHIVE_VERSION_NUMBER < 3000000
605/* Libarchive 1.x and 2.x use off_t for the argument, but that's not
606 * stable on Linux. */
607__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *,
608 const void *, size_t, off_t);
609#else
610/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */
611__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *,
612 const void *, size_t, __LA_INT64_T);
eaae26f3 613#endif
eaae26f3
TK
614__LA_DECL int archive_write_finish_entry(struct archive *);
615__LA_DECL int archive_write_close(struct archive *);
9890b31f
TK
616/* This can fail if the archive wasn't already closed, in which case
617 * archive_write_free() will implicitly call archive_write_close(). */
618__LA_DECL int archive_write_free(struct archive *);
619#if ARCHIVE_VERSION_NUMBER < 4000000
620/* Synonym for archive_write_free() for backwards compatibility. */
fc95189e 621__LA_DECL int archive_write_finish(struct archive *);
9890b31f 622#endif
eaae26f3 623
6943997e
MN
624/*
625 * Set write options.
626 */
627/* Apply option string to the format only. */
628__LA_DECL int archive_write_set_format_options(struct archive *_a,
629 const char *s);
630/* Apply option string to the compressor only. */
631__LA_DECL int archive_write_set_compressor_options(struct archive *_a,
632 const char *s);
633/* Apply option string to both the format and the compressor. */
634__LA_DECL int archive_write_set_options(struct archive *_a,
635 const char *s);
636
eaae26f3 637/*-
2d892504
TK
638 * ARCHIVE_WRITE_DISK API
639 *
eaae26f3
TK
640 * To create objects on disk:
641 * 1) Ask archive_write_disk_new for a new archive_write_disk object.
2d892504
TK
642 * 2) Set any global properties. In particular, you probably
643 * want to set the options.
eaae26f3
TK
644 * 3) For each entry:
645 * - construct an appropriate struct archive_entry structure
646 * - archive_write_header to create the file/dir/etc on disk
647 * - archive_write_data to write the entry data
9890b31f 648 * 4) archive_write_free to cleanup the writer and release resources
eaae26f3
TK
649 *
650 * In particular, you can use this in conjunction with archive_read()
651 * to pull entries out of an archive and create them on disk.
652 */
653__LA_DECL struct archive *archive_write_disk_new(void);
654/* This file will not be overwritten. */
73f39d90 655#if ARCHIVE_VERSION_NUMBER < 3000000
eaae26f3
TK
656__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
657 dev_t, ino_t);
73f39d90
TK
658#else
659__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
660 __LA_INT64_T, __LA_INT64_T);
661#endif
2d892504
TK
662/* Set flags to control how the next item gets created.
663 * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
eaae26f3
TK
664__LA_DECL int archive_write_disk_set_options(struct archive *,
665 int flags);
666/*
667 * The lookup functions are given uname/uid (or gname/gid) pairs and
668 * return a uid (gid) suitable for this system. These are used for
669 * restoring ownership and for setting ACLs. The default functions
670 * are naive, they just return the uid/gid. These are small, so reasonable
671 * for applications that don't need to preserve ownership; they
672 * are probably also appropriate for applications that are doing
673 * same-system backup and restore.
674 */
675/*
676 * The "standard" lookup functions use common system calls to lookup
677 * the uname/gname, falling back to the uid/gid if the names can't be
678 * found. They cache lookups and are reasonably fast, but can be very
679 * large, so they are not used unless you ask for them. In
680 * particular, these match the specifications of POSIX "pax" and old
681 * POSIX "tar".
682 */
683__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *);
684/*
685 * If neither the default (naive) nor the standard (big) functions suit
686 * your needs, you can write your own and register them. Be sure to
687 * include a cleanup function if you have allocated private data.
688 */
73f39d90 689#if ARCHIVE_VERSION_NUMBER < 3000000
eaae26f3
TK
690__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
691 void * /* private_data */,
692 __LA_GID_T (*)(void *, const char *, __LA_GID_T),
693 void (* /* cleanup */)(void *));
694__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
695 void * /* private_data */,
696 __LA_UID_T (*)(void *, const char *, __LA_UID_T),
697 void (* /* cleanup */)(void *));
73f39d90
TK
698#else
699__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
700 void * /* private_data */,
701 __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
702 void (* /* cleanup */)(void *));
703__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
704 void * /* private_data */,
705 __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
706 void (* /* cleanup */)(void *));
707#endif
eaae26f3 708
aede8174
TK
709/*
710 * ARCHIVE_READ_DISK API
a8ac0b18
TK
711 *
712 * This is still evolving and somewhat experimental.
aede8174
TK
713 */
714__LA_DECL struct archive *archive_read_disk_new(void);
a8ac0b18
TK
715/* The names for symlink modes here correspond to an old BSD
716 * command-line argument convention: -L, -P, -H */
717/* Follow all symlinks. */
718__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
719/* Follow no symlinks. */
720__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
721/* Follow symlink initially, then not. */
722__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
723/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
724__LA_DECL int archive_read_disk_entry_from_file(struct archive *,
725 struct archive_entry *, int /* fd */, const struct stat *);
726/* Look up gname for gid or uname for uid. */
727/* Default implementations are very, very stupid. */
73f39d90 728#if ARCHIVE_VERSION_NUMBER < 3000000
aede8174
TK
729__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_GID_T);
730__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_UID_T);
73f39d90
TK
731#else
732__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T);
733__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T);
734#endif
a8ac0b18
TK
735/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
736 * results for performance. */
737__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *);
738/* You can install your own lookups if you like. */
73f39d90 739#if ARCHIVE_VERSION_NUMBER < 3000000
aede8174
TK
740__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *,
741 void * /* private_data */,
742 const char *(* /* lookup_fn */)(void *, __LA_GID_T),
743 void (* /* cleanup_fn */)(void *));
744__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *,
745 void * /* private_data */,
746 const char *(* /* lookup_fn */)(void *, __LA_UID_T),
747 void (* /* cleanup_fn */)(void *));
73f39d90
TK
748#else
749__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *,
750 void * /* private_data */,
751 const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
752 void (* /* cleanup_fn */)(void *));
753__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *,
754 void * /* private_data */,
755 const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
756 void (* /* cleanup_fn */)(void *));
757#endif
aede8174 758
eaae26f3
TK
759/*
760 * Accessor functions to read/set various information in
761 * the struct archive object:
762 */
911dc2bf
TK
763
764/* Number of filters in the current filter pipeline. */
765/* Filter #0 is the one closest to the format, -1 is a synonym for the
766 * last filter, which is always the pseudo-filter that wraps the
767 * client callbacks. */
768__LA_DECL int archive_filter_count(struct archive *);
769__LA_DECL __LA_INT64_T archive_filter_bytes(struct archive *, int);
770__LA_DECL int archive_filter_code(struct archive *, int);
771__LA_DECL const char * archive_filter_name(struct archive *, int);
772
773#if ARCHIVE_VERSION_NUMBER < 4000000
774/* These don't properly handle multiple filters, so are deprecated and
775 * will eventually be removed. */
776/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
07be984c 777__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *);
911dc2bf 778/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
07be984c 779__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *);
911dc2bf 780/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
eaae26f3 781__LA_DECL const char *archive_compression_name(struct archive *);
911dc2bf 782/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
eaae26f3 783__LA_DECL int archive_compression(struct archive *);
911dc2bf
TK
784#endif
785
eaae26f3
TK
786__LA_DECL int archive_errno(struct archive *);
787__LA_DECL const char *archive_error_string(struct archive *);
788__LA_DECL const char *archive_format_name(struct archive *);
789__LA_DECL int archive_format(struct archive *);
790__LA_DECL void archive_clear_error(struct archive *);
791__LA_DECL void archive_set_error(struct archive *, int _err,
792 const char *fmt, ...);
793__LA_DECL void archive_copy_error(struct archive *dest,
794 struct archive *src);
ab649de7 795__LA_DECL int archive_file_count(struct archive *);
eaae26f3
TK
796
797#ifdef __cplusplus
798}
799#endif
800
1ca7365e 801/* These are meaningless outside of this header. */
eaae26f3 802#undef __LA_DECL
fa9a301c 803#undef __LA_GID_T
fa9a301c 804#undef __LA_UID_T
eaae26f3 805
1ca7365e
TK
806/* These need to remain defined because they're used in the
807 * callback type definitions. XXX Fix this. This is ugly. XXX */
808/* #undef __LA_INT64_T */
809/* #undef __LA_SSIZE_T */
810
eaae26f3 811#endif /* !ARCHIVE_H_INCLUDED */