]> git.ipfire.org Git - thirdparty/libarchive.git/blame - libarchive/archive.h
Libarchive 3.4.1
[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
58a482eb
BK
31/*
32 * The version number is expressed as a single integer that makes it
33 * easy to compare versions at build time: for version a.b.c, the
34 * version number is printf("%d%03d%03d",a,b,c). For example, if you
35 * know your application requires version 2.12.108 or later, you can
36 * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
37 */
38/* Note: Compiler will complain if this does not match archive_entry.h! */
c0cc148d 39#define ARCHIVE_VERSION_NUMBER 3004001
58a482eb 40
7f2ca0da 41#include <sys/stat.h>
5773f6f3 42#include <stddef.h> /* for wchar_t */
7f2ca0da 43#include <stdio.h> /* For FILE * */
6dc7b803 44#include <time.h> /* For time_t */
7f2ca0da 45
eaae26f3
TK
46/*
47 * Note: archive.h is for use outside of libarchive; the configuration
48 * headers (config.h, archive_platform.h, etc.) are purely internal.
49 * Do NOT use HAVE_XXX configuration macros to control the behavior of
50 * this header! If you must conditionalize, use predefined compiler and/or
51 * platform macros.
52 */
f828fbc1 53#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
7f2ca0da 54# include <stdint.h>
566f61f7 55#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__) && !defined(__CLANG_INTTYPES_H)
7f2ca0da 56# include <inttypes.h>
eaae26f3 57#endif
eaae26f3 58
1880dfc5
TK
59/* Get appropriate definitions of 64-bit integer */
60#if !defined(__LA_INT64_T_DEFINED)
61/* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */
62# if ARCHIVE_VERSION_NUMBER < 4000000
5886b865 63#define __LA_INT64_T la_int64_t
1880dfc5
TK
64# endif
65#define __LA_INT64_T_DEFINED
66# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
72e98eb4 67typedef __int64 la_int64_t;
b05b5e14 68# else
dacf7241 69# include <unistd.h> /* ssize_t */
7f3fc930 70# if defined(_SCO_DS) || defined(__osf__)
72e98eb4 71typedef long long la_int64_t;
1880dfc5 72# else
72e98eb4 73typedef int64_t la_int64_t;
1880dfc5 74# endif
7f2ca0da 75# endif
1880dfc5
TK
76#endif
77
78/* The la_ssize_t should match the type used in 'struct stat' */
79#if !defined(__LA_SSIZE_T_DEFINED)
80/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
81# if ARCHIVE_VERSION_NUMBER < 4000000
82#define __LA_SSIZE_T la_ssize_t
83# endif
84#define __LA_SSIZE_T_DEFINED
85# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
86# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
87typedef ssize_t la_ssize_t;
88# elif defined(_WIN64)
89typedef __int64 la_ssize_t;
90# else
91typedef long la_ssize_t;
92# endif
93# else
94# include <unistd.h> /* ssize_t */
72e98eb4 95typedef ssize_t la_ssize_t;
1880dfc5 96# endif
eaae26f3
TK
97#endif
98
cd2bca68 99/* Large file support for Android */
100#ifdef __ANDROID__
101#include "android_lf.h"
102#endif
103
eaae26f3
TK
104/*
105 * On Windows, define LIBARCHIVE_STATIC if you're building or using a
106 * .lib. The default here assumes you're building a DLL. Only
107 * libarchive source should ever define __LIBARCHIVE_BUILD.
108 */
44f9eb57 109#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
eaae26f3
TK
110# ifdef __LIBARCHIVE_BUILD
111# ifdef __GNUC__
112# define __LA_DECL __attribute__((dllexport)) extern
113# else
114# define __LA_DECL __declspec(dllexport)
115# endif
116# else
117# ifdef __GNUC__
5a0de499 118# define __LA_DECL
eaae26f3
TK
119# else
120# define __LA_DECL __declspec(dllimport)
121# endif
122# endif
123#else
124/* Static libraries or non-Windows needs no special declaration. */
125# define __LA_DECL
126#endif
127
5fb156f9 128#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__)
ac8ba3fa
JS
129#define __LA_PRINTF(fmtarg, firstvararg) \
130 __attribute__((__format__ (__printf__, fmtarg, firstvararg)))
131#else
132#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */
133#endif
134
152e191c
MN
135#if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
136# define __LA_DEPRECATED __attribute__((deprecated))
137#else
138# define __LA_DEPRECATED
139#endif
140
eaae26f3
TK
141#ifdef __cplusplus
142extern "C" {
143#endif
144
145/*
146 * The version number is provided as both a macro and a function.
147 * The macro identifies the installed header; the function identifies
148 * the library version (which may not be the same if you're using a
149 * dynamically-linked version of the library). Of course, if the
150 * header and library are very different, you should expect some
151 * strangeness. Don't do that.
152 */
eaae26f3
TK
153__LA_DECL int archive_version_number(void);
154
155/*
156 * Textual name/version of the library, useful for version displays.
157 */
cce09646 158#define ARCHIVE_VERSION_ONLY_STRING "3.4.1"
9af76876 159#define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
eaae26f3
TK
160__LA_DECL const char * archive_version_string(void);
161
efa2eb44
RL
162/*
163 * Detailed textual name/version of the library and its dependencies.
9af76876
TK
164 * This has the form:
165 * "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..."
166 * the list of libraries described here will vary depending on how
167 * libarchive was compiled.
efa2eb44
RL
168 */
169__LA_DECL const char * archive_version_details(void);
170
3933e100
TK
171/*
172 * Returns NULL if libarchive was compiled without the associated library.
173 * Otherwise, returns the version number that libarchive was compiled
174 * against.
175 */
176__LA_DECL const char * archive_zlib_version(void);
177__LA_DECL const char * archive_liblzma_version(void);
178__LA_DECL const char * archive_bzlib_version(void);
179__LA_DECL const char * archive_liblz4_version(void);
d38f6664 180__LA_DECL const char * archive_libzstd_version(void);
3933e100 181
eaae26f3
TK
182/* Declare our basic types. */
183struct archive;
184struct archive_entry;
185
186/*
187 * Error codes: Use archive_errno() and archive_error_string()
188 * to retrieve details. Unless specified otherwise, all functions
189 * that return 'int' use these codes.
190 */
191#define ARCHIVE_EOF 1 /* Found end of archive. */
192#define ARCHIVE_OK 0 /* Operation was successful. */
193#define ARCHIVE_RETRY (-10) /* Retry might succeed. */
194#define ARCHIVE_WARN (-20) /* Partial success. */
195/* For example, if write_header "fails", then you can't push data. */
196#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */
197/* But if write_header is "fatal," then this archive is dead and useless. */
198#define ARCHIVE_FATAL (-30) /* No more operations are possible. */
199
200/*
201 * As far as possible, archive_errno returns standard platform errno codes.
202 * Of course, the details vary by platform, so the actual definitions
203 * here are stored in "archive_platform.h". The symbols are listed here
204 * for reference; as a rule, clients should not need to know the exact
205 * platform-dependent error code.
206 */
207/* Unrecognized or invalid file format. */
208/* #define ARCHIVE_ERRNO_FILE_FORMAT */
209/* Illegal usage of the library. */
210/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */
211/* Unknown or unclassified error. */
212/* #define ARCHIVE_ERRNO_MISC */
213
214/*
215 * Callbacks are invoked to automatically read/skip/write/open/close the
216 * archive. You can provide your own for complex tasks (like breaking
217 * archives across multiple tapes) or use standard ones built into the
218 * library.
219 */
220
221/* Returns pointer and size of next block of data from archive. */
72e98eb4 222typedef la_ssize_t archive_read_callback(struct archive *,
fc95189e
TK
223 void *_client_data, const void **_buffer);
224
41f86ae9
TK
225/* Skips at most request bytes from archive and returns the skipped amount.
226 * This may skip fewer bytes than requested; it may even skip zero bytes.
227 * If you do skip fewer bytes than requested, libarchive will invoke your
228 * read callback and discard data as necessary to make up the full skip.
229 */
72e98eb4
PD
230typedef la_int64_t archive_skip_callback(struct archive *,
231 void *_client_data, la_int64_t request);
fc95189e 232
41f86ae9
TK
233/* Seeks to specified location in the file and returns the position.
234 * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
235 * Return ARCHIVE_FATAL if the seek fails for any reason.
236 */
72e98eb4
PD
237typedef la_int64_t archive_seek_callback(struct archive *,
238 void *_client_data, la_int64_t offset, int whence);
41f86ae9 239
eaae26f3 240/* Returns size actually written, zero on EOF, -1 on error. */
72e98eb4 241typedef la_ssize_t archive_write_callback(struct archive *,
fc95189e
TK
242 void *_client_data,
243 const void *_buffer, size_t _length);
244
eaae26f3 245typedef int archive_open_callback(struct archive *, void *_client_data);
fc95189e 246
eaae26f3
TK
247typedef int archive_close_callback(struct archive *, void *_client_data);
248
7b543b13
AM
249/* Switches from one client data object to the next/prev client data object.
250 * This is useful for reading from different data blocks such as a set of files
251 * that make up one large file.
252 */
253typedef int archive_switch_callback(struct archive *, void *_client_data1,
254 void *_client_data2);
255
6c222e59
MN
256/*
257 * Returns a passphrase used for encryption or decryption, NULL on nothing
258 * to do and give it up.
259 */
260typedef const char *archive_passphrase_callback(struct archive *,
261 void *_client_data);
262
eaae26f3 263/*
911dc2bf 264 * Codes to identify various stream filters.
eaae26f3 265 */
911dc2bf
TK
266#define ARCHIVE_FILTER_NONE 0
267#define ARCHIVE_FILTER_GZIP 1
268#define ARCHIVE_FILTER_BZIP2 2
269#define ARCHIVE_FILTER_COMPRESS 3
270#define ARCHIVE_FILTER_PROGRAM 4
271#define ARCHIVE_FILTER_LZMA 5
272#define ARCHIVE_FILTER_XZ 6
273#define ARCHIVE_FILTER_UU 7
274#define ARCHIVE_FILTER_RPM 8
d8961d39 275#define ARCHIVE_FILTER_LZIP 9
1e5f600e 276#define ARCHIVE_FILTER_LRZIP 10
f51924bb 277#define ARCHIVE_FILTER_LZOP 11
630ead78 278#define ARCHIVE_FILTER_GRZIP 12
724f3f91 279#define ARCHIVE_FILTER_LZ4 13
04a90489 280#define ARCHIVE_FILTER_ZSTD 14
911dc2bf
TK
281
282#if ARCHIVE_VERSION_NUMBER < 4000000
283#define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE
284#define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP
285#define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2
286#define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS
287#define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM
288#define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA
289#define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ
290#define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU
291#define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM
d8961d39 292#define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP
1e5f600e 293#define ARCHIVE_COMPRESSION_LRZIP ARCHIVE_FILTER_LRZIP
911dc2bf 294#endif
eaae26f3
TK
295
296/*
297 * Codes returned by archive_format.
298 *
299 * Top 16 bits identifies the format family (e.g., "tar"); lower
300 * 16 bits indicate the variant. This is updated by read_next_header.
301 * Note that the lower 16 bits will often vary from entry to entry.
302 * In some cases, this variation occurs as libarchive learns more about
303 * the archive (for example, later entries might utilize extensions that
304 * weren't necessary earlier in the archive; in this case, libarchive
305 * will change the format code to indicate the extended format that
306 * was used). In other cases, it's because different tools have
307 * modified the archive and so different parts of the archive
a0b2ef61 308 * actually have slightly different formats. (Both tar and cpio store
eaae26f3
TK
309 * format codes in each entry, so it is quite possible for each
310 * entry to be in a different format.)
311 */
312#define ARCHIVE_FORMAT_BASE_MASK 0xff0000
313#define ARCHIVE_FORMAT_CPIO 0x10000
314#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1)
315#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2)
316#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3)
317#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4)
318#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5)
19cc1b68 319#define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6)
eaae26f3
TK
320#define ARCHIVE_FORMAT_SHAR 0x20000
321#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1)
322#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2)
323#define ARCHIVE_FORMAT_TAR 0x30000
324#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1)
325#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2)
326#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3)
327#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4)
328#define ARCHIVE_FORMAT_ISO9660 0x40000
329#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1)
330#define ARCHIVE_FORMAT_ZIP 0x50000
331#define ARCHIVE_FORMAT_EMPTY 0x60000
332#define ARCHIVE_FORMAT_AR 0x70000
333#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1)
334#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2)
335#define ARCHIVE_FORMAT_MTREE 0x80000
ccdb0318 336#define ARCHIVE_FORMAT_RAW 0x90000
d2c0930d 337#define ARCHIVE_FORMAT_XAR 0xA0000
344711d5 338#define ARCHIVE_FORMAT_LHA 0xB0000
12a3fef6 339#define ARCHIVE_FORMAT_CAB 0xC0000
099075c1 340#define ARCHIVE_FORMAT_RAR 0xD0000
e58ec445 341#define ARCHIVE_FORMAT_7ZIP 0xE0000
667961d7 342#define ARCHIVE_FORMAT_WARC 0xF0000
7b3068c4 343#define ARCHIVE_FORMAT_RAR_V5 0x100000
eaae26f3 344
f31a5a02
KK
345/*
346 * Codes returned by archive_read_format_capabilities().
347 *
348 * This list can be extended with values between 0 and 0xffff.
349 * The original purpose of this list was to let different archive
350 * format readers expose their general capabilities in terms of
351 * encryption.
352 */
353#define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */
354#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0) /* reader can detect encrypted data */
355#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1) /* reader can detect encryptable metadata (pathname, mtime, etc.) */
356
2de568ca
KK
357/*
358 * Codes returned by archive_read_has_encrypted_entries().
359 *
360 * In case the archive does not support encryption detection at all
361 * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader
362 * for some other reason (e.g. not enough bytes read) cannot say if
363 * there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW
364 * is returned.
365 */
366#define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2
367#define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1
368
eaae26f3
TK
369/*-
370 * Basic outline for reading an archive:
371 * 1) Ask archive_read_new for an archive reader object.
372 * 2) Update any global properties as appropriate.
373 * In particular, you'll certainly want to call appropriate
374 * archive_read_support_XXX functions.
375 * 3) Call archive_read_open_XXX to open the archive
376 * 4) Repeatedly call archive_read_next_header to get information about
377 * successive archive entries. Call archive_read_data to extract
378 * data for entries of interest.
ee1299ea 379 * 5) Call archive_read_free to end processing.
eaae26f3
TK
380 */
381__LA_DECL struct archive *archive_read_new(void);
382
383/*
384 * The archive_read_support_XXX calls enable auto-detect for this
385 * archive handle. They also link in the necessary support code.
386 * For example, if you don't want bzlib linked in, don't invoke
387 * support_compression_bzip2(). The "all" functions provide the
388 * obvious shorthand.
389 */
911dc2bf 390
a58aaa4f 391#if ARCHIVE_VERSION_NUMBER < 4000000
b34f2a09
MN
392__LA_DECL int archive_read_support_compression_all(struct archive *)
393 __LA_DEPRECATED;
394__LA_DECL int archive_read_support_compression_bzip2(struct archive *)
395 __LA_DEPRECATED;
396__LA_DECL int archive_read_support_compression_compress(struct archive *)
397 __LA_DEPRECATED;
398__LA_DECL int archive_read_support_compression_gzip(struct archive *)
399 __LA_DEPRECATED;
400__LA_DECL int archive_read_support_compression_lzip(struct archive *)
401 __LA_DEPRECATED;
402__LA_DECL int archive_read_support_compression_lzma(struct archive *)
403 __LA_DEPRECATED;
404__LA_DECL int archive_read_support_compression_none(struct archive *)
405 __LA_DEPRECATED;
911dc2bf 406__LA_DECL int archive_read_support_compression_program(struct archive *,
b34f2a09 407 const char *command) __LA_DEPRECATED;
911dc2bf
TK
408__LA_DECL int archive_read_support_compression_program_signature
409 (struct archive *, const char *,
b34f2a09 410 const void * /* match */, size_t) __LA_DEPRECATED;
71aa143d 411
b34f2a09
MN
412__LA_DECL int archive_read_support_compression_rpm(struct archive *)
413 __LA_DEPRECATED;
414__LA_DECL int archive_read_support_compression_uu(struct archive *)
415 __LA_DEPRECATED;
416__LA_DECL int archive_read_support_compression_xz(struct archive *)
417 __LA_DEPRECATED;
a58aaa4f
RN
418#endif
419
420__LA_DECL int archive_read_support_filter_all(struct archive *);
421__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
422__LA_DECL int archive_read_support_filter_compress(struct archive *);
423__LA_DECL int archive_read_support_filter_gzip(struct archive *);
630ead78 424__LA_DECL int archive_read_support_filter_grzip(struct archive *);
1e5f600e 425__LA_DECL int archive_read_support_filter_lrzip(struct archive *);
724f3f91 426__LA_DECL int archive_read_support_filter_lz4(struct archive *);
a58aaa4f
RN
427__LA_DECL int archive_read_support_filter_lzip(struct archive *);
428__LA_DECL int archive_read_support_filter_lzma(struct archive *);
f51924bb 429__LA_DECL int archive_read_support_filter_lzop(struct archive *);
a58aaa4f
RN
430__LA_DECL int archive_read_support_filter_none(struct archive *);
431__LA_DECL int archive_read_support_filter_program(struct archive *,
432 const char *command);
433__LA_DECL int archive_read_support_filter_program_signature
40722a25 434 (struct archive *, const char * /* cmd */,
a58aaa4f 435 const void * /* match */, size_t);
a58aaa4f
RN
436__LA_DECL int archive_read_support_filter_rpm(struct archive *);
437__LA_DECL int archive_read_support_filter_uu(struct archive *);
438__LA_DECL int archive_read_support_filter_xz(struct archive *);
cd63bdcd 439__LA_DECL int archive_read_support_filter_zstd(struct archive *);
eaae26f3 440
e58ec445 441__LA_DECL int archive_read_support_format_7zip(struct archive *);
911dc2bf
TK
442__LA_DECL int archive_read_support_format_all(struct archive *);
443__LA_DECL int archive_read_support_format_ar(struct archive *);
819e53c0 444__LA_DECL int archive_read_support_format_by_code(struct archive *, int);
12a3fef6 445__LA_DECL int archive_read_support_format_cab(struct archive *);
911dc2bf
TK
446__LA_DECL int archive_read_support_format_cpio(struct archive *);
447__LA_DECL int archive_read_support_format_empty(struct archive *);
448__LA_DECL int archive_read_support_format_gnutar(struct archive *);
449__LA_DECL int archive_read_support_format_iso9660(struct archive *);
344711d5 450__LA_DECL int archive_read_support_format_lha(struct archive *);
911dc2bf 451__LA_DECL int archive_read_support_format_mtree(struct archive *);
41f86ae9 452__LA_DECL int archive_read_support_format_rar(struct archive *);
087319f7 453__LA_DECL int archive_read_support_format_rar5(struct archive *);
911dc2bf
TK
454__LA_DECL int archive_read_support_format_raw(struct archive *);
455__LA_DECL int archive_read_support_format_tar(struct archive *);
96938015 456__LA_DECL int archive_read_support_format_warc(struct archive *);
911dc2bf 457__LA_DECL int archive_read_support_format_xar(struct archive *);
1579f4ba
TK
458/* archive_read_support_format_zip() enables both streamable and seekable
459 * zip readers. */
911dc2bf 460__LA_DECL int archive_read_support_format_zip(struct archive *);
1579f4ba
TK
461/* Reads Zip archives as stream from beginning to end. Doesn't
462 * correctly handle SFX ZIP files or ZIP archives that have been modified
463 * in-place. */
464__LA_DECL int archive_read_support_format_zip_streamable(struct archive *);
465/* Reads starting from central directory; requires seekable input. */
466__LA_DECL int archive_read_support_format_zip_seekable(struct archive *);
eaae26f3 467
82b5d8df
AM
468/* Functions to manually set the format and filters to be used. This is
469 * useful to bypass the bidding process when the format and filters to use
470 * is known in advance.
471 */
472__LA_DECL int archive_read_set_format(struct archive *, int);
473__LA_DECL int archive_read_append_filter(struct archive *, int);
474__LA_DECL int archive_read_append_filter_program(struct archive *,
475 const char *);
476__LA_DECL int archive_read_append_filter_program_signature
477 (struct archive *, const char *, const void * /* match */, size_t);
478
0dd337ef
TK
479/* Set various callbacks. */
480__LA_DECL int archive_read_set_open_callback(struct archive *,
481 archive_open_callback *);
482__LA_DECL int archive_read_set_read_callback(struct archive *,
483 archive_read_callback *);
41f86ae9
TK
484__LA_DECL int archive_read_set_seek_callback(struct archive *,
485 archive_seek_callback *);
0dd337ef
TK
486__LA_DECL int archive_read_set_skip_callback(struct archive *,
487 archive_skip_callback *);
488__LA_DECL int archive_read_set_close_callback(struct archive *,
489 archive_close_callback *);
7b543b13
AM
490/* Callback used to switch between one data object to the next */
491__LA_DECL int archive_read_set_switch_callback(struct archive *,
492 archive_switch_callback *);
493
494/* This sets the first data object. */
0dd337ef 495__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
7b543b13
AM
496/* This sets data object at specified index */
497__LA_DECL int archive_read_set_callback_data2(struct archive *, void *,
498 unsigned int);
499/* This adds a data object at the specified index. */
500__LA_DECL int archive_read_add_callback_data(struct archive *, void *,
501 unsigned int);
502/* This appends a data object to the end of list */
503__LA_DECL int archive_read_append_callback_data(struct archive *, void *);
504/* This prepends a data object to the beginning of list */
505__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *);
506
0dd337ef
TK
507/* Opening freezes the callbacks. */
508__LA_DECL int archive_read_open1(struct archive *);
509
510/* Convenience wrappers around the above. */
911dc2bf 511__LA_DECL int archive_read_open(struct archive *, void *_client_data,
eaae26f3
TK
512 archive_open_callback *, archive_read_callback *,
513 archive_close_callback *);
911dc2bf 514__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
eaae26f3
TK
515 archive_open_callback *, archive_read_callback *,
516 archive_skip_callback *, archive_close_callback *);
517
518/*
519 * A variety of shortcuts that invoke archive_read_open() with
520 * canned callbacks suitable for common situations. The ones that
521 * accept a block size handle tape blocking correctly.
522 */
523/* Use this if you know the filename. Note: NULL indicates stdin. */
911dc2bf 524__LA_DECL int archive_read_open_filename(struct archive *,
eaae26f3 525 const char *_filename, size_t _block_size);
7b543b13
AM
526/* Use this for reading multivolume files by filenames.
527 * NOTE: Must be NULL terminated. Sorting is NOT done. */
528__LA_DECL int archive_read_open_filenames(struct archive *,
529 const char **_filenames, size_t _block_size);
87cc7b92
MN
530__LA_DECL int archive_read_open_filename_w(struct archive *,
531 const wchar_t *_filename, size_t _block_size);
eaae26f3 532/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
911dc2bf 533__LA_DECL int archive_read_open_file(struct archive *,
152e191c 534 const char *_filename, size_t _block_size) __LA_DEPRECATED;
eaae26f3 535/* Read an archive that's stored in memory. */
911dc2bf 536__LA_DECL int archive_read_open_memory(struct archive *,
be4d4ddc 537 const void * buff, size_t size);
eaae26f3 538/* A more involved version that is only used for internal testing. */
be4d4ddc 539__LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff,
eaae26f3
TK
540 size_t size, size_t read_size);
541/* Read an archive that's already open, using the file descriptor. */
911dc2bf 542__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
eaae26f3
TK
543 size_t _block_size);
544/* Read an archive that's already open, using a FILE *. */
545/* Note: DO NOT use this with tape drives. */
911dc2bf 546__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
eaae26f3
TK
547
548/* Parses and returns next entry header. */
911dc2bf 549__LA_DECL int archive_read_next_header(struct archive *,
eaae26f3
TK
550 struct archive_entry **);
551
ff12dfa8 552/* Parses and returns next entry header using the archive_entry passed in */
911dc2bf 553__LA_DECL int archive_read_next_header2(struct archive *,
ff12dfa8
TK
554 struct archive_entry *);
555
eaae26f3
TK
556/*
557 * Retrieve the byte offset in UNCOMPRESSED data where last-read
558 * header started.
559 */
72e98eb4 560__LA_DECL la_int64_t archive_read_header_position(struct archive *);
eaae26f3 561
2de568ca
KK
562/*
563 * Returns 1 if the archive contains at least one encrypted entry.
564 * If the archive format not support encryption at all
565 * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned.
566 * If for any other reason (e.g. not enough data read so far)
567 * we cannot say whether there are encrypted entries, then
568 * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned.
569 * In general, this function will return values below zero when the
fa8dc4e9 570 * reader is uncertain or totally incapable of encryption support.
2de568ca
KK
571 * When this function returns 0 you can be sure that the reader
572 * supports encryption detection but no encrypted entries have
573 * been found yet.
574 *
575 * NOTE: If the metadata/header of an archive is also encrypted, you
576 * cannot rely on the number of encrypted entries. That is why this
577 * function does not return the number of encrypted entries but#
578 * just shows that there are some.
579 */
cd174091 580__LA_DECL int archive_read_has_encrypted_entries(struct archive *);
f31a5a02
KK
581
582/*
583 * Returns a bitmask of capabilities that are supported by the archive format reader.
584 * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned.
585 */
586__LA_DECL int archive_read_format_capabilities(struct archive *);
587
eaae26f3 588/* Read data from the body of an entry. Similar to read(2). */
72e98eb4 589__LA_DECL la_ssize_t archive_read_data(struct archive *,
fc95189e
TK
590 void *, size_t);
591
a5b03cc1 592/* Seek within the body of an entry. Similar to lseek(2). */
72e98eb4 593__LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int);
a5b03cc1 594
eaae26f3
TK
595/*
596 * A zero-copy version of archive_read_data that also exposes the file offset
597 * of each returned block. Note that the client has no way to specify
598 * the desired size of the block. The API does guarantee that offsets will
599 * be strictly increasing and that returned blocks will not overlap.
600 */
911dc2bf 601__LA_DECL int archive_read_data_block(struct archive *a,
72e98eb4 602 const void **buff, size_t *size, la_int64_t *offset);
eaae26f3
TK
603
604/*-
605 * Some convenience functions that are built on archive_read_data:
606 * 'skip': skips entire entry
607 * 'into_buffer': writes data into memory buffer that you provide
608 * 'into_fd': writes data to specified filedes
609 */
911dc2bf 610__LA_DECL int archive_read_data_skip(struct archive *);
911dc2bf 611__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
eaae26f3 612
6943997e
MN
613/*
614 * Set read options.
615 */
11e7a909
TK
616/* Apply option to the format only. */
617__LA_DECL int archive_read_set_format_option(struct archive *_a,
618 const char *m, const char *o,
619 const char *v);
620/* Apply option to the filter only. */
621__LA_DECL int archive_read_set_filter_option(struct archive *_a,
622 const char *m, const char *o,
623 const char *v);
624/* Apply option to both the format and the filter. */
625__LA_DECL int archive_read_set_option(struct archive *_a,
626 const char *m, const char *o,
627 const char *v);
6943997e 628/* Apply option string to both the format and the filter. */
911dc2bf 629__LA_DECL int archive_read_set_options(struct archive *_a,
11e7a909 630 const char *opts);
6943997e 631
6c222e59
MN
632/*
633 * Add a decryption passphrase.
634 */
635__LA_DECL int archive_read_add_passphrase(struct archive *, const char *);
636__LA_DECL int archive_read_set_passphrase_callback(struct archive *,
637 void *client_data, archive_passphrase_callback *);
638
639
eaae26f3
TK
640/*-
641 * Convenience function to recreate the current entry (whose header
642 * has just been read) on disk.
643 *
644 * This does quite a bit more than just copy data to disk. It also:
645 * - Creates intermediate directories as required.
646 * - Manages directory permissions: non-writable directories will
647 * be initially created with write permission enabled; when the
648 * archive is closed, dir permissions are edited to the values specified
649 * in the archive.
650 * - Checks hardlinks: hardlinks will not be extracted unless the
651 * linked-to file was also extracted within the same session. (TODO)
652 */
653
654/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
655
656/* Default: Do not try to set owner/group. */
657#define ARCHIVE_EXTRACT_OWNER (0x0001)
658/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
659#define ARCHIVE_EXTRACT_PERM (0x0002)
660/* Default: Do not restore mtime/atime. */
661#define ARCHIVE_EXTRACT_TIME (0x0004)
662/* Default: Replace existing files. */
663#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008)
664/* Default: Try create first, unlink only if create fails with EEXIST. */
665#define ARCHIVE_EXTRACT_UNLINK (0x0010)
666/* Default: Do not restore ACLs. */
667#define ARCHIVE_EXTRACT_ACL (0x0020)
668/* Default: Do not restore fflags. */
669#define ARCHIVE_EXTRACT_FFLAGS (0x0040)
670/* Default: Do not restore xattrs. */
671#define ARCHIVE_EXTRACT_XATTR (0x0080)
672/* Default: Do not try to guard against extracts redirected by symlinks. */
673/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
674#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100)
675/* Default: Do not reject entries with '..' as path elements. */
676#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200)
677/* Default: Create parent directories as needed. */
678#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400)
679/* Default: Overwrite files, even if one on disk is newer. */
680#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800)
681/* Detect blocks of 0 and write holes instead. */
682#define ARCHIVE_EXTRACT_SPARSE (0x1000)
b8ad1655
TK
683/* Default: Do not restore Mac extended metadata. */
684/* This has no effect except on Mac OS. */
685#define ARCHIVE_EXTRACT_MAC_METADATA (0x2000)
6238bed6 686/* Default: Use HFS+ compression if it was compressed. */
fb67a295 687/* This has no effect except on Mac OS v10.6 or later. */
6238bed6
MN
688#define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000)
689/* Default: Do not use HFS+ compression if it was not compressed. */
690/* This has no effect except on Mac OS v10.6 or later. */
691#define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000)
59357157
AG
692/* Default: Do not reject entries with absolute paths */
693#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
6a595ef6
BD
694/* Default: Do not clear no-change flags when unlinking object */
695#define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000)
eaae26f3 696
911dc2bf 697__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
eaae26f3 698 int flags);
911dc2bf 699__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
eaae26f3
TK
700 struct archive * /* dest */);
701__LA_DECL void archive_read_extract_set_progress_callback(struct archive *,
702 void (*_progress_func)(void *), void *_user_data);
703
704/* Record the dev/ino of a file that will not be written. This is
705 * generally set to the dev/ino of the archive being read. */
73f39d90 706__LA_DECL void archive_read_extract_set_skip_file(struct archive *,
72e98eb4 707 la_int64_t, la_int64_t);
eaae26f3
TK
708
709/* Close the file and release most resources. */
710__LA_DECL int archive_read_close(struct archive *);
711/* Release all resources and destroy the object. */
9890b31f
TK
712/* Note that archive_read_free will call archive_read_close for you. */
713__LA_DECL int archive_read_free(struct archive *);
714#if ARCHIVE_VERSION_NUMBER < 4000000
715/* Synonym for archive_read_free() for backwards compatibility. */
b34f2a09 716__LA_DECL int archive_read_finish(struct archive *) __LA_DEPRECATED;
9890b31f 717#endif
eaae26f3
TK
718
719/*-
720 * To create an archive:
a0b2ef61 721 * 1) Ask archive_write_new for an archive writer object.
eaae26f3
TK
722 * 2) Set any global properties. In particular, you should set
723 * the compression and format to use.
724 * 3) Call archive_write_open to open the file (most people
725 * will use archive_write_open_file or archive_write_open_fd,
726 * which provide convenient canned I/O callbacks for you).
727 * 4) For each entry:
728 * - construct an appropriate struct archive_entry structure
729 * - archive_write_header to write the header
730 * - archive_write_data to write the entry data
731 * 5) archive_write_close to close the output
9890b31f 732 * 6) archive_write_free to cleanup the writer and release resources
eaae26f3
TK
733 */
734__LA_DECL struct archive *archive_write_new(void);
911dc2bf 735__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
eaae26f3 736 int bytes_per_block);
911dc2bf 737__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
eaae26f3 738/* XXX This is badly misnamed; suggestions appreciated. XXX */
911dc2bf 739__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
eaae26f3 740 int bytes_in_last_block);
911dc2bf 741__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
eaae26f3
TK
742
743/* The dev/ino of a file that won't be archived. This is used
744 * to avoid recursively adding an archive to itself. */
73f39d90 745__LA_DECL int archive_write_set_skip_file(struct archive *,
72e98eb4 746 la_int64_t, la_int64_t);
911dc2bf
TK
747
748#if ARCHIVE_VERSION_NUMBER < 4000000
b34f2a09
MN
749__LA_DECL int archive_write_set_compression_bzip2(struct archive *)
750 __LA_DEPRECATED;
751__LA_DECL int archive_write_set_compression_compress(struct archive *)
752 __LA_DEPRECATED;
753__LA_DECL int archive_write_set_compression_gzip(struct archive *)
754 __LA_DEPRECATED;
755__LA_DECL int archive_write_set_compression_lzip(struct archive *)
756 __LA_DEPRECATED;
757__LA_DECL int archive_write_set_compression_lzma(struct archive *)
758 __LA_DEPRECATED;
759__LA_DECL int archive_write_set_compression_none(struct archive *)
760 __LA_DEPRECATED;
911dc2bf 761__LA_DECL int archive_write_set_compression_program(struct archive *,
b34f2a09
MN
762 const char *cmd) __LA_DEPRECATED;
763__LA_DECL int archive_write_set_compression_xz(struct archive *)
764 __LA_DEPRECATED;
911dc2bf
TK
765#endif
766
9ca74e37
OH
767/* A convenience function to set the filter based on the code. */
768__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
d06fc9e5
MN
769__LA_DECL int archive_write_add_filter_by_name(struct archive *,
770 const char *name);
ba3b5811 771__LA_DECL int archive_write_add_filter_b64encode(struct archive *);
911dc2bf
TK
772__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
773__LA_DECL int archive_write_add_filter_compress(struct archive *);
630ead78 774__LA_DECL int archive_write_add_filter_grzip(struct archive *);
911dc2bf 775__LA_DECL int archive_write_add_filter_gzip(struct archive *);
1e5f600e 776__LA_DECL int archive_write_add_filter_lrzip(struct archive *);
8c4be28f 777__LA_DECL int archive_write_add_filter_lz4(struct archive *);
4295807f 778__LA_DECL int archive_write_add_filter_lzip(struct archive *);
911dc2bf 779__LA_DECL int archive_write_add_filter_lzma(struct archive *);
f51924bb 780__LA_DECL int archive_write_add_filter_lzop(struct archive *);
911dc2bf
TK
781__LA_DECL int archive_write_add_filter_none(struct archive *);
782__LA_DECL int archive_write_add_filter_program(struct archive *,
eaae26f3 783 const char *cmd);
1cbc562a 784__LA_DECL int archive_write_add_filter_uuencode(struct archive *);
911dc2bf 785__LA_DECL int archive_write_add_filter_xz(struct archive *);
cd63bdcd 786__LA_DECL int archive_write_add_filter_zstd(struct archive *);
911dc2bf
TK
787
788
eaae26f3 789/* A convenience function to set the format based on the code or name. */
911dc2bf
TK
790__LA_DECL int archive_write_set_format(struct archive *, int format_code);
791__LA_DECL int archive_write_set_format_by_name(struct archive *,
eaae26f3
TK
792 const char *name);
793/* To minimize link pollution, use one or more of the following. */
3b413389 794__LA_DECL int archive_write_set_format_7zip(struct archive *);
911dc2bf
TK
795__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
796__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
797__LA_DECL int archive_write_set_format_cpio(struct archive *);
798__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
7862cf7a 799__LA_DECL int archive_write_set_format_gnutar(struct archive *);
9d72ea76 800__LA_DECL int archive_write_set_format_iso9660(struct archive *);
911dc2bf 801__LA_DECL int archive_write_set_format_mtree(struct archive *);
f83da353 802__LA_DECL int archive_write_set_format_mtree_classic(struct archive *);
eaae26f3 803/* TODO: int archive_write_set_format_old_tar(struct archive *); */
911dc2bf
TK
804__LA_DECL int archive_write_set_format_pax(struct archive *);
805__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
e5d1fbb2 806__LA_DECL int archive_write_set_format_raw(struct archive *);
911dc2bf
TK
807__LA_DECL int archive_write_set_format_shar(struct archive *);
808__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
809__LA_DECL int archive_write_set_format_ustar(struct archive *);
72350f67 810__LA_DECL int archive_write_set_format_v7tar(struct archive *);
667961d7 811__LA_DECL int archive_write_set_format_warc(struct archive *);
b7115a7d 812__LA_DECL int archive_write_set_format_xar(struct archive *);
911dc2bf 813__LA_DECL int archive_write_set_format_zip(struct archive *);
ae9a8882
KO
814__LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
815__LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
36a3cc51
MB
816__LA_DECL int archive_write_zip_set_compression_deflate(struct archive *);
817__LA_DECL int archive_write_zip_set_compression_store(struct archive *);
911dc2bf 818__LA_DECL int archive_write_open(struct archive *, void *,
eaae26f3
TK
819 archive_open_callback *, archive_write_callback *,
820 archive_close_callback *);
911dc2bf
TK
821__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
822__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
87cc7b92
MN
823__LA_DECL int archive_write_open_filename_w(struct archive *,
824 const wchar_t *_file);
eaae26f3 825/* A deprecated synonym for archive_write_open_filename() */
152e191c
MN
826__LA_DECL int archive_write_open_file(struct archive *, const char *_file)
827 __LA_DEPRECATED;
911dc2bf 828__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
eaae26f3
TK
829/* _buffSize is the size of the buffer, _used refers to a variable that
830 * will be updated after each write into the buffer. */
911dc2bf 831__LA_DECL int archive_write_open_memory(struct archive *,
eaae26f3
TK
832 void *_buffer, size_t _buffSize, size_t *_used);
833
834/*
835 * Note that the library will truncate writes beyond the size provided
836 * to archive_write_header or pad if the provided data is short.
837 */
911dc2bf 838__LA_DECL int archive_write_header(struct archive *,
eaae26f3 839 struct archive_entry *);
72e98eb4 840__LA_DECL la_ssize_t archive_write_data(struct archive *,
fc95189e 841 const void *, size_t);
fc95189e 842
a653ac94 843/* This interface is currently only available for archive_write_disk handles. */
72e98eb4
PD
844__LA_DECL la_ssize_t archive_write_data_block(struct archive *,
845 const void *, size_t, la_int64_t);
a653ac94 846
eaae26f3
TK
847__LA_DECL int archive_write_finish_entry(struct archive *);
848__LA_DECL int archive_write_close(struct archive *);
aceae782
TK
849/* Marks the archive as FATAL so that a subsequent free() operation
850 * won't try to close() cleanly. Provides a fast abort capability
851 * when the client discovers that things have gone wrong. */
852__LA_DECL int archive_write_fail(struct archive *);
9890b31f
TK
853/* This can fail if the archive wasn't already closed, in which case
854 * archive_write_free() will implicitly call archive_write_close(). */
855__LA_DECL int archive_write_free(struct archive *);
856#if ARCHIVE_VERSION_NUMBER < 4000000
857/* Synonym for archive_write_free() for backwards compatibility. */
b34f2a09 858__LA_DECL int archive_write_finish(struct archive *) __LA_DEPRECATED;
9890b31f 859#endif
eaae26f3 860
6943997e 861/*
11e7a909 862 * Set write options.
6943997e 863 */
11e7a909
TK
864/* Apply option to the format only. */
865__LA_DECL int archive_write_set_format_option(struct archive *_a,
866 const char *m, const char *o,
867 const char *v);
868/* Apply option to the filter only. */
869__LA_DECL int archive_write_set_filter_option(struct archive *_a,
870 const char *m, const char *o,
871 const char *v);
872/* Apply option to both the format and the filter. */
873__LA_DECL int archive_write_set_option(struct archive *_a,
874 const char *m, const char *o,
875 const char *v);
876/* Apply option string to both the format and the filter. */
877__LA_DECL int archive_write_set_options(struct archive *_a,
878 const char *opts);
6943997e 879
6c222e59
MN
880/*
881 * Set a encryption passphrase.
882 */
883__LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p);
96c38181
MN
884__LA_DECL int archive_write_set_passphrase_callback(struct archive *,
885 void *client_data, archive_passphrase_callback *);
6c222e59 886
eaae26f3 887/*-
2d892504
TK
888 * ARCHIVE_WRITE_DISK API
889 *
eaae26f3
TK
890 * To create objects on disk:
891 * 1) Ask archive_write_disk_new for a new archive_write_disk object.
2d892504
TK
892 * 2) Set any global properties. In particular, you probably
893 * want to set the options.
eaae26f3
TK
894 * 3) For each entry:
895 * - construct an appropriate struct archive_entry structure
896 * - archive_write_header to create the file/dir/etc on disk
897 * - archive_write_data to write the entry data
9890b31f 898 * 4) archive_write_free to cleanup the writer and release resources
eaae26f3
TK
899 *
900 * In particular, you can use this in conjunction with archive_read()
901 * to pull entries out of an archive and create them on disk.
902 */
903__LA_DECL struct archive *archive_write_disk_new(void);
904/* This file will not be overwritten. */
73f39d90 905__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
72e98eb4 906 la_int64_t, la_int64_t);
2d892504
TK
907/* Set flags to control how the next item gets created.
908 * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
eaae26f3
TK
909__LA_DECL int archive_write_disk_set_options(struct archive *,
910 int flags);
911/*
912 * The lookup functions are given uname/uid (or gname/gid) pairs and
913 * return a uid (gid) suitable for this system. These are used for
914 * restoring ownership and for setting ACLs. The default functions
915 * are naive, they just return the uid/gid. These are small, so reasonable
916 * for applications that don't need to preserve ownership; they
917 * are probably also appropriate for applications that are doing
918 * same-system backup and restore.
919 */
920/*
921 * The "standard" lookup functions use common system calls to lookup
922 * the uname/gname, falling back to the uid/gid if the names can't be
923 * found. They cache lookups and are reasonably fast, but can be very
924 * large, so they are not used unless you ask for them. In
925 * particular, these match the specifications of POSIX "pax" and old
926 * POSIX "tar".
927 */
928__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *);
929/*
930 * If neither the default (naive) nor the standard (big) functions suit
931 * your needs, you can write your own and register them. Be sure to
932 * include a cleanup function if you have allocated private data.
933 */
73f39d90
TK
934__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
935 void * /* private_data */,
72e98eb4 936 la_int64_t (*)(void *, const char *, la_int64_t),
73f39d90
TK
937 void (* /* cleanup */)(void *));
938__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
939 void * /* private_data */,
72e98eb4 940 la_int64_t (*)(void *, const char *, la_int64_t),
73f39d90 941 void (* /* cleanup */)(void *));
72e98eb4
PD
942__LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t);
943__LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t);
eaae26f3 944
aede8174
TK
945/*
946 * ARCHIVE_READ_DISK API
a8ac0b18
TK
947 *
948 * This is still evolving and somewhat experimental.
aede8174
TK
949 */
950__LA_DECL struct archive *archive_read_disk_new(void);
a8ac0b18
TK
951/* The names for symlink modes here correspond to an old BSD
952 * command-line argument convention: -L, -P, -H */
953/* Follow all symlinks. */
954__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
955/* Follow no symlinks. */
956__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
957/* Follow symlink initially, then not. */
958__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
959/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
960__LA_DECL int archive_read_disk_entry_from_file(struct archive *,
961 struct archive_entry *, int /* fd */, const struct stat *);
962/* Look up gname for gid or uname for uid. */
963/* Default implementations are very, very stupid. */
72e98eb4
PD
964__LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t);
965__LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t);
a8ac0b18
TK
966/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
967 * results for performance. */
968__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *);
969/* You can install your own lookups if you like. */
73f39d90
TK
970__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *,
971 void * /* private_data */,
72e98eb4 972 const char *(* /* lookup_fn */)(void *, la_int64_t),
73f39d90
TK
973 void (* /* cleanup_fn */)(void *));
974__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *,
975 void * /* private_data */,
72e98eb4 976 const char *(* /* lookup_fn */)(void *, la_int64_t),
73f39d90 977 void (* /* cleanup_fn */)(void *));
3311bb52
MN
978/* Start traversal. */
979__LA_DECL int archive_read_disk_open(struct archive *, const char *);
5773f6f3 980__LA_DECL int archive_read_disk_open_w(struct archive *, const wchar_t *);
3311bb52
MN
981/*
982 * Request that current entry be visited. If you invoke it on every
983 * directory, you'll get a physical traversal. This is ignored if the
984 * current entry isn't a directory or a link to a directory. So, if
985 * you invoke this on every returned path, you'll get a full logical
986 * traversal.
987 */
988__LA_DECL int archive_read_disk_descend(struct archive *);
4fd30257 989__LA_DECL int archive_read_disk_can_descend(struct archive *);
9690aef4 990__LA_DECL int archive_read_disk_current_filesystem(struct archive *);
e3d450a7
MN
991__LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *);
992__LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *);
fa8dc4e9 993/* Request that the access time of the entry visited by traversal be restored. */
b857ba4f 994__LA_DECL int archive_read_disk_set_atime_restored(struct archive *);
3df7554a
MN
995/*
996 * Set behavior. The "flags" argument selects optional behavior.
997 */
fa8dc4e9 998/* Request that the access time of the entry visited by traversal be restored.
3df7554a
MN
999 * This is the same as archive_read_disk_set_atime_restored. */
1000#define ARCHIVE_READDISK_RESTORE_ATIME (0x0001)
1001/* Default: Do not skip an entry which has nodump flags. */
1002#define ARCHIVE_READDISK_HONOR_NODUMP (0x0002)
1003/* Default: Skip a mac resource fork file whose prefix is "._" because of
1004 * using copyfile. */
1005#define ARCHIVE_READDISK_MAC_COPYFILE (0x0004)
2a86f9c4 1006/* Default: Traverse mount points. */
3df7554a 1007#define ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS (0x0008)
48b288a0
TK
1008/* Default: Xattrs are read from disk. */
1009#define ARCHIVE_READDISK_NO_XATTR (0x0010)
afbb01ac
MM
1010/* Default: ACLs are read from disk. */
1011#define ARCHIVE_READDISK_NO_ACL (0x0020)
098e477b
MM
1012/* Default: File flags are read from disk. */
1013#define ARCHIVE_READDISK_NO_FFLAGS (0x0040)
3df7554a
MN
1014
1015__LA_DECL int archive_read_disk_set_behavior(struct archive *,
1016 int flags);
1017
4fd30257 1018/*
b4d25a74 1019 * Set archive_match object that will be used in archive_read_disk to
4fd30257
MN
1020 * know whether an entry should be skipped. The callback function
1021 * _excluded_func will be invoked when an entry is skipped by the result
b4d25a74 1022 * of archive_match.
4fd30257
MN
1023 */
1024__LA_DECL int archive_read_disk_set_matching(struct archive *,
1025 struct archive *_matching, void (*_excluded_func)
1026 (struct archive *, void *, struct archive_entry *),
1027 void *_client_data);
fcc5dcbe
MN
1028__LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *,
1029 int (*_metadata_filter_func)(struct archive *, void *,
27b627f2
MN
1030 struct archive_entry *), void *_client_data);
1031
3ae99fbc
TK
1032/* Simplified cleanup interface;
1033 * This calls archive_read_free() or archive_write_free() as needed. */
1034__LA_DECL int archive_free(struct archive *);
1035
eaae26f3
TK
1036/*
1037 * Accessor functions to read/set various information in
1038 * the struct archive object:
1039 */
911dc2bf
TK
1040
1041/* Number of filters in the current filter pipeline. */
1042/* Filter #0 is the one closest to the format, -1 is a synonym for the
1043 * last filter, which is always the pseudo-filter that wraps the
1044 * client callbacks. */
1045__LA_DECL int archive_filter_count(struct archive *);
72e98eb4 1046__LA_DECL la_int64_t archive_filter_bytes(struct archive *, int);
911dc2bf
TK
1047__LA_DECL int archive_filter_code(struct archive *, int);
1048__LA_DECL const char * archive_filter_name(struct archive *, int);
1049
1050#if ARCHIVE_VERSION_NUMBER < 4000000
1051/* These don't properly handle multiple filters, so are deprecated and
1052 * will eventually be removed. */
1053/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
72e98eb4 1054__LA_DECL la_int64_t archive_position_compressed(struct archive *)
152e191c 1055 __LA_DEPRECATED;
911dc2bf 1056/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
72e98eb4 1057__LA_DECL la_int64_t archive_position_uncompressed(struct archive *)
152e191c 1058 __LA_DEPRECATED;
911dc2bf 1059/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
152e191c
MN
1060__LA_DECL const char *archive_compression_name(struct archive *)
1061 __LA_DEPRECATED;
911dc2bf 1062/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
152e191c
MN
1063__LA_DECL int archive_compression(struct archive *)
1064 __LA_DEPRECATED;
911dc2bf
TK
1065#endif
1066
eaae26f3
TK
1067__LA_DECL int archive_errno(struct archive *);
1068__LA_DECL const char *archive_error_string(struct archive *);
1069__LA_DECL const char *archive_format_name(struct archive *);
1070__LA_DECL int archive_format(struct archive *);
1071__LA_DECL void archive_clear_error(struct archive *);
1072__LA_DECL void archive_set_error(struct archive *, int _err,
ac8ba3fa 1073 const char *fmt, ...) __LA_PRINTF(3, 4);
eaae26f3
TK
1074__LA_DECL void archive_copy_error(struct archive *dest,
1075 struct archive *src);
ab649de7 1076__LA_DECL int archive_file_count(struct archive *);
eaae26f3 1077
3b14daeb 1078/*
b4d25a74 1079 * ARCHIVE_MATCH API
3b14daeb 1080 */
b4d25a74
MN
1081__LA_DECL struct archive *archive_match_new(void);
1082__LA_DECL int archive_match_free(struct archive *);
3b14daeb
MN
1083
1084/*
1085 * Test if archive_entry is excluded.
1086 * This is a convenience function. This is the same as calling all
b4d25a74
MN
1087 * archive_match_path_excluded, archive_match_time_excluded
1088 * and archive_match_owner_excluded.
3b14daeb 1089 */
b4d25a74 1090__LA_DECL int archive_match_excluded(struct archive *,
3b14daeb
MN
1091 struct archive_entry *);
1092
1093/*
56418500 1094 * Test if pathname is excluded. The conditions are set by following functions.
3b14daeb 1095 */
b4d25a74 1096__LA_DECL int archive_match_path_excluded(struct archive *,
3b14daeb 1097 struct archive_entry *);
7c5e94c9
PO
1098/* Control recursive inclusion of directory content when directory is included. Default on. */
1099__LA_DECL int archive_match_set_inclusion_recursion(struct archive *, int);
56418500 1100/* Add exclusion pathname pattern. */
b4d25a74
MN
1101__LA_DECL int archive_match_exclude_pattern(struct archive *, const char *);
1102__LA_DECL int archive_match_exclude_pattern_w(struct archive *,
3b14daeb 1103 const wchar_t *);
ae314ad8
MN
1104/* Add exclusion pathname pattern from file. */
1105__LA_DECL int archive_match_exclude_pattern_from_file(struct archive *,
1106 const char *, int _nullSeparator);
1107__LA_DECL int archive_match_exclude_pattern_from_file_w(struct archive *,
1108 const wchar_t *, int _nullSeparator);
56418500 1109/* Add inclusion pathname pattern. */
b4d25a74
MN
1110__LA_DECL int archive_match_include_pattern(struct archive *, const char *);
1111__LA_DECL int archive_match_include_pattern_w(struct archive *,
3b14daeb 1112 const wchar_t *);
ae314ad8
MN
1113/* Add inclusion pathname pattern from file. */
1114__LA_DECL int archive_match_include_pattern_from_file(struct archive *,
1115 const char *, int _nullSeparator);
1116__LA_DECL int archive_match_include_pattern_from_file_w(struct archive *,
1117 const wchar_t *, int _nullSeparator);
3b14daeb
MN
1118/*
1119 * How to get statistic information for inclusion patterns.
1120 */
1121/* Return the amount number of unmatched inclusion patterns. */
b4d25a74 1122__LA_DECL int archive_match_path_unmatched_inclusions(struct archive *);
3b14daeb
MN
1123/* Return the pattern of unmatched inclusion with ARCHIVE_OK.
1124 * Return ARCHIVE_EOF if there is no inclusion pattern. */
b4d25a74 1125__LA_DECL int archive_match_path_unmatched_inclusions_next(
3b14daeb 1126 struct archive *, const char **);
b4d25a74 1127__LA_DECL int archive_match_path_unmatched_inclusions_next_w(
3b14daeb
MN
1128 struct archive *, const wchar_t **);
1129
1130/*
1131 * Test if a file is excluded by its time stamp.
1132 * The conditions are set by following functions.
1133 */
b4d25a74 1134__LA_DECL int archive_match_time_excluded(struct archive *,
3b14daeb 1135 struct archive_entry *);
70779b91
MN
1136
1137/*
1138 * Flags to tell a matching type of time stamps. These are used for
fa8dc4e9 1139 * following functions.
70779b91
MN
1140 */
1141/* Time flag: mtime to be tested. */
b4d25a74 1142#define ARCHIVE_MATCH_MTIME (0x0100)
70779b91 1143/* Time flag: ctime to be tested. */
b4d25a74 1144#define ARCHIVE_MATCH_CTIME (0x0200)
70779b91 1145/* Comparison flag: Match the time if it is newer than. */
b4d25a74 1146#define ARCHIVE_MATCH_NEWER (0x0001)
70779b91 1147/* Comparison flag: Match the time if it is older than. */
b4d25a74 1148#define ARCHIVE_MATCH_OLDER (0x0002)
70779b91 1149/* Comparison flag: Match the time if it is equal to. */
b4d25a74 1150#define ARCHIVE_MATCH_EQUAL (0x0010)
70779b91 1151/* Set inclusion time. */
b4d25a74 1152__LA_DECL int archive_match_include_time(struct archive *, int _flag,
6aed59f1 1153 time_t _sec, long _nsec);
70779b91 1154/* Set inclusion time by a date string. */
b4d25a74 1155__LA_DECL int archive_match_include_date(struct archive *, int _flag,
6aed59f1 1156 const char *_datestr);
b4d25a74 1157__LA_DECL int archive_match_include_date_w(struct archive *, int _flag,
6aed59f1 1158 const wchar_t *_datestr);
fa8dc4e9 1159/* Set inclusion time by a particular file. */
b4d25a74 1160__LA_DECL int archive_match_include_file_time(struct archive *,
70779b91 1161 int _flag, const char *_pathname);
b4d25a74 1162__LA_DECL int archive_match_include_file_time_w(struct archive *,
70779b91
MN
1163 int _flag, const wchar_t *_pathname);
1164/* Add exclusion entry. */
b4d25a74 1165__LA_DECL int archive_match_exclude_entry(struct archive *,
70779b91 1166 int _flag, struct archive_entry *);
3b14daeb
MN
1167
1168/*
1169 * Test if a file is excluded by its uid ,gid, uname or gname.
1170 * The conditions are set by following functions.
1171 */
b4d25a74 1172__LA_DECL int archive_match_owner_excluded(struct archive *,
3b14daeb
MN
1173 struct archive_entry *);
1174/* Add inclusion uid, gid, uname and gname. */
72e98eb4
PD
1175__LA_DECL int archive_match_include_uid(struct archive *, la_int64_t);
1176__LA_DECL int archive_match_include_gid(struct archive *, la_int64_t);
b4d25a74
MN
1177__LA_DECL int archive_match_include_uname(struct archive *, const char *);
1178__LA_DECL int archive_match_include_uname_w(struct archive *,
3b14daeb 1179 const wchar_t *);
b4d25a74
MN
1180__LA_DECL int archive_match_include_gname(struct archive *, const char *);
1181__LA_DECL int archive_match_include_gname_w(struct archive *,
3b14daeb
MN
1182 const wchar_t *);
1183
258fd855
AM
1184/* Utility functions */
1185/* Convenience function to sort a NULL terminated list of strings */
1186__LA_DECL int archive_utility_string_sort(char **);
1187
eaae26f3
TK
1188#ifdef __cplusplus
1189}
1190#endif
1191
1ca7365e 1192/* These are meaningless outside of this header. */
eaae26f3
TK
1193#undef __LA_DECL
1194
1195#endif /* !ARCHIVE_H_INCLUDED */