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