archive.h revision 315432
1228753Smm/*-
2232153Smm * Copyright (c) 2003-2010 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm *
25228763Smm * $FreeBSD: stable/11/contrib/libarchive/libarchive/archive.h 315432 2017-03-16 23:07:35Z mm $
26228753Smm */
27228753Smm
28228753Smm#ifndef ARCHIVE_H_INCLUDED
29228753Smm#define	ARCHIVE_H_INCLUDED
30228753Smm
31299529Smm/*
32299529Smm * The version number is expressed as a single integer that makes it
33299529Smm * easy to compare versions at build time: for version a.b.c, the
34299529Smm * version number is printf("%d%03d%03d",a,b,c).  For example, if you
35299529Smm * know your application requires version 2.12.108 or later, you can
36299529Smm * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
37299529Smm */
38299529Smm/* Note: Compiler will complain if this does not match archive_entry.h! */
39315432Smm#define	ARCHIVE_VERSION_NUMBER 3003001
40299529Smm
41232153Smm#include <sys/stat.h>
42232153Smm#include <stddef.h>  /* for wchar_t */
43232153Smm#include <stdio.h> /* For FILE * */
44299529Smm#include <time.h> /* For time_t */
45232153Smm
46228753Smm/*
47228753Smm * Note: archive.h is for use outside of libarchive; the configuration
48228753Smm * headers (config.h, archive_platform.h, etc.) are purely internal.
49228753Smm * Do NOT use HAVE_XXX configuration macros to control the behavior of
50228753Smm * this header!  If you must conditionalize, use predefined compiler and/or
51228753Smm * platform macros.
52228753Smm */
53228753Smm#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
54232153Smm# include <stdint.h>
55299529Smm#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__)
56232153Smm# include <inttypes.h>
57228753Smm#endif
58228753Smm
59299529Smm/* Get appropriate definitions of 64-bit integer */
60299529Smm#if !defined(__LA_INT64_T_DEFINED)
61299529Smm/* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */
62299529Smm# if ARCHIVE_VERSION_NUMBER < 4000000
63299529Smm#define __LA_INT64_T la_int64_t
64299529Smm# endif
65299529Smm#define __LA_INT64_T_DEFINED
66299529Smm# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
67299529Smmtypedef __int64 la_int64_t;
68228753Smm# else
69299529Smm# include <unistd.h>  /* ssize_t */
70299529Smm#  if defined(_SCO_DS) || defined(__osf__)
71299529Smmtypedef long long la_int64_t;
72299529Smm#  else
73299529Smmtypedef int64_t la_int64_t;
74299529Smm#  endif
75228753Smm# endif
76299529Smm#endif
77299529Smm
78299529Smm/* The la_ssize_t should match the type used in 'struct stat' */
79299529Smm#if !defined(__LA_SSIZE_T_DEFINED)
80299529Smm/* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
81299529Smm# if ARCHIVE_VERSION_NUMBER < 4000000
82299529Smm#define __LA_SSIZE_T la_ssize_t
83299529Smm# endif
84299529Smm#define __LA_SSIZE_T_DEFINED
85299529Smm# if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
86299529Smm#  if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
87299529Smmtypedef ssize_t la_ssize_t;
88299529Smm#  elif defined(_WIN64)
89299529Smmtypedef __int64 la_ssize_t;
90299529Smm#  else
91299529Smmtypedef long la_ssize_t;
92299529Smm#  endif
93299529Smm# else
94238856Smm# include <unistd.h>  /* ssize_t */
95299529Smmtypedef ssize_t la_ssize_t;
96232153Smm# endif
97228753Smm#endif
98228753Smm
99299529Smm/* Large file support for Android */
100299529Smm#ifdef __ANDROID__
101299529Smm#include "android_lf.h"
102299529Smm#endif
103299529Smm
104228753Smm/*
105228753Smm * On Windows, define LIBARCHIVE_STATIC if you're building or using a
106228753Smm * .lib.  The default here assumes you're building a DLL.  Only
107228753Smm * libarchive source should ever define __LIBARCHIVE_BUILD.
108228753Smm */
109228753Smm#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
110228753Smm# ifdef __LIBARCHIVE_BUILD
111228753Smm#  ifdef __GNUC__
112228753Smm#   define __LA_DECL	__attribute__((dllexport)) extern
113228753Smm#  else
114228753Smm#   define __LA_DECL	__declspec(dllexport)
115228753Smm#  endif
116228753Smm# else
117228753Smm#  ifdef __GNUC__
118232153Smm#   define __LA_DECL
119228753Smm#  else
120228753Smm#   define __LA_DECL	__declspec(dllimport)
121228753Smm#  endif
122228753Smm# endif
123228753Smm#else
124228753Smm/* Static libraries or non-Windows needs no special declaration. */
125228753Smm# define __LA_DECL
126228753Smm#endif
127228753Smm
128232153Smm#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__)
129228753Smm#define	__LA_PRINTF(fmtarg, firstvararg) \
130228753Smm	__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
131228753Smm#else
132228753Smm#define	__LA_PRINTF(fmtarg, firstvararg)	/* nothing */
133228753Smm#endif
134228753Smm
135248616Smm#if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
136248616Smm# define __LA_DEPRECATED __attribute__((deprecated))
137248616Smm#else
138248616Smm# define __LA_DEPRECATED
139248616Smm#endif
140248616Smm
141228753Smm#ifdef __cplusplus
142228753Smmextern "C" {
143228753Smm#endif
144228753Smm
145228753Smm/*
146228753Smm * The version number is provided as both a macro and a function.
147228753Smm * The macro identifies the installed header; the function identifies
148228753Smm * the library version (which may not be the same if you're using a
149228753Smm * dynamically-linked version of the library).  Of course, if the
150228753Smm * header and library are very different, you should expect some
151228753Smm * strangeness.  Don't do that.
152228753Smm */
153228753Smm__LA_DECL int		archive_version_number(void);
154228753Smm
155228753Smm/*
156228753Smm * Textual name/version of the library, useful for version displays.
157228753Smm */
158315432Smm#define	ARCHIVE_VERSION_ONLY_STRING "3.3.1"
159299529Smm#define	ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING
160228753Smm__LA_DECL const char *	archive_version_string(void);
161228753Smm
162299529Smm/*
163299529Smm * Detailed textual name/version of the library and its dependencies.
164299529Smm * This has the form:
165299529Smm *    "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..."
166299529Smm * the list of libraries described here will vary depending on how
167299529Smm * libarchive was compiled.
168299529Smm */
169299529Smm__LA_DECL const char *	archive_version_details(void);
170299529Smm
171299529Smm/*
172299529Smm * Returns NULL if libarchive was compiled without the associated library.
173299529Smm * Otherwise, returns the version number that libarchive was compiled
174299529Smm * against.
175299529Smm */
176299529Smm__LA_DECL const char *  archive_zlib_version(void);
177299529Smm__LA_DECL const char *  archive_liblzma_version(void);
178299529Smm__LA_DECL const char *  archive_bzlib_version(void);
179299529Smm__LA_DECL const char *  archive_liblz4_version(void);
180299529Smm
181228753Smm/* Declare our basic types. */
182228753Smmstruct archive;
183228753Smmstruct archive_entry;
184228753Smm
185228753Smm/*
186228753Smm * Error codes: Use archive_errno() and archive_error_string()
187228753Smm * to retrieve details.  Unless specified otherwise, all functions
188228753Smm * that return 'int' use these codes.
189228753Smm */
190228753Smm#define	ARCHIVE_EOF	  1	/* Found end of archive. */
191228753Smm#define	ARCHIVE_OK	  0	/* Operation was successful. */
192228753Smm#define	ARCHIVE_RETRY	(-10)	/* Retry might succeed. */
193228753Smm#define	ARCHIVE_WARN	(-20)	/* Partial success. */
194228753Smm/* For example, if write_header "fails", then you can't push data. */
195228753Smm#define	ARCHIVE_FAILED	(-25)	/* Current operation cannot complete. */
196228753Smm/* But if write_header is "fatal," then this archive is dead and useless. */
197228753Smm#define	ARCHIVE_FATAL	(-30)	/* No more operations are possible. */
198228753Smm
199228753Smm/*
200228753Smm * As far as possible, archive_errno returns standard platform errno codes.
201228753Smm * Of course, the details vary by platform, so the actual definitions
202228753Smm * here are stored in "archive_platform.h".  The symbols are listed here
203228753Smm * for reference; as a rule, clients should not need to know the exact
204228753Smm * platform-dependent error code.
205228753Smm */
206228753Smm/* Unrecognized or invalid file format. */
207228753Smm/* #define	ARCHIVE_ERRNO_FILE_FORMAT */
208228753Smm/* Illegal usage of the library. */
209228753Smm/* #define	ARCHIVE_ERRNO_PROGRAMMER_ERROR */
210228753Smm/* Unknown or unclassified error. */
211228753Smm/* #define	ARCHIVE_ERRNO_MISC */
212228753Smm
213228753Smm/*
214228753Smm * Callbacks are invoked to automatically read/skip/write/open/close the
215228753Smm * archive. You can provide your own for complex tasks (like breaking
216228753Smm * archives across multiple tapes) or use standard ones built into the
217228753Smm * library.
218228753Smm */
219228753Smm
220228753Smm/* Returns pointer and size of next block of data from archive. */
221299529Smmtypedef la_ssize_t	archive_read_callback(struct archive *,
222228753Smm			    void *_client_data, const void **_buffer);
223228753Smm
224232153Smm/* Skips at most request bytes from archive and returns the skipped amount.
225232153Smm * This may skip fewer bytes than requested; it may even skip zero bytes.
226232153Smm * If you do skip fewer bytes than requested, libarchive will invoke your
227232153Smm * read callback and discard data as necessary to make up the full skip.
228232153Smm */
229299529Smmtypedef la_int64_t	archive_skip_callback(struct archive *,
230299529Smm			    void *_client_data, la_int64_t request);
231228753Smm
232232153Smm/* Seeks to specified location in the file and returns the position.
233232153Smm * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
234232153Smm * Return ARCHIVE_FATAL if the seek fails for any reason.
235232153Smm */
236299529Smmtypedef la_int64_t	archive_seek_callback(struct archive *,
237299529Smm    void *_client_data, la_int64_t offset, int whence);
238232153Smm
239228753Smm/* Returns size actually written, zero on EOF, -1 on error. */
240299529Smmtypedef la_ssize_t	archive_write_callback(struct archive *,
241228753Smm			    void *_client_data,
242228753Smm			    const void *_buffer, size_t _length);
243228753Smm
244228753Smmtypedef int	archive_open_callback(struct archive *, void *_client_data);
245228753Smm
246228753Smmtypedef int	archive_close_callback(struct archive *, void *_client_data);
247228753Smm
248248616Smm/* Switches from one client data object to the next/prev client data object.
249248616Smm * This is useful for reading from different data blocks such as a set of files
250248616Smm * that make up one large file.
251248616Smm */
252248616Smmtypedef int archive_switch_callback(struct archive *, void *_client_data1,
253248616Smm			    void *_client_data2);
254248616Smm
255228753Smm/*
256299529Smm * Returns a passphrase used for encryption or decryption, NULL on nothing
257299529Smm * to do and give it up.
258299529Smm */
259299529Smmtypedef const char *archive_passphrase_callback(struct archive *,
260299529Smm			    void *_client_data);
261299529Smm
262299529Smm/*
263232153Smm * Codes to identify various stream filters.
264228753Smm */
265232153Smm#define	ARCHIVE_FILTER_NONE	0
266232153Smm#define	ARCHIVE_FILTER_GZIP	1
267232153Smm#define	ARCHIVE_FILTER_BZIP2	2
268232153Smm#define	ARCHIVE_FILTER_COMPRESS	3
269232153Smm#define	ARCHIVE_FILTER_PROGRAM	4
270232153Smm#define	ARCHIVE_FILTER_LZMA	5
271232153Smm#define	ARCHIVE_FILTER_XZ	6
272232153Smm#define	ARCHIVE_FILTER_UU	7
273232153Smm#define	ARCHIVE_FILTER_RPM	8
274232153Smm#define	ARCHIVE_FILTER_LZIP	9
275248616Smm#define	ARCHIVE_FILTER_LRZIP	10
276248616Smm#define	ARCHIVE_FILTER_LZOP	11
277248616Smm#define	ARCHIVE_FILTER_GRZIP	12
278299529Smm#define	ARCHIVE_FILTER_LZ4	13
279228753Smm
280232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
281232153Smm#define	ARCHIVE_COMPRESSION_NONE	ARCHIVE_FILTER_NONE
282232153Smm#define	ARCHIVE_COMPRESSION_GZIP	ARCHIVE_FILTER_GZIP
283232153Smm#define	ARCHIVE_COMPRESSION_BZIP2	ARCHIVE_FILTER_BZIP2
284232153Smm#define	ARCHIVE_COMPRESSION_COMPRESS	ARCHIVE_FILTER_COMPRESS
285232153Smm#define	ARCHIVE_COMPRESSION_PROGRAM	ARCHIVE_FILTER_PROGRAM
286232153Smm#define	ARCHIVE_COMPRESSION_LZMA	ARCHIVE_FILTER_LZMA
287232153Smm#define	ARCHIVE_COMPRESSION_XZ		ARCHIVE_FILTER_XZ
288232153Smm#define	ARCHIVE_COMPRESSION_UU		ARCHIVE_FILTER_UU
289232153Smm#define	ARCHIVE_COMPRESSION_RPM		ARCHIVE_FILTER_RPM
290232153Smm#define	ARCHIVE_COMPRESSION_LZIP	ARCHIVE_FILTER_LZIP
291248616Smm#define	ARCHIVE_COMPRESSION_LRZIP	ARCHIVE_FILTER_LRZIP
292232153Smm#endif
293232153Smm
294228753Smm/*
295228753Smm * Codes returned by archive_format.
296228753Smm *
297228753Smm * Top 16 bits identifies the format family (e.g., "tar"); lower
298228753Smm * 16 bits indicate the variant.  This is updated by read_next_header.
299228753Smm * Note that the lower 16 bits will often vary from entry to entry.
300228753Smm * In some cases, this variation occurs as libarchive learns more about
301228753Smm * the archive (for example, later entries might utilize extensions that
302228753Smm * weren't necessary earlier in the archive; in this case, libarchive
303228753Smm * will change the format code to indicate the extended format that
304228753Smm * was used).  In other cases, it's because different tools have
305228753Smm * modified the archive and so different parts of the archive
306232153Smm * actually have slightly different formats.  (Both tar and cpio store
307228753Smm * format codes in each entry, so it is quite possible for each
308228753Smm * entry to be in a different format.)
309228753Smm */
310228753Smm#define	ARCHIVE_FORMAT_BASE_MASK		0xff0000
311228753Smm#define	ARCHIVE_FORMAT_CPIO			0x10000
312228753Smm#define	ARCHIVE_FORMAT_CPIO_POSIX		(ARCHIVE_FORMAT_CPIO | 1)
313228753Smm#define	ARCHIVE_FORMAT_CPIO_BIN_LE		(ARCHIVE_FORMAT_CPIO | 2)
314228753Smm#define	ARCHIVE_FORMAT_CPIO_BIN_BE		(ARCHIVE_FORMAT_CPIO | 3)
315228753Smm#define	ARCHIVE_FORMAT_CPIO_SVR4_NOCRC		(ARCHIVE_FORMAT_CPIO | 4)
316228753Smm#define	ARCHIVE_FORMAT_CPIO_SVR4_CRC		(ARCHIVE_FORMAT_CPIO | 5)
317232153Smm#define	ARCHIVE_FORMAT_CPIO_AFIO_LARGE		(ARCHIVE_FORMAT_CPIO | 6)
318228753Smm#define	ARCHIVE_FORMAT_SHAR			0x20000
319228753Smm#define	ARCHIVE_FORMAT_SHAR_BASE		(ARCHIVE_FORMAT_SHAR | 1)
320228753Smm#define	ARCHIVE_FORMAT_SHAR_DUMP		(ARCHIVE_FORMAT_SHAR | 2)
321228753Smm#define	ARCHIVE_FORMAT_TAR			0x30000
322228753Smm#define	ARCHIVE_FORMAT_TAR_USTAR		(ARCHIVE_FORMAT_TAR | 1)
323228753Smm#define	ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE	(ARCHIVE_FORMAT_TAR | 2)
324228753Smm#define	ARCHIVE_FORMAT_TAR_PAX_RESTRICTED	(ARCHIVE_FORMAT_TAR | 3)
325228753Smm#define	ARCHIVE_FORMAT_TAR_GNUTAR		(ARCHIVE_FORMAT_TAR | 4)
326228753Smm#define	ARCHIVE_FORMAT_ISO9660			0x40000
327228753Smm#define	ARCHIVE_FORMAT_ISO9660_ROCKRIDGE	(ARCHIVE_FORMAT_ISO9660 | 1)
328228753Smm#define	ARCHIVE_FORMAT_ZIP			0x50000
329228753Smm#define	ARCHIVE_FORMAT_EMPTY			0x60000
330228753Smm#define	ARCHIVE_FORMAT_AR			0x70000
331228753Smm#define	ARCHIVE_FORMAT_AR_GNU			(ARCHIVE_FORMAT_AR | 1)
332228753Smm#define	ARCHIVE_FORMAT_AR_BSD			(ARCHIVE_FORMAT_AR | 2)
333228753Smm#define	ARCHIVE_FORMAT_MTREE			0x80000
334228753Smm#define	ARCHIVE_FORMAT_RAW			0x90000
335228753Smm#define	ARCHIVE_FORMAT_XAR			0xA0000
336232153Smm#define	ARCHIVE_FORMAT_LHA			0xB0000
337232153Smm#define	ARCHIVE_FORMAT_CAB			0xC0000
338232153Smm#define	ARCHIVE_FORMAT_RAR			0xD0000
339232153Smm#define	ARCHIVE_FORMAT_7ZIP			0xE0000
340299529Smm#define	ARCHIVE_FORMAT_WARC			0xF0000
341228753Smm
342299529Smm/*
343299529Smm * Codes returned by archive_read_format_capabilities().
344299529Smm *
345299529Smm * This list can be extended with values between 0 and 0xffff.
346299529Smm * The original purpose of this list was to let different archive
347299529Smm * format readers expose their general capabilities in terms of
348299529Smm * encryption.
349299529Smm */
350299529Smm#define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */
351299529Smm#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0)  /* reader can detect encrypted data */
352299529Smm#define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1)  /* reader can detect encryptable metadata (pathname, mtime, etc.) */
353299529Smm
354299529Smm/*
355299529Smm * Codes returned by archive_read_has_encrypted_entries().
356299529Smm *
357299529Smm * In case the archive does not support encryption detection at all
358299529Smm * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader
359299529Smm * for some other reason (e.g. not enough bytes read) cannot say if
360299529Smm * there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW
361299529Smm * is returned.
362299529Smm */
363299529Smm#define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2
364299529Smm#define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1
365299529Smm
366228753Smm/*-
367228753Smm * Basic outline for reading an archive:
368228753Smm *   1) Ask archive_read_new for an archive reader object.
369228753Smm *   2) Update any global properties as appropriate.
370228753Smm *      In particular, you'll certainly want to call appropriate
371228753Smm *      archive_read_support_XXX functions.
372228753Smm *   3) Call archive_read_open_XXX to open the archive
373228753Smm *   4) Repeatedly call archive_read_next_header to get information about
374228753Smm *      successive archive entries.  Call archive_read_data to extract
375228753Smm *      data for entries of interest.
376311041Smm *   5) Call archive_read_free to end processing.
377228753Smm */
378228753Smm__LA_DECL struct archive	*archive_read_new(void);
379228753Smm
380228753Smm/*
381228753Smm * The archive_read_support_XXX calls enable auto-detect for this
382228753Smm * archive handle.  They also link in the necessary support code.
383228753Smm * For example, if you don't want bzlib linked in, don't invoke
384228753Smm * support_compression_bzip2().  The "all" functions provide the
385228753Smm * obvious shorthand.
386228753Smm */
387232153Smm
388232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
389248616Smm__LA_DECL int archive_read_support_compression_all(struct archive *)
390248616Smm		__LA_DEPRECATED;
391248616Smm__LA_DECL int archive_read_support_compression_bzip2(struct archive *)
392248616Smm		__LA_DEPRECATED;
393248616Smm__LA_DECL int archive_read_support_compression_compress(struct archive *)
394248616Smm		__LA_DEPRECATED;
395248616Smm__LA_DECL int archive_read_support_compression_gzip(struct archive *)
396248616Smm		__LA_DEPRECATED;
397248616Smm__LA_DECL int archive_read_support_compression_lzip(struct archive *)
398248616Smm		__LA_DEPRECATED;
399248616Smm__LA_DECL int archive_read_support_compression_lzma(struct archive *)
400248616Smm		__LA_DEPRECATED;
401248616Smm__LA_DECL int archive_read_support_compression_none(struct archive *)
402248616Smm		__LA_DEPRECATED;
403232153Smm__LA_DECL int archive_read_support_compression_program(struct archive *,
404248616Smm		     const char *command) __LA_DEPRECATED;
405232153Smm__LA_DECL int archive_read_support_compression_program_signature
406232153Smm		(struct archive *, const char *,
407248616Smm		 const void * /* match */, size_t) __LA_DEPRECATED;
408228753Smm
409248616Smm__LA_DECL int archive_read_support_compression_rpm(struct archive *)
410248616Smm		__LA_DEPRECATED;
411248616Smm__LA_DECL int archive_read_support_compression_uu(struct archive *)
412248616Smm		__LA_DEPRECATED;
413248616Smm__LA_DECL int archive_read_support_compression_xz(struct archive *)
414248616Smm		__LA_DEPRECATED;
415232153Smm#endif
416228753Smm
417232153Smm__LA_DECL int archive_read_support_filter_all(struct archive *);
418232153Smm__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
419232153Smm__LA_DECL int archive_read_support_filter_compress(struct archive *);
420232153Smm__LA_DECL int archive_read_support_filter_gzip(struct archive *);
421248616Smm__LA_DECL int archive_read_support_filter_grzip(struct archive *);
422248616Smm__LA_DECL int archive_read_support_filter_lrzip(struct archive *);
423299529Smm__LA_DECL int archive_read_support_filter_lz4(struct archive *);
424232153Smm__LA_DECL int archive_read_support_filter_lzip(struct archive *);
425232153Smm__LA_DECL int archive_read_support_filter_lzma(struct archive *);
426248616Smm__LA_DECL int archive_read_support_filter_lzop(struct archive *);
427232153Smm__LA_DECL int archive_read_support_filter_none(struct archive *);
428232153Smm__LA_DECL int archive_read_support_filter_program(struct archive *,
429232153Smm		     const char *command);
430232153Smm__LA_DECL int archive_read_support_filter_program_signature
431248616Smm		(struct archive *, const char * /* cmd */,
432232153Smm				    const void * /* match */, size_t);
433232153Smm__LA_DECL int archive_read_support_filter_rpm(struct archive *);
434232153Smm__LA_DECL int archive_read_support_filter_uu(struct archive *);
435232153Smm__LA_DECL int archive_read_support_filter_xz(struct archive *);
436228753Smm
437232153Smm__LA_DECL int archive_read_support_format_7zip(struct archive *);
438232153Smm__LA_DECL int archive_read_support_format_all(struct archive *);
439232153Smm__LA_DECL int archive_read_support_format_ar(struct archive *);
440232153Smm__LA_DECL int archive_read_support_format_by_code(struct archive *, int);
441232153Smm__LA_DECL int archive_read_support_format_cab(struct archive *);
442232153Smm__LA_DECL int archive_read_support_format_cpio(struct archive *);
443232153Smm__LA_DECL int archive_read_support_format_empty(struct archive *);
444232153Smm__LA_DECL int archive_read_support_format_gnutar(struct archive *);
445232153Smm__LA_DECL int archive_read_support_format_iso9660(struct archive *);
446232153Smm__LA_DECL int archive_read_support_format_lha(struct archive *);
447232153Smm__LA_DECL int archive_read_support_format_mtree(struct archive *);
448232153Smm__LA_DECL int archive_read_support_format_rar(struct archive *);
449232153Smm__LA_DECL int archive_read_support_format_raw(struct archive *);
450232153Smm__LA_DECL int archive_read_support_format_tar(struct archive *);
451299529Smm__LA_DECL int archive_read_support_format_warc(struct archive *);
452232153Smm__LA_DECL int archive_read_support_format_xar(struct archive *);
453299529Smm/* archive_read_support_format_zip() enables both streamable and seekable
454299529Smm * zip readers. */
455232153Smm__LA_DECL int archive_read_support_format_zip(struct archive *);
456299529Smm/* Reads Zip archives as stream from beginning to end.  Doesn't
457299529Smm * correctly handle SFX ZIP files or ZIP archives that have been modified
458299529Smm * in-place. */
459299529Smm__LA_DECL int archive_read_support_format_zip_streamable(struct archive *);
460299529Smm/* Reads starting from central directory; requires seekable input. */
461299529Smm__LA_DECL int archive_read_support_format_zip_seekable(struct archive *);
462232153Smm
463248616Smm/* Functions to manually set the format and filters to be used. This is
464248616Smm * useful to bypass the bidding process when the format and filters to use
465248616Smm * is known in advance.
466248616Smm */
467248616Smm__LA_DECL int archive_read_set_format(struct archive *, int);
468248616Smm__LA_DECL int archive_read_append_filter(struct archive *, int);
469248616Smm__LA_DECL int archive_read_append_filter_program(struct archive *,
470248616Smm    const char *);
471248616Smm__LA_DECL int archive_read_append_filter_program_signature
472248616Smm    (struct archive *, const char *, const void * /* match */, size_t);
473248616Smm
474232153Smm/* Set various callbacks. */
475232153Smm__LA_DECL int archive_read_set_open_callback(struct archive *,
476232153Smm    archive_open_callback *);
477232153Smm__LA_DECL int archive_read_set_read_callback(struct archive *,
478232153Smm    archive_read_callback *);
479232153Smm__LA_DECL int archive_read_set_seek_callback(struct archive *,
480232153Smm    archive_seek_callback *);
481232153Smm__LA_DECL int archive_read_set_skip_callback(struct archive *,
482232153Smm    archive_skip_callback *);
483232153Smm__LA_DECL int archive_read_set_close_callback(struct archive *,
484232153Smm    archive_close_callback *);
485248616Smm/* Callback used to switch between one data object to the next */
486248616Smm__LA_DECL int archive_read_set_switch_callback(struct archive *,
487248616Smm    archive_switch_callback *);
488248616Smm
489248616Smm/* This sets the first data object. */
490232153Smm__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
491248616Smm/* This sets data object at specified index */
492248616Smm__LA_DECL int archive_read_set_callback_data2(struct archive *, void *,
493248616Smm    unsigned int);
494248616Smm/* This adds a data object at the specified index. */
495248616Smm__LA_DECL int archive_read_add_callback_data(struct archive *, void *,
496248616Smm    unsigned int);
497248616Smm/* This appends a data object to the end of list */
498248616Smm__LA_DECL int archive_read_append_callback_data(struct archive *, void *);
499248616Smm/* This prepends a data object to the beginning of list */
500248616Smm__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *);
501248616Smm
502232153Smm/* Opening freezes the callbacks. */
503232153Smm__LA_DECL int archive_read_open1(struct archive *);
504232153Smm
505232153Smm/* Convenience wrappers around the above. */
506232153Smm__LA_DECL int archive_read_open(struct archive *, void *_client_data,
507228753Smm		     archive_open_callback *, archive_read_callback *,
508228753Smm		     archive_close_callback *);
509232153Smm__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
510228753Smm		     archive_open_callback *, archive_read_callback *,
511228753Smm		     archive_skip_callback *, archive_close_callback *);
512228753Smm
513228753Smm/*
514228753Smm * A variety of shortcuts that invoke archive_read_open() with
515228753Smm * canned callbacks suitable for common situations.  The ones that
516228753Smm * accept a block size handle tape blocking correctly.
517228753Smm */
518228753Smm/* Use this if you know the filename.  Note: NULL indicates stdin. */
519232153Smm__LA_DECL int archive_read_open_filename(struct archive *,
520228753Smm		     const char *_filename, size_t _block_size);
521248616Smm/* Use this for reading multivolume files by filenames.
522248616Smm * NOTE: Must be NULL terminated. Sorting is NOT done. */
523248616Smm__LA_DECL int archive_read_open_filenames(struct archive *,
524248616Smm		     const char **_filenames, size_t _block_size);
525232153Smm__LA_DECL int archive_read_open_filename_w(struct archive *,
526232153Smm		     const wchar_t *_filename, size_t _block_size);
527228753Smm/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
528232153Smm__LA_DECL int archive_read_open_file(struct archive *,
529248616Smm		     const char *_filename, size_t _block_size) __LA_DEPRECATED;
530228753Smm/* Read an archive that's stored in memory. */
531232153Smm__LA_DECL int archive_read_open_memory(struct archive *,
532299529Smm		     const void * buff, size_t size);
533228753Smm/* A more involved version that is only used for internal testing. */
534299529Smm__LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff,
535228753Smm		     size_t size, size_t read_size);
536228753Smm/* Read an archive that's already open, using the file descriptor. */
537232153Smm__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
538228753Smm		     size_t _block_size);
539228753Smm/* Read an archive that's already open, using a FILE *. */
540228753Smm/* Note: DO NOT use this with tape drives. */
541232153Smm__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
542228753Smm
543228753Smm/* Parses and returns next entry header. */
544232153Smm__LA_DECL int archive_read_next_header(struct archive *,
545228753Smm		     struct archive_entry **);
546228753Smm
547228753Smm/* Parses and returns next entry header using the archive_entry passed in */
548232153Smm__LA_DECL int archive_read_next_header2(struct archive *,
549228753Smm		     struct archive_entry *);
550228753Smm
551228753Smm/*
552228753Smm * Retrieve the byte offset in UNCOMPRESSED data where last-read
553228753Smm * header started.
554228753Smm */
555299529Smm__LA_DECL la_int64_t		 archive_read_header_position(struct archive *);
556228753Smm
557299529Smm/*
558299529Smm * Returns 1 if the archive contains at least one encrypted entry.
559299529Smm * If the archive format not support encryption at all
560299529Smm * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned.
561299529Smm * If for any other reason (e.g. not enough data read so far)
562299529Smm * we cannot say whether there are encrypted entries, then
563299529Smm * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned.
564299529Smm * In general, this function will return values below zero when the
565311041Smm * reader is uncertain or totally incapable of encryption support.
566299529Smm * When this function returns 0 you can be sure that the reader
567299529Smm * supports encryption detection but no encrypted entries have
568299529Smm * been found yet.
569299529Smm *
570299529Smm * NOTE: If the metadata/header of an archive is also encrypted, you
571299529Smm * cannot rely on the number of encrypted entries. That is why this
572299529Smm * function does not return the number of encrypted entries but#
573299529Smm * just shows that there are some.
574299529Smm */
575299529Smm__LA_DECL int	archive_read_has_encrypted_entries(struct archive *);
576299529Smm
577299529Smm/*
578299529Smm * Returns a bitmask of capabilities that are supported by the archive format reader.
579299529Smm * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned.
580299529Smm */
581299529Smm__LA_DECL int		 archive_read_format_capabilities(struct archive *);
582299529Smm
583228753Smm/* Read data from the body of an entry.  Similar to read(2). */
584299529Smm__LA_DECL la_ssize_t		 archive_read_data(struct archive *,
585228753Smm				    void *, size_t);
586228753Smm
587248616Smm/* Seek within the body of an entry.  Similar to lseek(2). */
588299529Smm__LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int);
589248616Smm
590228753Smm/*
591228753Smm * A zero-copy version of archive_read_data that also exposes the file offset
592228753Smm * of each returned block.  Note that the client has no way to specify
593228753Smm * the desired size of the block.  The API does guarantee that offsets will
594228753Smm * be strictly increasing and that returned blocks will not overlap.
595228753Smm */
596232153Smm__LA_DECL int archive_read_data_block(struct archive *a,
597299529Smm		    const void **buff, size_t *size, la_int64_t *offset);
598228753Smm
599228753Smm/*-
600228753Smm * Some convenience functions that are built on archive_read_data:
601228753Smm *  'skip': skips entire entry
602228753Smm *  'into_buffer': writes data into memory buffer that you provide
603228753Smm *  'into_fd': writes data to specified filedes
604228753Smm */
605232153Smm__LA_DECL int archive_read_data_skip(struct archive *);
606232153Smm__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
607228753Smm
608228753Smm/*
609228753Smm * Set read options.
610228753Smm */
611232153Smm/* Apply option to the format only. */
612232153Smm__LA_DECL int archive_read_set_format_option(struct archive *_a,
613232153Smm			    const char *m, const char *o,
614232153Smm			    const char *v);
615232153Smm/* Apply option to the filter only. */
616232153Smm__LA_DECL int archive_read_set_filter_option(struct archive *_a,
617232153Smm			    const char *m, const char *o,
618232153Smm			    const char *v);
619232153Smm/* Apply option to both the format and the filter. */
620232153Smm__LA_DECL int archive_read_set_option(struct archive *_a,
621232153Smm			    const char *m, const char *o,
622232153Smm			    const char *v);
623228753Smm/* Apply option string to both the format and the filter. */
624232153Smm__LA_DECL int archive_read_set_options(struct archive *_a,
625232153Smm			    const char *opts);
626228753Smm
627299529Smm/*
628299529Smm * Add a decryption passphrase.
629299529Smm */
630299529Smm__LA_DECL int archive_read_add_passphrase(struct archive *, const char *);
631299529Smm__LA_DECL int archive_read_set_passphrase_callback(struct archive *,
632299529Smm			    void *client_data, archive_passphrase_callback *);
633299529Smm
634299529Smm
635228753Smm/*-
636228753Smm * Convenience function to recreate the current entry (whose header
637228753Smm * has just been read) on disk.
638228753Smm *
639228753Smm * This does quite a bit more than just copy data to disk. It also:
640228753Smm *  - Creates intermediate directories as required.
641228753Smm *  - Manages directory permissions:  non-writable directories will
642228753Smm *    be initially created with write permission enabled; when the
643228753Smm *    archive is closed, dir permissions are edited to the values specified
644228753Smm *    in the archive.
645228753Smm *  - Checks hardlinks:  hardlinks will not be extracted unless the
646228753Smm *    linked-to file was also extracted within the same session. (TODO)
647228753Smm */
648228753Smm
649228753Smm/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
650228753Smm
651228753Smm/* Default: Do not try to set owner/group. */
652228753Smm#define	ARCHIVE_EXTRACT_OWNER			(0x0001)
653228753Smm/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
654228753Smm#define	ARCHIVE_EXTRACT_PERM			(0x0002)
655228753Smm/* Default: Do not restore mtime/atime. */
656228753Smm#define	ARCHIVE_EXTRACT_TIME			(0x0004)
657228753Smm/* Default: Replace existing files. */
658228753Smm#define	ARCHIVE_EXTRACT_NO_OVERWRITE 		(0x0008)
659228753Smm/* Default: Try create first, unlink only if create fails with EEXIST. */
660228753Smm#define	ARCHIVE_EXTRACT_UNLINK			(0x0010)
661228753Smm/* Default: Do not restore ACLs. */
662228753Smm#define	ARCHIVE_EXTRACT_ACL			(0x0020)
663228753Smm/* Default: Do not restore fflags. */
664228753Smm#define	ARCHIVE_EXTRACT_FFLAGS			(0x0040)
665228753Smm/* Default: Do not restore xattrs. */
666228753Smm#define	ARCHIVE_EXTRACT_XATTR 			(0x0080)
667228753Smm/* Default: Do not try to guard against extracts redirected by symlinks. */
668228753Smm/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
669228753Smm#define	ARCHIVE_EXTRACT_SECURE_SYMLINKS		(0x0100)
670228753Smm/* Default: Do not reject entries with '..' as path elements. */
671228753Smm#define	ARCHIVE_EXTRACT_SECURE_NODOTDOT		(0x0200)
672228753Smm/* Default: Create parent directories as needed. */
673228753Smm#define	ARCHIVE_EXTRACT_NO_AUTODIR		(0x0400)
674228753Smm/* Default: Overwrite files, even if one on disk is newer. */
675228753Smm#define	ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER	(0x0800)
676228753Smm/* Detect blocks of 0 and write holes instead. */
677228753Smm#define	ARCHIVE_EXTRACT_SPARSE			(0x1000)
678232153Smm/* Default: Do not restore Mac extended metadata. */
679232153Smm/* This has no effect except on Mac OS. */
680232153Smm#define	ARCHIVE_EXTRACT_MAC_METADATA		(0x2000)
681248616Smm/* Default: Use HFS+ compression if it was compressed. */
682248616Smm/* This has no effect except on Mac OS v10.6 or later. */
683248616Smm#define	ARCHIVE_EXTRACT_NO_HFS_COMPRESSION	(0x4000)
684248616Smm/* Default: Do not use HFS+ compression if it was not compressed. */
685248616Smm/* This has no effect except on Mac OS v10.6 or later. */
686248616Smm#define	ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED	(0x8000)
687299529Smm/* Default: Do not reject entries with absolute paths */
688299529Smm#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
689299529Smm/* Default: Do not clear no-change flags when unlinking object */
690299529Smm#define	ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS	(0x20000)
691228753Smm
692232153Smm__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
693228753Smm		     int flags);
694232153Smm__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
695228753Smm		     struct archive * /* dest */);
696228753Smm__LA_DECL void	 archive_read_extract_set_progress_callback(struct archive *,
697228753Smm		     void (*_progress_func)(void *), void *_user_data);
698228753Smm
699228753Smm/* Record the dev/ino of a file that will not be written.  This is
700228753Smm * generally set to the dev/ino of the archive being read. */
701228753Smm__LA_DECL void		archive_read_extract_set_skip_file(struct archive *,
702299529Smm		     la_int64_t, la_int64_t);
703228753Smm
704228753Smm/* Close the file and release most resources. */
705228753Smm__LA_DECL int		 archive_read_close(struct archive *);
706228753Smm/* Release all resources and destroy the object. */
707228773Smm/* Note that archive_read_free will call archive_read_close for you. */
708228773Smm__LA_DECL int		 archive_read_free(struct archive *);
709228773Smm#if ARCHIVE_VERSION_NUMBER < 4000000
710228773Smm/* Synonym for archive_read_free() for backwards compatibility. */
711248616Smm__LA_DECL int		 archive_read_finish(struct archive *) __LA_DEPRECATED;
712228753Smm#endif
713228753Smm
714228753Smm/*-
715228753Smm * To create an archive:
716232153Smm *   1) Ask archive_write_new for an archive writer object.
717228753Smm *   2) Set any global properties.  In particular, you should set
718228753Smm *      the compression and format to use.
719228753Smm *   3) Call archive_write_open to open the file (most people
720228753Smm *       will use archive_write_open_file or archive_write_open_fd,
721228753Smm *       which provide convenient canned I/O callbacks for you).
722228753Smm *   4) For each entry:
723228753Smm *      - construct an appropriate struct archive_entry structure
724228753Smm *      - archive_write_header to write the header
725228753Smm *      - archive_write_data to write the entry data
726228753Smm *   5) archive_write_close to close the output
727228773Smm *   6) archive_write_free to cleanup the writer and release resources
728228753Smm */
729228753Smm__LA_DECL struct archive	*archive_write_new(void);
730232153Smm__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
731228753Smm		     int bytes_per_block);
732232153Smm__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
733228753Smm/* XXX This is badly misnamed; suggestions appreciated. XXX */
734232153Smm__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
735228753Smm		     int bytes_in_last_block);
736232153Smm__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
737228753Smm
738228753Smm/* The dev/ino of a file that won't be archived.  This is used
739228753Smm * to avoid recursively adding an archive to itself. */
740232153Smm__LA_DECL int archive_write_set_skip_file(struct archive *,
741299529Smm    la_int64_t, la_int64_t);
742228753Smm
743232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
744248616Smm__LA_DECL int archive_write_set_compression_bzip2(struct archive *)
745248616Smm		__LA_DEPRECATED;
746248616Smm__LA_DECL int archive_write_set_compression_compress(struct archive *)
747248616Smm		__LA_DEPRECATED;
748248616Smm__LA_DECL int archive_write_set_compression_gzip(struct archive *)
749248616Smm		__LA_DEPRECATED;
750248616Smm__LA_DECL int archive_write_set_compression_lzip(struct archive *)
751248616Smm		__LA_DEPRECATED;
752248616Smm__LA_DECL int archive_write_set_compression_lzma(struct archive *)
753248616Smm		__LA_DEPRECATED;
754248616Smm__LA_DECL int archive_write_set_compression_none(struct archive *)
755248616Smm		__LA_DEPRECATED;
756232153Smm__LA_DECL int archive_write_set_compression_program(struct archive *,
757248616Smm		     const char *cmd) __LA_DEPRECATED;
758248616Smm__LA_DECL int archive_write_set_compression_xz(struct archive *)
759248616Smm		__LA_DEPRECATED;
760232153Smm#endif
761232153Smm
762238856Smm/* A convenience function to set the filter based on the code. */
763238856Smm__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
764248616Smm__LA_DECL int archive_write_add_filter_by_name(struct archive *,
765248616Smm		     const char *name);
766248616Smm__LA_DECL int archive_write_add_filter_b64encode(struct archive *);
767232153Smm__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
768232153Smm__LA_DECL int archive_write_add_filter_compress(struct archive *);
769248616Smm__LA_DECL int archive_write_add_filter_grzip(struct archive *);
770232153Smm__LA_DECL int archive_write_add_filter_gzip(struct archive *);
771248616Smm__LA_DECL int archive_write_add_filter_lrzip(struct archive *);
772299529Smm__LA_DECL int archive_write_add_filter_lz4(struct archive *);
773232153Smm__LA_DECL int archive_write_add_filter_lzip(struct archive *);
774232153Smm__LA_DECL int archive_write_add_filter_lzma(struct archive *);
775248616Smm__LA_DECL int archive_write_add_filter_lzop(struct archive *);
776232153Smm__LA_DECL int archive_write_add_filter_none(struct archive *);
777232153Smm__LA_DECL int archive_write_add_filter_program(struct archive *,
778232153Smm		     const char *cmd);
779248616Smm__LA_DECL int archive_write_add_filter_uuencode(struct archive *);
780232153Smm__LA_DECL int archive_write_add_filter_xz(struct archive *);
781232153Smm
782232153Smm
783228753Smm/* A convenience function to set the format based on the code or name. */
784232153Smm__LA_DECL int archive_write_set_format(struct archive *, int format_code);
785232153Smm__LA_DECL int archive_write_set_format_by_name(struct archive *,
786228753Smm		     const char *name);
787228753Smm/* To minimize link pollution, use one or more of the following. */
788232153Smm__LA_DECL int archive_write_set_format_7zip(struct archive *);
789232153Smm__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
790232153Smm__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
791232153Smm__LA_DECL int archive_write_set_format_cpio(struct archive *);
792232153Smm__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
793232153Smm__LA_DECL int archive_write_set_format_gnutar(struct archive *);
794232153Smm__LA_DECL int archive_write_set_format_iso9660(struct archive *);
795232153Smm__LA_DECL int archive_write_set_format_mtree(struct archive *);
796248616Smm__LA_DECL int archive_write_set_format_mtree_classic(struct archive *);
797228753Smm/* TODO: int archive_write_set_format_old_tar(struct archive *); */
798232153Smm__LA_DECL int archive_write_set_format_pax(struct archive *);
799232153Smm__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
800299529Smm__LA_DECL int archive_write_set_format_raw(struct archive *);
801232153Smm__LA_DECL int archive_write_set_format_shar(struct archive *);
802232153Smm__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
803232153Smm__LA_DECL int archive_write_set_format_ustar(struct archive *);
804248616Smm__LA_DECL int archive_write_set_format_v7tar(struct archive *);
805299529Smm__LA_DECL int archive_write_set_format_warc(struct archive *);
806232153Smm__LA_DECL int archive_write_set_format_xar(struct archive *);
807232153Smm__LA_DECL int archive_write_set_format_zip(struct archive *);
808299529Smm__LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename);
809299529Smm__LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext);
810248616Smm__LA_DECL int archive_write_zip_set_compression_deflate(struct archive *);
811248616Smm__LA_DECL int archive_write_zip_set_compression_store(struct archive *);
812232153Smm__LA_DECL int archive_write_open(struct archive *, void *,
813228753Smm		     archive_open_callback *, archive_write_callback *,
814228753Smm		     archive_close_callback *);
815232153Smm__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
816232153Smm__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
817232153Smm__LA_DECL int archive_write_open_filename_w(struct archive *,
818232153Smm		     const wchar_t *_file);
819228753Smm/* A deprecated synonym for archive_write_open_filename() */
820248616Smm__LA_DECL int archive_write_open_file(struct archive *, const char *_file)
821248616Smm		__LA_DEPRECATED;
822232153Smm__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
823228753Smm/* _buffSize is the size of the buffer, _used refers to a variable that
824228753Smm * will be updated after each write into the buffer. */
825232153Smm__LA_DECL int archive_write_open_memory(struct archive *,
826228753Smm			void *_buffer, size_t _buffSize, size_t *_used);
827228753Smm
828228753Smm/*
829228753Smm * Note that the library will truncate writes beyond the size provided
830228753Smm * to archive_write_header or pad if the provided data is short.
831228753Smm */
832232153Smm__LA_DECL int archive_write_header(struct archive *,
833228753Smm		     struct archive_entry *);
834299529Smm__LA_DECL la_ssize_t	archive_write_data(struct archive *,
835228753Smm			    const void *, size_t);
836228753Smm
837232153Smm/* This interface is currently only available for archive_write_disk handles.  */
838299529Smm__LA_DECL la_ssize_t	 archive_write_data_block(struct archive *,
839299529Smm				    const void *, size_t, la_int64_t);
840232153Smm
841228753Smm__LA_DECL int		 archive_write_finish_entry(struct archive *);
842228753Smm__LA_DECL int		 archive_write_close(struct archive *);
843248616Smm/* Marks the archive as FATAL so that a subsequent free() operation
844248616Smm * won't try to close() cleanly.  Provides a fast abort capability
845248616Smm * when the client discovers that things have gone wrong. */
846248616Smm__LA_DECL int            archive_write_fail(struct archive *);
847228773Smm/* This can fail if the archive wasn't already closed, in which case
848228773Smm * archive_write_free() will implicitly call archive_write_close(). */
849228773Smm__LA_DECL int		 archive_write_free(struct archive *);
850228773Smm#if ARCHIVE_VERSION_NUMBER < 4000000
851228773Smm/* Synonym for archive_write_free() for backwards compatibility. */
852248616Smm__LA_DECL int		 archive_write_finish(struct archive *) __LA_DEPRECATED;
853228753Smm#endif
854228753Smm
855228753Smm/*
856228753Smm * Set write options.
857228753Smm */
858232153Smm/* Apply option to the format only. */
859232153Smm__LA_DECL int archive_write_set_format_option(struct archive *_a,
860232153Smm			    const char *m, const char *o,
861232153Smm			    const char *v);
862232153Smm/* Apply option to the filter only. */
863232153Smm__LA_DECL int archive_write_set_filter_option(struct archive *_a,
864232153Smm			    const char *m, const char *o,
865232153Smm			    const char *v);
866232153Smm/* Apply option to both the format and the filter. */
867232153Smm__LA_DECL int archive_write_set_option(struct archive *_a,
868232153Smm			    const char *m, const char *o,
869232153Smm			    const char *v);
870232153Smm/* Apply option string to both the format and the filter. */
871232153Smm__LA_DECL int archive_write_set_options(struct archive *_a,
872232153Smm			    const char *opts);
873228753Smm
874299529Smm/*
875299529Smm * Set a encryption passphrase.
876299529Smm */
877299529Smm__LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p);
878299529Smm__LA_DECL int archive_write_set_passphrase_callback(struct archive *,
879299529Smm			    void *client_data, archive_passphrase_callback *);
880299529Smm
881228753Smm/*-
882228753Smm * ARCHIVE_WRITE_DISK API
883228753Smm *
884228753Smm * To create objects on disk:
885228753Smm *   1) Ask archive_write_disk_new for a new archive_write_disk object.
886228753Smm *   2) Set any global properties.  In particular, you probably
887228753Smm *      want to set the options.
888228753Smm *   3) For each entry:
889228753Smm *      - construct an appropriate struct archive_entry structure
890228753Smm *      - archive_write_header to create the file/dir/etc on disk
891228753Smm *      - archive_write_data to write the entry data
892228773Smm *   4) archive_write_free to cleanup the writer and release resources
893228753Smm *
894228753Smm * In particular, you can use this in conjunction with archive_read()
895228753Smm * to pull entries out of an archive and create them on disk.
896228753Smm */
897228753Smm__LA_DECL struct archive	*archive_write_disk_new(void);
898228753Smm/* This file will not be overwritten. */
899232153Smm__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
900299529Smm    la_int64_t, la_int64_t);
901228753Smm/* Set flags to control how the next item gets created.
902228753Smm * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
903228753Smm__LA_DECL int		 archive_write_disk_set_options(struct archive *,
904228753Smm		     int flags);
905228753Smm/*
906228753Smm * The lookup functions are given uname/uid (or gname/gid) pairs and
907228753Smm * return a uid (gid) suitable for this system.  These are used for
908228753Smm * restoring ownership and for setting ACLs.  The default functions
909228753Smm * are naive, they just return the uid/gid.  These are small, so reasonable
910228753Smm * for applications that don't need to preserve ownership; they
911228753Smm * are probably also appropriate for applications that are doing
912228753Smm * same-system backup and restore.
913228753Smm */
914228753Smm/*
915228753Smm * The "standard" lookup functions use common system calls to lookup
916228753Smm * the uname/gname, falling back to the uid/gid if the names can't be
917228753Smm * found.  They cache lookups and are reasonably fast, but can be very
918228753Smm * large, so they are not used unless you ask for them.  In
919228753Smm * particular, these match the specifications of POSIX "pax" and old
920228753Smm * POSIX "tar".
921228753Smm */
922228753Smm__LA_DECL int	 archive_write_disk_set_standard_lookup(struct archive *);
923228753Smm/*
924228753Smm * If neither the default (naive) nor the standard (big) functions suit
925228753Smm * your needs, you can write your own and register them.  Be sure to
926228753Smm * include a cleanup function if you have allocated private data.
927228753Smm */
928232153Smm__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
929232153Smm    void * /* private_data */,
930299529Smm    la_int64_t (*)(void *, const char *, la_int64_t),
931232153Smm    void (* /* cleanup */)(void *));
932232153Smm__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
933232153Smm    void * /* private_data */,
934299529Smm    la_int64_t (*)(void *, const char *, la_int64_t),
935232153Smm    void (* /* cleanup */)(void *));
936299529Smm__LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t);
937299529Smm__LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t);
938228753Smm
939228753Smm/*
940228753Smm * ARCHIVE_READ_DISK API
941228753Smm *
942228753Smm * This is still evolving and somewhat experimental.
943228753Smm */
944228753Smm__LA_DECL struct archive *archive_read_disk_new(void);
945228753Smm/* The names for symlink modes here correspond to an old BSD
946228753Smm * command-line argument convention: -L, -P, -H */
947228753Smm/* Follow all symlinks. */
948228753Smm__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
949228753Smm/* Follow no symlinks. */
950228753Smm__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
951228753Smm/* Follow symlink initially, then not. */
952228753Smm__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
953228753Smm/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
954228753Smm__LA_DECL int archive_read_disk_entry_from_file(struct archive *,
955228753Smm    struct archive_entry *, int /* fd */, const struct stat *);
956228753Smm/* Look up gname for gid or uname for uid. */
957228753Smm/* Default implementations are very, very stupid. */
958299529Smm__LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t);
959299529Smm__LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t);
960228753Smm/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
961228753Smm * results for performance. */
962228753Smm__LA_DECL int	archive_read_disk_set_standard_lookup(struct archive *);
963228753Smm/* You can install your own lookups if you like. */
964228753Smm__LA_DECL int	archive_read_disk_set_gname_lookup(struct archive *,
965228753Smm    void * /* private_data */,
966299529Smm    const char *(* /* lookup_fn */)(void *, la_int64_t),
967228753Smm    void (* /* cleanup_fn */)(void *));
968228753Smm__LA_DECL int	archive_read_disk_set_uname_lookup(struct archive *,
969228753Smm    void * /* private_data */,
970299529Smm    const char *(* /* lookup_fn */)(void *, la_int64_t),
971228753Smm    void (* /* cleanup_fn */)(void *));
972232153Smm/* Start traversal. */
973232153Smm__LA_DECL int	archive_read_disk_open(struct archive *, const char *);
974232153Smm__LA_DECL int	archive_read_disk_open_w(struct archive *, const wchar_t *);
975232153Smm/*
976232153Smm * Request that current entry be visited.  If you invoke it on every
977232153Smm * directory, you'll get a physical traversal.  This is ignored if the
978232153Smm * current entry isn't a directory or a link to a directory.  So, if
979232153Smm * you invoke this on every returned path, you'll get a full logical
980232153Smm * traversal.
981232153Smm */
982232153Smm__LA_DECL int	archive_read_disk_descend(struct archive *);
983238856Smm__LA_DECL int	archive_read_disk_can_descend(struct archive *);
984232153Smm__LA_DECL int	archive_read_disk_current_filesystem(struct archive *);
985232153Smm__LA_DECL int	archive_read_disk_current_filesystem_is_synthetic(struct archive *);
986232153Smm__LA_DECL int	archive_read_disk_current_filesystem_is_remote(struct archive *);
987311041Smm/* Request that the access time of the entry visited by traversal be restored. */
988232153Smm__LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
989238856Smm/*
990238856Smm * Set behavior. The "flags" argument selects optional behavior.
991238856Smm */
992311041Smm/* Request that the access time of the entry visited by traversal be restored.
993238856Smm * This is the same as archive_read_disk_set_atime_restored. */
994238856Smm#define	ARCHIVE_READDISK_RESTORE_ATIME		(0x0001)
995238856Smm/* Default: Do not skip an entry which has nodump flags. */
996238856Smm#define	ARCHIVE_READDISK_HONOR_NODUMP		(0x0002)
997238856Smm/* Default: Skip a mac resource fork file whose prefix is "._" because of
998238856Smm * using copyfile. */
999238856Smm#define	ARCHIVE_READDISK_MAC_COPYFILE		(0x0004)
1000299529Smm/* Default: Traverse mount points. */
1001238856Smm#define	ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS	(0x0008)
1002299529Smm/* Default: Xattrs are read from disk. */
1003299529Smm#define	ARCHIVE_READDISK_NO_XATTR		(0x0010)
1004315432Smm/* Default: ACLs are read from disk. */
1005315432Smm#define	ARCHIVE_READDISK_NO_ACL			(0x0020)
1006315432Smm/* Default: File flags are read from disk. */
1007315432Smm#define	ARCHIVE_READDISK_NO_FFLAGS		(0x0040)
1008228753Smm
1009238856Smm__LA_DECL int  archive_read_disk_set_behavior(struct archive *,
1010238856Smm		    int flags);
1011238856Smm
1012228753Smm/*
1013238856Smm * Set archive_match object that will be used in archive_read_disk to
1014238856Smm * know whether an entry should be skipped. The callback function
1015238856Smm * _excluded_func will be invoked when an entry is skipped by the result
1016238856Smm * of archive_match.
1017238856Smm */
1018238856Smm__LA_DECL int	archive_read_disk_set_matching(struct archive *,
1019238856Smm		    struct archive *_matching, void (*_excluded_func)
1020238856Smm		    (struct archive *, void *, struct archive_entry *),
1021238856Smm		    void *_client_data);
1022238856Smm__LA_DECL int	archive_read_disk_set_metadata_filter_callback(struct archive *,
1023238856Smm		    int (*_metadata_filter_func)(struct archive *, void *,
1024238856Smm		    	struct archive_entry *), void *_client_data);
1025238856Smm
1026299529Smm/* Simplified cleanup interface;
1027299529Smm * This calls archive_read_free() or archive_write_free() as needed. */
1028299529Smm__LA_DECL int	archive_free(struct archive *);
1029299529Smm
1030238856Smm/*
1031228753Smm * Accessor functions to read/set various information in
1032228753Smm * the struct archive object:
1033228753Smm */
1034232153Smm
1035232153Smm/* Number of filters in the current filter pipeline. */
1036232153Smm/* Filter #0 is the one closest to the format, -1 is a synonym for the
1037232153Smm * last filter, which is always the pseudo-filter that wraps the
1038232153Smm * client callbacks. */
1039232153Smm__LA_DECL int		 archive_filter_count(struct archive *);
1040299529Smm__LA_DECL la_int64_t	 archive_filter_bytes(struct archive *, int);
1041232153Smm__LA_DECL int		 archive_filter_code(struct archive *, int);
1042232153Smm__LA_DECL const char *	 archive_filter_name(struct archive *, int);
1043232153Smm
1044232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
1045232153Smm/* These don't properly handle multiple filters, so are deprecated and
1046232153Smm * will eventually be removed. */
1047232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
1048299529Smm__LA_DECL la_int64_t	 archive_position_compressed(struct archive *)
1049248616Smm				__LA_DEPRECATED;
1050232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
1051299529Smm__LA_DECL la_int64_t	 archive_position_uncompressed(struct archive *)
1052248616Smm				__LA_DEPRECATED;
1053232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
1054248616Smm__LA_DECL const char	*archive_compression_name(struct archive *)
1055248616Smm				__LA_DEPRECATED;
1056232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
1057248616Smm__LA_DECL int		 archive_compression(struct archive *)
1058248616Smm				__LA_DEPRECATED;
1059232153Smm#endif
1060232153Smm
1061228753Smm__LA_DECL int		 archive_errno(struct archive *);
1062228753Smm__LA_DECL const char	*archive_error_string(struct archive *);
1063228753Smm__LA_DECL const char	*archive_format_name(struct archive *);
1064228753Smm__LA_DECL int		 archive_format(struct archive *);
1065228753Smm__LA_DECL void		 archive_clear_error(struct archive *);
1066228753Smm__LA_DECL void		 archive_set_error(struct archive *, int _err,
1067228753Smm			    const char *fmt, ...) __LA_PRINTF(3, 4);
1068228753Smm__LA_DECL void		 archive_copy_error(struct archive *dest,
1069228753Smm			    struct archive *src);
1070228753Smm__LA_DECL int		 archive_file_count(struct archive *);
1071228753Smm
1072238856Smm/*
1073238856Smm * ARCHIVE_MATCH API
1074238856Smm */
1075238856Smm__LA_DECL struct archive *archive_match_new(void);
1076238856Smm__LA_DECL int	archive_match_free(struct archive *);
1077238856Smm
1078238856Smm/*
1079238856Smm * Test if archive_entry is excluded.
1080238856Smm * This is a convenience function. This is the same as calling all
1081238856Smm * archive_match_path_excluded, archive_match_time_excluded
1082238856Smm * and archive_match_owner_excluded.
1083238856Smm */
1084238856Smm__LA_DECL int	archive_match_excluded(struct archive *,
1085238856Smm		    struct archive_entry *);
1086238856Smm
1087238856Smm/*
1088238856Smm * Test if pathname is excluded. The conditions are set by following functions.
1089238856Smm */
1090238856Smm__LA_DECL int	archive_match_path_excluded(struct archive *,
1091238856Smm		    struct archive_entry *);
1092238856Smm/* Add exclusion pathname pattern. */
1093238856Smm__LA_DECL int	archive_match_exclude_pattern(struct archive *, const char *);
1094238856Smm__LA_DECL int	archive_match_exclude_pattern_w(struct archive *,
1095238856Smm		    const wchar_t *);
1096238856Smm/* Add exclusion pathname pattern from file. */
1097238856Smm__LA_DECL int	archive_match_exclude_pattern_from_file(struct archive *,
1098238856Smm		    const char *, int _nullSeparator);
1099238856Smm__LA_DECL int	archive_match_exclude_pattern_from_file_w(struct archive *,
1100238856Smm		    const wchar_t *, int _nullSeparator);
1101238856Smm/* Add inclusion pathname pattern. */
1102238856Smm__LA_DECL int	archive_match_include_pattern(struct archive *, const char *);
1103238856Smm__LA_DECL int	archive_match_include_pattern_w(struct archive *,
1104238856Smm		    const wchar_t *);
1105238856Smm/* Add inclusion pathname pattern from file. */
1106238856Smm__LA_DECL int	archive_match_include_pattern_from_file(struct archive *,
1107238856Smm		    const char *, int _nullSeparator);
1108238856Smm__LA_DECL int	archive_match_include_pattern_from_file_w(struct archive *,
1109238856Smm		    const wchar_t *, int _nullSeparator);
1110238856Smm/*
1111238856Smm * How to get statistic information for inclusion patterns.
1112238856Smm */
1113238856Smm/* Return the amount number of unmatched inclusion patterns. */
1114238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions(struct archive *);
1115238856Smm/* Return the pattern of unmatched inclusion with ARCHIVE_OK.
1116238856Smm * Return ARCHIVE_EOF if there is no inclusion pattern. */
1117238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions_next(
1118238856Smm		    struct archive *, const char **);
1119238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions_next_w(
1120238856Smm		    struct archive *, const wchar_t **);
1121238856Smm
1122238856Smm/*
1123238856Smm * Test if a file is excluded by its time stamp.
1124238856Smm * The conditions are set by following functions.
1125238856Smm */
1126238856Smm__LA_DECL int	archive_match_time_excluded(struct archive *,
1127238856Smm		    struct archive_entry *);
1128238856Smm
1129238856Smm/*
1130238856Smm * Flags to tell a matching type of time stamps. These are used for
1131311041Smm * following functions.
1132238856Smm */
1133238856Smm/* Time flag: mtime to be tested. */
1134238856Smm#define ARCHIVE_MATCH_MTIME	(0x0100)
1135238856Smm/* Time flag: ctime to be tested. */
1136238856Smm#define ARCHIVE_MATCH_CTIME	(0x0200)
1137238856Smm/* Comparison flag: Match the time if it is newer than. */
1138238856Smm#define ARCHIVE_MATCH_NEWER	(0x0001)
1139238856Smm/* Comparison flag: Match the time if it is older than. */
1140238856Smm#define ARCHIVE_MATCH_OLDER	(0x0002)
1141238856Smm/* Comparison flag: Match the time if it is equal to. */
1142238856Smm#define ARCHIVE_MATCH_EQUAL	(0x0010)
1143238856Smm/* Set inclusion time. */
1144238856Smm__LA_DECL int	archive_match_include_time(struct archive *, int _flag,
1145238856Smm		    time_t _sec, long _nsec);
1146238856Smm/* Set inclusion time by a date string. */
1147238856Smm__LA_DECL int	archive_match_include_date(struct archive *, int _flag,
1148238856Smm		    const char *_datestr);
1149238856Smm__LA_DECL int	archive_match_include_date_w(struct archive *, int _flag,
1150238856Smm		    const wchar_t *_datestr);
1151311041Smm/* Set inclusion time by a particular file. */
1152238856Smm__LA_DECL int	archive_match_include_file_time(struct archive *,
1153238856Smm		    int _flag, const char *_pathname);
1154238856Smm__LA_DECL int	archive_match_include_file_time_w(struct archive *,
1155238856Smm		    int _flag, const wchar_t *_pathname);
1156238856Smm/* Add exclusion entry. */
1157238856Smm__LA_DECL int	archive_match_exclude_entry(struct archive *,
1158238856Smm		    int _flag, struct archive_entry *);
1159238856Smm
1160238856Smm/*
1161238856Smm * Test if a file is excluded by its uid ,gid, uname or gname.
1162238856Smm * The conditions are set by following functions.
1163238856Smm */
1164238856Smm__LA_DECL int	archive_match_owner_excluded(struct archive *,
1165238856Smm		    struct archive_entry *);
1166238856Smm/* Add inclusion uid, gid, uname and gname. */
1167299529Smm__LA_DECL int	archive_match_include_uid(struct archive *, la_int64_t);
1168299529Smm__LA_DECL int	archive_match_include_gid(struct archive *, la_int64_t);
1169238856Smm__LA_DECL int	archive_match_include_uname(struct archive *, const char *);
1170238856Smm__LA_DECL int	archive_match_include_uname_w(struct archive *,
1171238856Smm		    const wchar_t *);
1172238856Smm__LA_DECL int	archive_match_include_gname(struct archive *, const char *);
1173238856Smm__LA_DECL int	archive_match_include_gname_w(struct archive *,
1174238856Smm		    const wchar_t *);
1175238856Smm
1176299529Smm/* Utility functions */
1177299529Smm/* Convenience function to sort a NULL terminated list of strings */
1178299529Smm__LA_DECL int archive_utility_string_sort(char **);
1179299529Smm
1180228753Smm#ifdef __cplusplus
1181228753Smm}
1182228753Smm#endif
1183228753Smm
1184228753Smm/* These are meaningless outside of this header. */
1185228753Smm#undef __LA_DECL
1186228753Smm
1187228753Smm#endif /* !ARCHIVE_H_INCLUDED */
1188