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: releng/10.3/contrib/libarchive/libarchive/archive.h 301048 2016-05-31 16:35:03Z glebius $
26228753Smm */
27228753Smm
28228753Smm#ifndef ARCHIVE_H_INCLUDED
29228753Smm#define	ARCHIVE_H_INCLUDED
30228753Smm
31232153Smm#include <sys/stat.h>
32232153Smm#include <stddef.h>  /* for wchar_t */
33232153Smm#include <stdio.h> /* For FILE * */
34232153Smm
35228753Smm/*
36228753Smm * Note: archive.h is for use outside of libarchive; the configuration
37228753Smm * headers (config.h, archive_platform.h, etc.) are purely internal.
38228753Smm * Do NOT use HAVE_XXX configuration macros to control the behavior of
39228753Smm * this header!  If you must conditionalize, use predefined compiler and/or
40228753Smm * platform macros.
41228753Smm */
42228753Smm#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
43232153Smm# include <stdint.h>
44232153Smm#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS)
45232153Smm# include <inttypes.h>
46228753Smm#endif
47228753Smm
48228753Smm/* Get appropriate definitions of standard POSIX-style types. */
49228753Smm/* These should match the types used in 'struct stat' */
50228753Smm#if defined(_WIN32) && !defined(__CYGWIN__)
51232153Smm# define	__LA_INT64_T	__int64
52228753Smm# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
53228753Smm#  define	__LA_SSIZE_T	ssize_t
54228753Smm# elif defined(_WIN64)
55228753Smm#  define	__LA_SSIZE_T	__int64
56228753Smm# else
57228753Smm#  define	__LA_SSIZE_T	long
58228753Smm# endif
59228753Smm#else
60238856Smm# include <unistd.h>  /* ssize_t */
61232153Smm# if defined(_SCO_DS)
62232153Smm#  define	__LA_INT64_T	long long
63232153Smm# else
64232153Smm#  define	__LA_INT64_T	int64_t
65232153Smm# endif
66232153Smm# define	__LA_SSIZE_T	ssize_t
67228753Smm#endif
68228753Smm
69228753Smm/*
70228753Smm * On Windows, define LIBARCHIVE_STATIC if you're building or using a
71228753Smm * .lib.  The default here assumes you're building a DLL.  Only
72228753Smm * libarchive source should ever define __LIBARCHIVE_BUILD.
73228753Smm */
74228753Smm#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
75228753Smm# ifdef __LIBARCHIVE_BUILD
76228753Smm#  ifdef __GNUC__
77228753Smm#   define __LA_DECL	__attribute__((dllexport)) extern
78228753Smm#  else
79228753Smm#   define __LA_DECL	__declspec(dllexport)
80228753Smm#  endif
81228753Smm# else
82228753Smm#  ifdef __GNUC__
83232153Smm#   define __LA_DECL
84228753Smm#  else
85228753Smm#   define __LA_DECL	__declspec(dllimport)
86228753Smm#  endif
87228753Smm# endif
88228753Smm#else
89228753Smm/* Static libraries or non-Windows needs no special declaration. */
90228753Smm# define __LA_DECL
91228753Smm#endif
92228753Smm
93232153Smm#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__)
94228753Smm#define	__LA_PRINTF(fmtarg, firstvararg) \
95228753Smm	__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
96228753Smm#else
97228753Smm#define	__LA_PRINTF(fmtarg, firstvararg)	/* nothing */
98228753Smm#endif
99228753Smm
100248616Smm#if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
101248616Smm# define __LA_DEPRECATED __attribute__((deprecated))
102248616Smm#else
103248616Smm# define __LA_DEPRECATED
104248616Smm#endif
105248616Smm
106228753Smm#ifdef __cplusplus
107228753Smmextern "C" {
108228753Smm#endif
109228753Smm
110228753Smm/*
111228753Smm * The version number is provided as both a macro and a function.
112228753Smm * The macro identifies the installed header; the function identifies
113228753Smm * the library version (which may not be the same if you're using a
114228753Smm * dynamically-linked version of the library).  Of course, if the
115228753Smm * header and library are very different, you should expect some
116228753Smm * strangeness.  Don't do that.
117228753Smm */
118228753Smm
119228753Smm/*
120228753Smm * The version number is expressed as a single integer that makes it
121228753Smm * easy to compare versions at build time: for version a.b.c, the
122228753Smm * version number is printf("%d%03d%03d",a,b,c).  For example, if you
123228753Smm * know your application requires version 2.12.108 or later, you can
124232153Smm * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
125228753Smm */
126232153Smm/* Note: Compiler will complain if this does not match archive_entry.h! */
127248616Smm#define	ARCHIVE_VERSION_NUMBER 3001002
128228753Smm__LA_DECL int		archive_version_number(void);
129228753Smm
130228753Smm/*
131228753Smm * Textual name/version of the library, useful for version displays.
132228753Smm */
133248616Smm#define	ARCHIVE_VERSION_STRING "libarchive 3.1.2"
134228753Smm__LA_DECL const char *	archive_version_string(void);
135228753Smm
136228753Smm/* Declare our basic types. */
137228753Smmstruct archive;
138228753Smmstruct archive_entry;
139228753Smm
140228753Smm/*
141228753Smm * Error codes: Use archive_errno() and archive_error_string()
142228753Smm * to retrieve details.  Unless specified otherwise, all functions
143228753Smm * that return 'int' use these codes.
144228753Smm */
145228753Smm#define	ARCHIVE_EOF	  1	/* Found end of archive. */
146228753Smm#define	ARCHIVE_OK	  0	/* Operation was successful. */
147228753Smm#define	ARCHIVE_RETRY	(-10)	/* Retry might succeed. */
148228753Smm#define	ARCHIVE_WARN	(-20)	/* Partial success. */
149228753Smm/* For example, if write_header "fails", then you can't push data. */
150228753Smm#define	ARCHIVE_FAILED	(-25)	/* Current operation cannot complete. */
151228753Smm/* But if write_header is "fatal," then this archive is dead and useless. */
152228753Smm#define	ARCHIVE_FATAL	(-30)	/* No more operations are possible. */
153228753Smm
154228753Smm/*
155228753Smm * As far as possible, archive_errno returns standard platform errno codes.
156228753Smm * Of course, the details vary by platform, so the actual definitions
157228753Smm * here are stored in "archive_platform.h".  The symbols are listed here
158228753Smm * for reference; as a rule, clients should not need to know the exact
159228753Smm * platform-dependent error code.
160228753Smm */
161228753Smm/* Unrecognized or invalid file format. */
162228753Smm/* #define	ARCHIVE_ERRNO_FILE_FORMAT */
163228753Smm/* Illegal usage of the library. */
164228753Smm/* #define	ARCHIVE_ERRNO_PROGRAMMER_ERROR */
165228753Smm/* Unknown or unclassified error. */
166228753Smm/* #define	ARCHIVE_ERRNO_MISC */
167228753Smm
168228753Smm/*
169228753Smm * Callbacks are invoked to automatically read/skip/write/open/close the
170228753Smm * archive. You can provide your own for complex tasks (like breaking
171228753Smm * archives across multiple tapes) or use standard ones built into the
172228753Smm * library.
173228753Smm */
174228753Smm
175228753Smm/* Returns pointer and size of next block of data from archive. */
176228753Smmtypedef __LA_SSIZE_T	archive_read_callback(struct archive *,
177228753Smm			    void *_client_data, const void **_buffer);
178228753Smm
179232153Smm/* Skips at most request bytes from archive and returns the skipped amount.
180232153Smm * This may skip fewer bytes than requested; it may even skip zero bytes.
181232153Smm * If you do skip fewer bytes than requested, libarchive will invoke your
182232153Smm * read callback and discard data as necessary to make up the full skip.
183232153Smm */
184228753Smmtypedef __LA_INT64_T	archive_skip_callback(struct archive *,
185228753Smm			    void *_client_data, __LA_INT64_T request);
186228753Smm
187232153Smm/* Seeks to specified location in the file and returns the position.
188232153Smm * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
189232153Smm * Return ARCHIVE_FATAL if the seek fails for any reason.
190232153Smm */
191232153Smmtypedef __LA_INT64_T	archive_seek_callback(struct archive *,
192232153Smm    void *_client_data, __LA_INT64_T offset, int whence);
193232153Smm
194228753Smm/* Returns size actually written, zero on EOF, -1 on error. */
195228753Smmtypedef __LA_SSIZE_T	archive_write_callback(struct archive *,
196228753Smm			    void *_client_data,
197228753Smm			    const void *_buffer, size_t _length);
198228753Smm
199228753Smmtypedef int	archive_open_callback(struct archive *, void *_client_data);
200228753Smm
201228753Smmtypedef int	archive_close_callback(struct archive *, void *_client_data);
202228753Smm
203248616Smm/* Switches from one client data object to the next/prev client data object.
204248616Smm * This is useful for reading from different data blocks such as a set of files
205248616Smm * that make up one large file.
206248616Smm */
207248616Smmtypedef int archive_switch_callback(struct archive *, void *_client_data1,
208248616Smm			    void *_client_data2);
209248616Smm
210228753Smm/*
211232153Smm * Codes to identify various stream filters.
212228753Smm */
213232153Smm#define	ARCHIVE_FILTER_NONE	0
214232153Smm#define	ARCHIVE_FILTER_GZIP	1
215232153Smm#define	ARCHIVE_FILTER_BZIP2	2
216232153Smm#define	ARCHIVE_FILTER_COMPRESS	3
217232153Smm#define	ARCHIVE_FILTER_PROGRAM	4
218232153Smm#define	ARCHIVE_FILTER_LZMA	5
219232153Smm#define	ARCHIVE_FILTER_XZ	6
220232153Smm#define	ARCHIVE_FILTER_UU	7
221232153Smm#define	ARCHIVE_FILTER_RPM	8
222232153Smm#define	ARCHIVE_FILTER_LZIP	9
223248616Smm#define	ARCHIVE_FILTER_LRZIP	10
224248616Smm#define	ARCHIVE_FILTER_LZOP	11
225248616Smm#define	ARCHIVE_FILTER_GRZIP	12
226228753Smm
227232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
228232153Smm#define	ARCHIVE_COMPRESSION_NONE	ARCHIVE_FILTER_NONE
229232153Smm#define	ARCHIVE_COMPRESSION_GZIP	ARCHIVE_FILTER_GZIP
230232153Smm#define	ARCHIVE_COMPRESSION_BZIP2	ARCHIVE_FILTER_BZIP2
231232153Smm#define	ARCHIVE_COMPRESSION_COMPRESS	ARCHIVE_FILTER_COMPRESS
232232153Smm#define	ARCHIVE_COMPRESSION_PROGRAM	ARCHIVE_FILTER_PROGRAM
233232153Smm#define	ARCHIVE_COMPRESSION_LZMA	ARCHIVE_FILTER_LZMA
234232153Smm#define	ARCHIVE_COMPRESSION_XZ		ARCHIVE_FILTER_XZ
235232153Smm#define	ARCHIVE_COMPRESSION_UU		ARCHIVE_FILTER_UU
236232153Smm#define	ARCHIVE_COMPRESSION_RPM		ARCHIVE_FILTER_RPM
237232153Smm#define	ARCHIVE_COMPRESSION_LZIP	ARCHIVE_FILTER_LZIP
238248616Smm#define	ARCHIVE_COMPRESSION_LRZIP	ARCHIVE_FILTER_LRZIP
239232153Smm#endif
240232153Smm
241228753Smm/*
242228753Smm * Codes returned by archive_format.
243228753Smm *
244228753Smm * Top 16 bits identifies the format family (e.g., "tar"); lower
245228753Smm * 16 bits indicate the variant.  This is updated by read_next_header.
246228753Smm * Note that the lower 16 bits will often vary from entry to entry.
247228753Smm * In some cases, this variation occurs as libarchive learns more about
248228753Smm * the archive (for example, later entries might utilize extensions that
249228753Smm * weren't necessary earlier in the archive; in this case, libarchive
250228753Smm * will change the format code to indicate the extended format that
251228753Smm * was used).  In other cases, it's because different tools have
252228753Smm * modified the archive and so different parts of the archive
253232153Smm * actually have slightly different formats.  (Both tar and cpio store
254228753Smm * format codes in each entry, so it is quite possible for each
255228753Smm * entry to be in a different format.)
256228753Smm */
257228753Smm#define	ARCHIVE_FORMAT_BASE_MASK		0xff0000
258228753Smm#define	ARCHIVE_FORMAT_CPIO			0x10000
259228753Smm#define	ARCHIVE_FORMAT_CPIO_POSIX		(ARCHIVE_FORMAT_CPIO | 1)
260228753Smm#define	ARCHIVE_FORMAT_CPIO_BIN_LE		(ARCHIVE_FORMAT_CPIO | 2)
261228753Smm#define	ARCHIVE_FORMAT_CPIO_BIN_BE		(ARCHIVE_FORMAT_CPIO | 3)
262228753Smm#define	ARCHIVE_FORMAT_CPIO_SVR4_NOCRC		(ARCHIVE_FORMAT_CPIO | 4)
263228753Smm#define	ARCHIVE_FORMAT_CPIO_SVR4_CRC		(ARCHIVE_FORMAT_CPIO | 5)
264232153Smm#define	ARCHIVE_FORMAT_CPIO_AFIO_LARGE		(ARCHIVE_FORMAT_CPIO | 6)
265228753Smm#define	ARCHIVE_FORMAT_SHAR			0x20000
266228753Smm#define	ARCHIVE_FORMAT_SHAR_BASE		(ARCHIVE_FORMAT_SHAR | 1)
267228753Smm#define	ARCHIVE_FORMAT_SHAR_DUMP		(ARCHIVE_FORMAT_SHAR | 2)
268228753Smm#define	ARCHIVE_FORMAT_TAR			0x30000
269228753Smm#define	ARCHIVE_FORMAT_TAR_USTAR		(ARCHIVE_FORMAT_TAR | 1)
270228753Smm#define	ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE	(ARCHIVE_FORMAT_TAR | 2)
271228753Smm#define	ARCHIVE_FORMAT_TAR_PAX_RESTRICTED	(ARCHIVE_FORMAT_TAR | 3)
272228753Smm#define	ARCHIVE_FORMAT_TAR_GNUTAR		(ARCHIVE_FORMAT_TAR | 4)
273228753Smm#define	ARCHIVE_FORMAT_ISO9660			0x40000
274228753Smm#define	ARCHIVE_FORMAT_ISO9660_ROCKRIDGE	(ARCHIVE_FORMAT_ISO9660 | 1)
275228753Smm#define	ARCHIVE_FORMAT_ZIP			0x50000
276228753Smm#define	ARCHIVE_FORMAT_EMPTY			0x60000
277228753Smm#define	ARCHIVE_FORMAT_AR			0x70000
278228753Smm#define	ARCHIVE_FORMAT_AR_GNU			(ARCHIVE_FORMAT_AR | 1)
279228753Smm#define	ARCHIVE_FORMAT_AR_BSD			(ARCHIVE_FORMAT_AR | 2)
280228753Smm#define	ARCHIVE_FORMAT_MTREE			0x80000
281228753Smm#define	ARCHIVE_FORMAT_RAW			0x90000
282228753Smm#define	ARCHIVE_FORMAT_XAR			0xA0000
283232153Smm#define	ARCHIVE_FORMAT_LHA			0xB0000
284232153Smm#define	ARCHIVE_FORMAT_CAB			0xC0000
285232153Smm#define	ARCHIVE_FORMAT_RAR			0xD0000
286232153Smm#define	ARCHIVE_FORMAT_7ZIP			0xE0000
287228753Smm
288228753Smm/*-
289228753Smm * Basic outline for reading an archive:
290228753Smm *   1) Ask archive_read_new for an archive reader object.
291228753Smm *   2) Update any global properties as appropriate.
292228753Smm *      In particular, you'll certainly want to call appropriate
293228753Smm *      archive_read_support_XXX functions.
294228753Smm *   3) Call archive_read_open_XXX to open the archive
295228753Smm *   4) Repeatedly call archive_read_next_header to get information about
296228753Smm *      successive archive entries.  Call archive_read_data to extract
297228753Smm *      data for entries of interest.
298228753Smm *   5) Call archive_read_finish to end processing.
299228753Smm */
300228753Smm__LA_DECL struct archive	*archive_read_new(void);
301228753Smm
302228753Smm/*
303228753Smm * The archive_read_support_XXX calls enable auto-detect for this
304228753Smm * archive handle.  They also link in the necessary support code.
305228753Smm * For example, if you don't want bzlib linked in, don't invoke
306228753Smm * support_compression_bzip2().  The "all" functions provide the
307228753Smm * obvious shorthand.
308228753Smm */
309232153Smm
310232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
311248616Smm__LA_DECL int archive_read_support_compression_all(struct archive *)
312248616Smm		__LA_DEPRECATED;
313248616Smm__LA_DECL int archive_read_support_compression_bzip2(struct archive *)
314248616Smm		__LA_DEPRECATED;
315248616Smm__LA_DECL int archive_read_support_compression_compress(struct archive *)
316248616Smm		__LA_DEPRECATED;
317248616Smm__LA_DECL int archive_read_support_compression_gzip(struct archive *)
318248616Smm		__LA_DEPRECATED;
319248616Smm__LA_DECL int archive_read_support_compression_lzip(struct archive *)
320248616Smm		__LA_DEPRECATED;
321248616Smm__LA_DECL int archive_read_support_compression_lzma(struct archive *)
322248616Smm		__LA_DEPRECATED;
323248616Smm__LA_DECL int archive_read_support_compression_none(struct archive *)
324248616Smm		__LA_DEPRECATED;
325232153Smm__LA_DECL int archive_read_support_compression_program(struct archive *,
326248616Smm		     const char *command) __LA_DEPRECATED;
327232153Smm__LA_DECL int archive_read_support_compression_program_signature
328232153Smm		(struct archive *, const char *,
329248616Smm		 const void * /* match */, size_t) __LA_DEPRECATED;
330228753Smm
331248616Smm__LA_DECL int archive_read_support_compression_rpm(struct archive *)
332248616Smm		__LA_DEPRECATED;
333248616Smm__LA_DECL int archive_read_support_compression_uu(struct archive *)
334248616Smm		__LA_DEPRECATED;
335248616Smm__LA_DECL int archive_read_support_compression_xz(struct archive *)
336248616Smm		__LA_DEPRECATED;
337232153Smm#endif
338228753Smm
339232153Smm__LA_DECL int archive_read_support_filter_all(struct archive *);
340232153Smm__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
341232153Smm__LA_DECL int archive_read_support_filter_compress(struct archive *);
342232153Smm__LA_DECL int archive_read_support_filter_gzip(struct archive *);
343248616Smm__LA_DECL int archive_read_support_filter_grzip(struct archive *);
344248616Smm__LA_DECL int archive_read_support_filter_lrzip(struct archive *);
345232153Smm__LA_DECL int archive_read_support_filter_lzip(struct archive *);
346232153Smm__LA_DECL int archive_read_support_filter_lzma(struct archive *);
347248616Smm__LA_DECL int archive_read_support_filter_lzop(struct archive *);
348232153Smm__LA_DECL int archive_read_support_filter_none(struct archive *);
349232153Smm__LA_DECL int archive_read_support_filter_program(struct archive *,
350232153Smm		     const char *command);
351232153Smm__LA_DECL int archive_read_support_filter_program_signature
352248616Smm		(struct archive *, const char * /* cmd */,
353232153Smm				    const void * /* match */, size_t);
354232153Smm__LA_DECL int archive_read_support_filter_rpm(struct archive *);
355232153Smm__LA_DECL int archive_read_support_filter_uu(struct archive *);
356232153Smm__LA_DECL int archive_read_support_filter_xz(struct archive *);
357228753Smm
358232153Smm__LA_DECL int archive_read_support_format_7zip(struct archive *);
359232153Smm__LA_DECL int archive_read_support_format_all(struct archive *);
360232153Smm__LA_DECL int archive_read_support_format_ar(struct archive *);
361232153Smm__LA_DECL int archive_read_support_format_by_code(struct archive *, int);
362232153Smm__LA_DECL int archive_read_support_format_cab(struct archive *);
363232153Smm__LA_DECL int archive_read_support_format_cpio(struct archive *);
364232153Smm__LA_DECL int archive_read_support_format_empty(struct archive *);
365232153Smm__LA_DECL int archive_read_support_format_gnutar(struct archive *);
366232153Smm__LA_DECL int archive_read_support_format_iso9660(struct archive *);
367232153Smm__LA_DECL int archive_read_support_format_lha(struct archive *);
368232153Smm__LA_DECL int archive_read_support_format_mtree(struct archive *);
369232153Smm__LA_DECL int archive_read_support_format_rar(struct archive *);
370232153Smm__LA_DECL int archive_read_support_format_raw(struct archive *);
371232153Smm__LA_DECL int archive_read_support_format_tar(struct archive *);
372232153Smm__LA_DECL int archive_read_support_format_xar(struct archive *);
373232153Smm__LA_DECL int archive_read_support_format_zip(struct archive *);
374232153Smm
375248616Smm/* Functions to manually set the format and filters to be used. This is
376248616Smm * useful to bypass the bidding process when the format and filters to use
377248616Smm * is known in advance.
378248616Smm */
379248616Smm__LA_DECL int archive_read_set_format(struct archive *, int);
380248616Smm__LA_DECL int archive_read_append_filter(struct archive *, int);
381248616Smm__LA_DECL int archive_read_append_filter_program(struct archive *,
382248616Smm    const char *);
383248616Smm__LA_DECL int archive_read_append_filter_program_signature
384248616Smm    (struct archive *, const char *, const void * /* match */, size_t);
385248616Smm
386232153Smm/* Set various callbacks. */
387232153Smm__LA_DECL int archive_read_set_open_callback(struct archive *,
388232153Smm    archive_open_callback *);
389232153Smm__LA_DECL int archive_read_set_read_callback(struct archive *,
390232153Smm    archive_read_callback *);
391232153Smm__LA_DECL int archive_read_set_seek_callback(struct archive *,
392232153Smm    archive_seek_callback *);
393232153Smm__LA_DECL int archive_read_set_skip_callback(struct archive *,
394232153Smm    archive_skip_callback *);
395232153Smm__LA_DECL int archive_read_set_close_callback(struct archive *,
396232153Smm    archive_close_callback *);
397248616Smm/* Callback used to switch between one data object to the next */
398248616Smm__LA_DECL int archive_read_set_switch_callback(struct archive *,
399248616Smm    archive_switch_callback *);
400248616Smm
401248616Smm/* This sets the first data object. */
402232153Smm__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
403248616Smm/* This sets data object at specified index */
404248616Smm__LA_DECL int archive_read_set_callback_data2(struct archive *, void *,
405248616Smm    unsigned int);
406248616Smm/* This adds a data object at the specified index. */
407248616Smm__LA_DECL int archive_read_add_callback_data(struct archive *, void *,
408248616Smm    unsigned int);
409248616Smm/* This appends a data object to the end of list */
410248616Smm__LA_DECL int archive_read_append_callback_data(struct archive *, void *);
411248616Smm/* This prepends a data object to the beginning of list */
412248616Smm__LA_DECL int archive_read_prepend_callback_data(struct archive *, void *);
413248616Smm
414232153Smm/* Opening freezes the callbacks. */
415232153Smm__LA_DECL int archive_read_open1(struct archive *);
416232153Smm
417232153Smm/* Convenience wrappers around the above. */
418232153Smm__LA_DECL int archive_read_open(struct archive *, void *_client_data,
419228753Smm		     archive_open_callback *, archive_read_callback *,
420228753Smm		     archive_close_callback *);
421232153Smm__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
422228753Smm		     archive_open_callback *, archive_read_callback *,
423228753Smm		     archive_skip_callback *, archive_close_callback *);
424228753Smm
425228753Smm/*
426228753Smm * A variety of shortcuts that invoke archive_read_open() with
427228753Smm * canned callbacks suitable for common situations.  The ones that
428228753Smm * accept a block size handle tape blocking correctly.
429228753Smm */
430228753Smm/* Use this if you know the filename.  Note: NULL indicates stdin. */
431232153Smm__LA_DECL int archive_read_open_filename(struct archive *,
432228753Smm		     const char *_filename, size_t _block_size);
433248616Smm/* Use this for reading multivolume files by filenames.
434248616Smm * NOTE: Must be NULL terminated. Sorting is NOT done. */
435248616Smm__LA_DECL int archive_read_open_filenames(struct archive *,
436248616Smm		     const char **_filenames, size_t _block_size);
437232153Smm__LA_DECL int archive_read_open_filename_w(struct archive *,
438232153Smm		     const wchar_t *_filename, size_t _block_size);
439228753Smm/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
440232153Smm__LA_DECL int archive_read_open_file(struct archive *,
441248616Smm		     const char *_filename, size_t _block_size) __LA_DEPRECATED;
442228753Smm/* Read an archive that's stored in memory. */
443232153Smm__LA_DECL int archive_read_open_memory(struct archive *,
444228753Smm		     void * buff, size_t size);
445228753Smm/* A more involved version that is only used for internal testing. */
446232153Smm__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff,
447228753Smm		     size_t size, size_t read_size);
448228753Smm/* Read an archive that's already open, using the file descriptor. */
449232153Smm__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
450228753Smm		     size_t _block_size);
451228753Smm/* Read an archive that's already open, using a FILE *. */
452228753Smm/* Note: DO NOT use this with tape drives. */
453232153Smm__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
454228753Smm
455228753Smm/* Parses and returns next entry header. */
456232153Smm__LA_DECL int archive_read_next_header(struct archive *,
457228753Smm		     struct archive_entry **);
458228753Smm
459228753Smm/* Parses and returns next entry header using the archive_entry passed in */
460232153Smm__LA_DECL int archive_read_next_header2(struct archive *,
461228753Smm		     struct archive_entry *);
462228753Smm
463228753Smm/*
464228753Smm * Retrieve the byte offset in UNCOMPRESSED data where last-read
465228753Smm * header started.
466228753Smm */
467228753Smm__LA_DECL __LA_INT64_T		 archive_read_header_position(struct archive *);
468228753Smm
469228753Smm/* Read data from the body of an entry.  Similar to read(2). */
470228753Smm__LA_DECL __LA_SSIZE_T		 archive_read_data(struct archive *,
471228753Smm				    void *, size_t);
472228753Smm
473248616Smm/* Seek within the body of an entry.  Similar to lseek(2). */
474248616Smm__LA_DECL __LA_INT64_T archive_seek_data(struct archive *, __LA_INT64_T, int);
475248616Smm
476228753Smm/*
477228753Smm * A zero-copy version of archive_read_data that also exposes the file offset
478228753Smm * of each returned block.  Note that the client has no way to specify
479228753Smm * the desired size of the block.  The API does guarantee that offsets will
480228753Smm * be strictly increasing and that returned blocks will not overlap.
481228753Smm */
482232153Smm__LA_DECL int archive_read_data_block(struct archive *a,
483232153Smm		    const void **buff, size_t *size, __LA_INT64_T *offset);
484228753Smm
485228753Smm/*-
486228753Smm * Some convenience functions that are built on archive_read_data:
487228753Smm *  'skip': skips entire entry
488228753Smm *  'into_buffer': writes data into memory buffer that you provide
489228753Smm *  'into_fd': writes data to specified filedes
490228753Smm */
491232153Smm__LA_DECL int archive_read_data_skip(struct archive *);
492232153Smm__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
493228753Smm
494228753Smm/*
495228753Smm * Set read options.
496228753Smm */
497232153Smm/* Apply option to the format only. */
498232153Smm__LA_DECL int archive_read_set_format_option(struct archive *_a,
499232153Smm			    const char *m, const char *o,
500232153Smm			    const char *v);
501232153Smm/* Apply option to the filter only. */
502232153Smm__LA_DECL int archive_read_set_filter_option(struct archive *_a,
503232153Smm			    const char *m, const char *o,
504232153Smm			    const char *v);
505232153Smm/* Apply option to both the format and the filter. */
506232153Smm__LA_DECL int archive_read_set_option(struct archive *_a,
507232153Smm			    const char *m, const char *o,
508232153Smm			    const char *v);
509228753Smm/* Apply option string to both the format and the filter. */
510232153Smm__LA_DECL int archive_read_set_options(struct archive *_a,
511232153Smm			    const char *opts);
512228753Smm
513228753Smm/*-
514228753Smm * Convenience function to recreate the current entry (whose header
515228753Smm * has just been read) on disk.
516228753Smm *
517228753Smm * This does quite a bit more than just copy data to disk. It also:
518228753Smm *  - Creates intermediate directories as required.
519228753Smm *  - Manages directory permissions:  non-writable directories will
520228753Smm *    be initially created with write permission enabled; when the
521228753Smm *    archive is closed, dir permissions are edited to the values specified
522228753Smm *    in the archive.
523228753Smm *  - Checks hardlinks:  hardlinks will not be extracted unless the
524228753Smm *    linked-to file was also extracted within the same session. (TODO)
525228753Smm */
526228753Smm
527228753Smm/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
528228753Smm
529228753Smm/* Default: Do not try to set owner/group. */
530228753Smm#define	ARCHIVE_EXTRACT_OWNER			(0x0001)
531228753Smm/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
532228753Smm#define	ARCHIVE_EXTRACT_PERM			(0x0002)
533228753Smm/* Default: Do not restore mtime/atime. */
534228753Smm#define	ARCHIVE_EXTRACT_TIME			(0x0004)
535228753Smm/* Default: Replace existing files. */
536228753Smm#define	ARCHIVE_EXTRACT_NO_OVERWRITE 		(0x0008)
537228753Smm/* Default: Try create first, unlink only if create fails with EEXIST. */
538228753Smm#define	ARCHIVE_EXTRACT_UNLINK			(0x0010)
539228753Smm/* Default: Do not restore ACLs. */
540228753Smm#define	ARCHIVE_EXTRACT_ACL			(0x0020)
541228753Smm/* Default: Do not restore fflags. */
542228753Smm#define	ARCHIVE_EXTRACT_FFLAGS			(0x0040)
543228753Smm/* Default: Do not restore xattrs. */
544228753Smm#define	ARCHIVE_EXTRACT_XATTR 			(0x0080)
545228753Smm/* Default: Do not try to guard against extracts redirected by symlinks. */
546228753Smm/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
547228753Smm#define	ARCHIVE_EXTRACT_SECURE_SYMLINKS		(0x0100)
548228753Smm/* Default: Do not reject entries with '..' as path elements. */
549228753Smm#define	ARCHIVE_EXTRACT_SECURE_NODOTDOT		(0x0200)
550228753Smm/* Default: Create parent directories as needed. */
551228753Smm#define	ARCHIVE_EXTRACT_NO_AUTODIR		(0x0400)
552228753Smm/* Default: Overwrite files, even if one on disk is newer. */
553228753Smm#define	ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER	(0x0800)
554228753Smm/* Detect blocks of 0 and write holes instead. */
555228753Smm#define	ARCHIVE_EXTRACT_SPARSE			(0x1000)
556232153Smm/* Default: Do not restore Mac extended metadata. */
557232153Smm/* This has no effect except on Mac OS. */
558232153Smm#define	ARCHIVE_EXTRACT_MAC_METADATA		(0x2000)
559248616Smm/* Default: Use HFS+ compression if it was compressed. */
560248616Smm/* This has no effect except on Mac OS v10.6 or later. */
561248616Smm#define	ARCHIVE_EXTRACT_NO_HFS_COMPRESSION	(0x4000)
562248616Smm/* Default: Do not use HFS+ compression if it was not compressed. */
563248616Smm/* This has no effect except on Mac OS v10.6 or later. */
564248616Smm#define	ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED	(0x8000)
565301048Sglebius/* Default: Do not reject entries with absolute paths */
566301048Sglebius#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000)
567228753Smm
568232153Smm__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
569228753Smm		     int flags);
570232153Smm__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
571228753Smm		     struct archive * /* dest */);
572228753Smm__LA_DECL void	 archive_read_extract_set_progress_callback(struct archive *,
573228753Smm		     void (*_progress_func)(void *), void *_user_data);
574228753Smm
575228753Smm/* Record the dev/ino of a file that will not be written.  This is
576228753Smm * generally set to the dev/ino of the archive being read. */
577228753Smm__LA_DECL void		archive_read_extract_set_skip_file(struct archive *,
578232153Smm		     __LA_INT64_T, __LA_INT64_T);
579228753Smm
580228753Smm/* Close the file and release most resources. */
581228753Smm__LA_DECL int		 archive_read_close(struct archive *);
582228753Smm/* Release all resources and destroy the object. */
583228773Smm/* Note that archive_read_free will call archive_read_close for you. */
584228773Smm__LA_DECL int		 archive_read_free(struct archive *);
585228773Smm#if ARCHIVE_VERSION_NUMBER < 4000000
586228773Smm/* Synonym for archive_read_free() for backwards compatibility. */
587248616Smm__LA_DECL int		 archive_read_finish(struct archive *) __LA_DEPRECATED;
588228753Smm#endif
589228753Smm
590228753Smm/*-
591228753Smm * To create an archive:
592232153Smm *   1) Ask archive_write_new for an archive writer object.
593228753Smm *   2) Set any global properties.  In particular, you should set
594228753Smm *      the compression and format to use.
595228753Smm *   3) Call archive_write_open to open the file (most people
596228753Smm *       will use archive_write_open_file or archive_write_open_fd,
597228753Smm *       which provide convenient canned I/O callbacks for you).
598228753Smm *   4) For each entry:
599228753Smm *      - construct an appropriate struct archive_entry structure
600228753Smm *      - archive_write_header to write the header
601228753Smm *      - archive_write_data to write the entry data
602228753Smm *   5) archive_write_close to close the output
603228773Smm *   6) archive_write_free to cleanup the writer and release resources
604228753Smm */
605228753Smm__LA_DECL struct archive	*archive_write_new(void);
606232153Smm__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
607228753Smm		     int bytes_per_block);
608232153Smm__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
609228753Smm/* XXX This is badly misnamed; suggestions appreciated. XXX */
610232153Smm__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
611228753Smm		     int bytes_in_last_block);
612232153Smm__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
613228753Smm
614228753Smm/* The dev/ino of a file that won't be archived.  This is used
615228753Smm * to avoid recursively adding an archive to itself. */
616232153Smm__LA_DECL int archive_write_set_skip_file(struct archive *,
617232153Smm    __LA_INT64_T, __LA_INT64_T);
618228753Smm
619232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
620248616Smm__LA_DECL int archive_write_set_compression_bzip2(struct archive *)
621248616Smm		__LA_DEPRECATED;
622248616Smm__LA_DECL int archive_write_set_compression_compress(struct archive *)
623248616Smm		__LA_DEPRECATED;
624248616Smm__LA_DECL int archive_write_set_compression_gzip(struct archive *)
625248616Smm		__LA_DEPRECATED;
626248616Smm__LA_DECL int archive_write_set_compression_lzip(struct archive *)
627248616Smm		__LA_DEPRECATED;
628248616Smm__LA_DECL int archive_write_set_compression_lzma(struct archive *)
629248616Smm		__LA_DEPRECATED;
630248616Smm__LA_DECL int archive_write_set_compression_none(struct archive *)
631248616Smm		__LA_DEPRECATED;
632232153Smm__LA_DECL int archive_write_set_compression_program(struct archive *,
633248616Smm		     const char *cmd) __LA_DEPRECATED;
634248616Smm__LA_DECL int archive_write_set_compression_xz(struct archive *)
635248616Smm		__LA_DEPRECATED;
636232153Smm#endif
637232153Smm
638238856Smm/* A convenience function to set the filter based on the code. */
639238856Smm__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
640248616Smm__LA_DECL int archive_write_add_filter_by_name(struct archive *,
641248616Smm		     const char *name);
642248616Smm__LA_DECL int archive_write_add_filter_b64encode(struct archive *);
643232153Smm__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
644232153Smm__LA_DECL int archive_write_add_filter_compress(struct archive *);
645248616Smm__LA_DECL int archive_write_add_filter_grzip(struct archive *);
646232153Smm__LA_DECL int archive_write_add_filter_gzip(struct archive *);
647248616Smm__LA_DECL int archive_write_add_filter_lrzip(struct archive *);
648232153Smm__LA_DECL int archive_write_add_filter_lzip(struct archive *);
649232153Smm__LA_DECL int archive_write_add_filter_lzma(struct archive *);
650248616Smm__LA_DECL int archive_write_add_filter_lzop(struct archive *);
651232153Smm__LA_DECL int archive_write_add_filter_none(struct archive *);
652232153Smm__LA_DECL int archive_write_add_filter_program(struct archive *,
653232153Smm		     const char *cmd);
654248616Smm__LA_DECL int archive_write_add_filter_uuencode(struct archive *);
655232153Smm__LA_DECL int archive_write_add_filter_xz(struct archive *);
656232153Smm
657232153Smm
658228753Smm/* A convenience function to set the format based on the code or name. */
659232153Smm__LA_DECL int archive_write_set_format(struct archive *, int format_code);
660232153Smm__LA_DECL int archive_write_set_format_by_name(struct archive *,
661228753Smm		     const char *name);
662228753Smm/* To minimize link pollution, use one or more of the following. */
663232153Smm__LA_DECL int archive_write_set_format_7zip(struct archive *);
664232153Smm__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
665232153Smm__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
666232153Smm__LA_DECL int archive_write_set_format_cpio(struct archive *);
667232153Smm__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
668232153Smm__LA_DECL int archive_write_set_format_gnutar(struct archive *);
669232153Smm__LA_DECL int archive_write_set_format_iso9660(struct archive *);
670232153Smm__LA_DECL int archive_write_set_format_mtree(struct archive *);
671248616Smm__LA_DECL int archive_write_set_format_mtree_classic(struct archive *);
672228753Smm/* TODO: int archive_write_set_format_old_tar(struct archive *); */
673232153Smm__LA_DECL int archive_write_set_format_pax(struct archive *);
674232153Smm__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
675232153Smm__LA_DECL int archive_write_set_format_shar(struct archive *);
676232153Smm__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
677232153Smm__LA_DECL int archive_write_set_format_ustar(struct archive *);
678248616Smm__LA_DECL int archive_write_set_format_v7tar(struct archive *);
679232153Smm__LA_DECL int archive_write_set_format_xar(struct archive *);
680232153Smm__LA_DECL int archive_write_set_format_zip(struct archive *);
681248616Smm__LA_DECL int archive_write_zip_set_compression_deflate(struct archive *);
682248616Smm__LA_DECL int archive_write_zip_set_compression_store(struct archive *);
683232153Smm__LA_DECL int archive_write_open(struct archive *, void *,
684228753Smm		     archive_open_callback *, archive_write_callback *,
685228753Smm		     archive_close_callback *);
686232153Smm__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
687232153Smm__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
688232153Smm__LA_DECL int archive_write_open_filename_w(struct archive *,
689232153Smm		     const wchar_t *_file);
690228753Smm/* A deprecated synonym for archive_write_open_filename() */
691248616Smm__LA_DECL int archive_write_open_file(struct archive *, const char *_file)
692248616Smm		__LA_DEPRECATED;
693232153Smm__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
694228753Smm/* _buffSize is the size of the buffer, _used refers to a variable that
695228753Smm * will be updated after each write into the buffer. */
696232153Smm__LA_DECL int archive_write_open_memory(struct archive *,
697228753Smm			void *_buffer, size_t _buffSize, size_t *_used);
698228753Smm
699228753Smm/*
700228753Smm * Note that the library will truncate writes beyond the size provided
701228753Smm * to archive_write_header or pad if the provided data is short.
702228753Smm */
703232153Smm__LA_DECL int archive_write_header(struct archive *,
704228753Smm		     struct archive_entry *);
705232153Smm__LA_DECL __LA_SSIZE_T	archive_write_data(struct archive *,
706228753Smm			    const void *, size_t);
707228753Smm
708232153Smm/* This interface is currently only available for archive_write_disk handles.  */
709228753Smm__LA_DECL __LA_SSIZE_T	 archive_write_data_block(struct archive *,
710228753Smm				    const void *, size_t, __LA_INT64_T);
711232153Smm
712228753Smm__LA_DECL int		 archive_write_finish_entry(struct archive *);
713228753Smm__LA_DECL int		 archive_write_close(struct archive *);
714248616Smm/* Marks the archive as FATAL so that a subsequent free() operation
715248616Smm * won't try to close() cleanly.  Provides a fast abort capability
716248616Smm * when the client discovers that things have gone wrong. */
717248616Smm__LA_DECL int            archive_write_fail(struct archive *);
718228773Smm/* This can fail if the archive wasn't already closed, in which case
719228773Smm * archive_write_free() will implicitly call archive_write_close(). */
720228773Smm__LA_DECL int		 archive_write_free(struct archive *);
721228773Smm#if ARCHIVE_VERSION_NUMBER < 4000000
722228773Smm/* Synonym for archive_write_free() for backwards compatibility. */
723248616Smm__LA_DECL int		 archive_write_finish(struct archive *) __LA_DEPRECATED;
724228753Smm#endif
725228753Smm
726228753Smm/*
727228753Smm * Set write options.
728228753Smm */
729232153Smm/* Apply option to the format only. */
730232153Smm__LA_DECL int archive_write_set_format_option(struct archive *_a,
731232153Smm			    const char *m, const char *o,
732232153Smm			    const char *v);
733232153Smm/* Apply option to the filter only. */
734232153Smm__LA_DECL int archive_write_set_filter_option(struct archive *_a,
735232153Smm			    const char *m, const char *o,
736232153Smm			    const char *v);
737232153Smm/* Apply option to both the format and the filter. */
738232153Smm__LA_DECL int archive_write_set_option(struct archive *_a,
739232153Smm			    const char *m, const char *o,
740232153Smm			    const char *v);
741232153Smm/* Apply option string to both the format and the filter. */
742232153Smm__LA_DECL int archive_write_set_options(struct archive *_a,
743232153Smm			    const char *opts);
744228753Smm
745228753Smm/*-
746228753Smm * ARCHIVE_WRITE_DISK API
747228753Smm *
748228753Smm * To create objects on disk:
749228753Smm *   1) Ask archive_write_disk_new for a new archive_write_disk object.
750228753Smm *   2) Set any global properties.  In particular, you probably
751228753Smm *      want to set the options.
752228753Smm *   3) For each entry:
753228753Smm *      - construct an appropriate struct archive_entry structure
754228753Smm *      - archive_write_header to create the file/dir/etc on disk
755228753Smm *      - archive_write_data to write the entry data
756228773Smm *   4) archive_write_free to cleanup the writer and release resources
757228753Smm *
758228753Smm * In particular, you can use this in conjunction with archive_read()
759228753Smm * to pull entries out of an archive and create them on disk.
760228753Smm */
761228753Smm__LA_DECL struct archive	*archive_write_disk_new(void);
762228753Smm/* This file will not be overwritten. */
763232153Smm__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
764232153Smm    __LA_INT64_T, __LA_INT64_T);
765228753Smm/* Set flags to control how the next item gets created.
766228753Smm * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
767228753Smm__LA_DECL int		 archive_write_disk_set_options(struct archive *,
768228753Smm		     int flags);
769228753Smm/*
770228753Smm * The lookup functions are given uname/uid (or gname/gid) pairs and
771228753Smm * return a uid (gid) suitable for this system.  These are used for
772228753Smm * restoring ownership and for setting ACLs.  The default functions
773228753Smm * are naive, they just return the uid/gid.  These are small, so reasonable
774228753Smm * for applications that don't need to preserve ownership; they
775228753Smm * are probably also appropriate for applications that are doing
776228753Smm * same-system backup and restore.
777228753Smm */
778228753Smm/*
779228753Smm * The "standard" lookup functions use common system calls to lookup
780228753Smm * the uname/gname, falling back to the uid/gid if the names can't be
781228753Smm * found.  They cache lookups and are reasonably fast, but can be very
782228753Smm * large, so they are not used unless you ask for them.  In
783228753Smm * particular, these match the specifications of POSIX "pax" and old
784228753Smm * POSIX "tar".
785228753Smm */
786228753Smm__LA_DECL int	 archive_write_disk_set_standard_lookup(struct archive *);
787228753Smm/*
788228753Smm * If neither the default (naive) nor the standard (big) functions suit
789228753Smm * your needs, you can write your own and register them.  Be sure to
790228753Smm * include a cleanup function if you have allocated private data.
791228753Smm */
792232153Smm__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
793232153Smm    void * /* private_data */,
794232153Smm    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
795232153Smm    void (* /* cleanup */)(void *));
796232153Smm__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
797232153Smm    void * /* private_data */,
798232153Smm    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
799232153Smm    void (* /* cleanup */)(void *));
800232153Smm__LA_DECL __LA_INT64_T archive_write_disk_gid(struct archive *, const char *, __LA_INT64_T);
801232153Smm__LA_DECL __LA_INT64_T archive_write_disk_uid(struct archive *, const char *, __LA_INT64_T);
802228753Smm
803228753Smm/*
804228753Smm * ARCHIVE_READ_DISK API
805228753Smm *
806228753Smm * This is still evolving and somewhat experimental.
807228753Smm */
808228753Smm__LA_DECL struct archive *archive_read_disk_new(void);
809228753Smm/* The names for symlink modes here correspond to an old BSD
810228753Smm * command-line argument convention: -L, -P, -H */
811228753Smm/* Follow all symlinks. */
812228753Smm__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
813228753Smm/* Follow no symlinks. */
814228753Smm__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
815228753Smm/* Follow symlink initially, then not. */
816228753Smm__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
817228753Smm/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
818228753Smm__LA_DECL int archive_read_disk_entry_from_file(struct archive *,
819228753Smm    struct archive_entry *, int /* fd */, const struct stat *);
820228753Smm/* Look up gname for gid or uname for uid. */
821228753Smm/* Default implementations are very, very stupid. */
822232153Smm__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T);
823232153Smm__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T);
824228753Smm/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
825228753Smm * results for performance. */
826228753Smm__LA_DECL int	archive_read_disk_set_standard_lookup(struct archive *);
827228753Smm/* You can install your own lookups if you like. */
828228753Smm__LA_DECL int	archive_read_disk_set_gname_lookup(struct archive *,
829228753Smm    void * /* private_data */,
830232153Smm    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
831228753Smm    void (* /* cleanup_fn */)(void *));
832228753Smm__LA_DECL int	archive_read_disk_set_uname_lookup(struct archive *,
833228753Smm    void * /* private_data */,
834232153Smm    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
835228753Smm    void (* /* cleanup_fn */)(void *));
836232153Smm/* Start traversal. */
837232153Smm__LA_DECL int	archive_read_disk_open(struct archive *, const char *);
838232153Smm__LA_DECL int	archive_read_disk_open_w(struct archive *, const wchar_t *);
839232153Smm/*
840232153Smm * Request that current entry be visited.  If you invoke it on every
841232153Smm * directory, you'll get a physical traversal.  This is ignored if the
842232153Smm * current entry isn't a directory or a link to a directory.  So, if
843232153Smm * you invoke this on every returned path, you'll get a full logical
844232153Smm * traversal.
845232153Smm */
846232153Smm__LA_DECL int	archive_read_disk_descend(struct archive *);
847238856Smm__LA_DECL int	archive_read_disk_can_descend(struct archive *);
848232153Smm__LA_DECL int	archive_read_disk_current_filesystem(struct archive *);
849232153Smm__LA_DECL int	archive_read_disk_current_filesystem_is_synthetic(struct archive *);
850232153Smm__LA_DECL int	archive_read_disk_current_filesystem_is_remote(struct archive *);
851232153Smm/* Request that the access time of the entry visited by travesal be restored. */
852232153Smm__LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
853238856Smm/*
854238856Smm * Set behavior. The "flags" argument selects optional behavior.
855238856Smm */
856238856Smm/* Request that the access time of the entry visited by travesal be restored.
857238856Smm * This is the same as archive_read_disk_set_atime_restored. */
858238856Smm#define	ARCHIVE_READDISK_RESTORE_ATIME		(0x0001)
859238856Smm/* Default: Do not skip an entry which has nodump flags. */
860238856Smm#define	ARCHIVE_READDISK_HONOR_NODUMP		(0x0002)
861238856Smm/* Default: Skip a mac resource fork file whose prefix is "._" because of
862238856Smm * using copyfile. */
863238856Smm#define	ARCHIVE_READDISK_MAC_COPYFILE		(0x0004)
864238856Smm/* Default: Do not traverse mount points. */
865238856Smm#define	ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS	(0x0008)
866228753Smm
867238856Smm__LA_DECL int  archive_read_disk_set_behavior(struct archive *,
868238856Smm		    int flags);
869238856Smm
870228753Smm/*
871238856Smm * Set archive_match object that will be used in archive_read_disk to
872238856Smm * know whether an entry should be skipped. The callback function
873238856Smm * _excluded_func will be invoked when an entry is skipped by the result
874238856Smm * of archive_match.
875238856Smm */
876238856Smm__LA_DECL int	archive_read_disk_set_matching(struct archive *,
877238856Smm		    struct archive *_matching, void (*_excluded_func)
878238856Smm		    (struct archive *, void *, struct archive_entry *),
879238856Smm		    void *_client_data);
880238856Smm__LA_DECL int	archive_read_disk_set_metadata_filter_callback(struct archive *,
881238856Smm		    int (*_metadata_filter_func)(struct archive *, void *,
882238856Smm		    	struct archive_entry *), void *_client_data);
883238856Smm
884238856Smm/*
885228753Smm * Accessor functions to read/set various information in
886228753Smm * the struct archive object:
887228753Smm */
888232153Smm
889232153Smm/* Number of filters in the current filter pipeline. */
890232153Smm/* Filter #0 is the one closest to the format, -1 is a synonym for the
891232153Smm * last filter, which is always the pseudo-filter that wraps the
892232153Smm * client callbacks. */
893232153Smm__LA_DECL int		 archive_filter_count(struct archive *);
894232153Smm__LA_DECL __LA_INT64_T	 archive_filter_bytes(struct archive *, int);
895232153Smm__LA_DECL int		 archive_filter_code(struct archive *, int);
896232153Smm__LA_DECL const char *	 archive_filter_name(struct archive *, int);
897232153Smm
898232153Smm#if ARCHIVE_VERSION_NUMBER < 4000000
899232153Smm/* These don't properly handle multiple filters, so are deprecated and
900232153Smm * will eventually be removed. */
901232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
902248616Smm__LA_DECL __LA_INT64_T	 archive_position_compressed(struct archive *)
903248616Smm				__LA_DEPRECATED;
904232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
905248616Smm__LA_DECL __LA_INT64_T	 archive_position_uncompressed(struct archive *)
906248616Smm				__LA_DEPRECATED;
907232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
908248616Smm__LA_DECL const char	*archive_compression_name(struct archive *)
909248616Smm				__LA_DEPRECATED;
910232153Smm/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
911248616Smm__LA_DECL int		 archive_compression(struct archive *)
912248616Smm				__LA_DEPRECATED;
913232153Smm#endif
914232153Smm
915228753Smm__LA_DECL int		 archive_errno(struct archive *);
916228753Smm__LA_DECL const char	*archive_error_string(struct archive *);
917228753Smm__LA_DECL const char	*archive_format_name(struct archive *);
918228753Smm__LA_DECL int		 archive_format(struct archive *);
919228753Smm__LA_DECL void		 archive_clear_error(struct archive *);
920228753Smm__LA_DECL void		 archive_set_error(struct archive *, int _err,
921228753Smm			    const char *fmt, ...) __LA_PRINTF(3, 4);
922228753Smm__LA_DECL void		 archive_copy_error(struct archive *dest,
923228753Smm			    struct archive *src);
924228753Smm__LA_DECL int		 archive_file_count(struct archive *);
925228753Smm
926238856Smm/*
927238856Smm * ARCHIVE_MATCH API
928238856Smm */
929238856Smm__LA_DECL struct archive *archive_match_new(void);
930238856Smm__LA_DECL int	archive_match_free(struct archive *);
931238856Smm
932238856Smm/*
933238856Smm * Test if archive_entry is excluded.
934238856Smm * This is a convenience function. This is the same as calling all
935238856Smm * archive_match_path_excluded, archive_match_time_excluded
936238856Smm * and archive_match_owner_excluded.
937238856Smm */
938238856Smm__LA_DECL int	archive_match_excluded(struct archive *,
939238856Smm		    struct archive_entry *);
940238856Smm
941238856Smm/*
942238856Smm * Test if pathname is excluded. The conditions are set by following functions.
943238856Smm */
944238856Smm__LA_DECL int	archive_match_path_excluded(struct archive *,
945238856Smm		    struct archive_entry *);
946238856Smm/* Add exclusion pathname pattern. */
947238856Smm__LA_DECL int	archive_match_exclude_pattern(struct archive *, const char *);
948238856Smm__LA_DECL int	archive_match_exclude_pattern_w(struct archive *,
949238856Smm		    const wchar_t *);
950238856Smm/* Add exclusion pathname pattern from file. */
951238856Smm__LA_DECL int	archive_match_exclude_pattern_from_file(struct archive *,
952238856Smm		    const char *, int _nullSeparator);
953238856Smm__LA_DECL int	archive_match_exclude_pattern_from_file_w(struct archive *,
954238856Smm		    const wchar_t *, int _nullSeparator);
955238856Smm/* Add inclusion pathname pattern. */
956238856Smm__LA_DECL int	archive_match_include_pattern(struct archive *, const char *);
957238856Smm__LA_DECL int	archive_match_include_pattern_w(struct archive *,
958238856Smm		    const wchar_t *);
959238856Smm/* Add inclusion pathname pattern from file. */
960238856Smm__LA_DECL int	archive_match_include_pattern_from_file(struct archive *,
961238856Smm		    const char *, int _nullSeparator);
962238856Smm__LA_DECL int	archive_match_include_pattern_from_file_w(struct archive *,
963238856Smm		    const wchar_t *, int _nullSeparator);
964238856Smm/*
965238856Smm * How to get statistic information for inclusion patterns.
966238856Smm */
967238856Smm/* Return the amount number of unmatched inclusion patterns. */
968238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions(struct archive *);
969238856Smm/* Return the pattern of unmatched inclusion with ARCHIVE_OK.
970238856Smm * Return ARCHIVE_EOF if there is no inclusion pattern. */
971238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions_next(
972238856Smm		    struct archive *, const char **);
973238856Smm__LA_DECL int	archive_match_path_unmatched_inclusions_next_w(
974238856Smm		    struct archive *, const wchar_t **);
975238856Smm
976238856Smm/*
977238856Smm * Test if a file is excluded by its time stamp.
978238856Smm * The conditions are set by following functions.
979238856Smm */
980238856Smm__LA_DECL int	archive_match_time_excluded(struct archive *,
981238856Smm		    struct archive_entry *);
982238856Smm
983238856Smm/*
984238856Smm * Flags to tell a matching type of time stamps. These are used for
985238856Smm * following functinos.
986238856Smm */
987238856Smm/* Time flag: mtime to be tested. */
988238856Smm#define ARCHIVE_MATCH_MTIME	(0x0100)
989238856Smm/* Time flag: ctime to be tested. */
990238856Smm#define ARCHIVE_MATCH_CTIME	(0x0200)
991238856Smm/* Comparison flag: Match the time if it is newer than. */
992238856Smm#define ARCHIVE_MATCH_NEWER	(0x0001)
993238856Smm/* Comparison flag: Match the time if it is older than. */
994238856Smm#define ARCHIVE_MATCH_OLDER	(0x0002)
995238856Smm/* Comparison flag: Match the time if it is equal to. */
996238856Smm#define ARCHIVE_MATCH_EQUAL	(0x0010)
997238856Smm/* Set inclusion time. */
998238856Smm__LA_DECL int	archive_match_include_time(struct archive *, int _flag,
999238856Smm		    time_t _sec, long _nsec);
1000238856Smm/* Set inclusion time by a date string. */
1001238856Smm__LA_DECL int	archive_match_include_date(struct archive *, int _flag,
1002238856Smm		    const char *_datestr);
1003238856Smm__LA_DECL int	archive_match_include_date_w(struct archive *, int _flag,
1004238856Smm		    const wchar_t *_datestr);
1005238856Smm/* Set inclusion time by a particluar file. */
1006238856Smm__LA_DECL int	archive_match_include_file_time(struct archive *,
1007238856Smm		    int _flag, const char *_pathname);
1008238856Smm__LA_DECL int	archive_match_include_file_time_w(struct archive *,
1009238856Smm		    int _flag, const wchar_t *_pathname);
1010238856Smm/* Add exclusion entry. */
1011238856Smm__LA_DECL int	archive_match_exclude_entry(struct archive *,
1012238856Smm		    int _flag, struct archive_entry *);
1013238856Smm
1014238856Smm/*
1015238856Smm * Test if a file is excluded by its uid ,gid, uname or gname.
1016238856Smm * The conditions are set by following functions.
1017238856Smm */
1018238856Smm__LA_DECL int	archive_match_owner_excluded(struct archive *,
1019238856Smm		    struct archive_entry *);
1020238856Smm/* Add inclusion uid, gid, uname and gname. */
1021238856Smm__LA_DECL int	archive_match_include_uid(struct archive *, __LA_INT64_T);
1022238856Smm__LA_DECL int	archive_match_include_gid(struct archive *, __LA_INT64_T);
1023238856Smm__LA_DECL int	archive_match_include_uname(struct archive *, const char *);
1024238856Smm__LA_DECL int	archive_match_include_uname_w(struct archive *,
1025238856Smm		    const wchar_t *);
1026238856Smm__LA_DECL int	archive_match_include_gname(struct archive *, const char *);
1027238856Smm__LA_DECL int	archive_match_include_gname_w(struct archive *,
1028238856Smm		    const wchar_t *);
1029238856Smm
1030228753Smm#ifdef __cplusplus
1031228753Smm}
1032228753Smm#endif
1033228753Smm
1034228753Smm/* These are meaningless outside of this header. */
1035228753Smm#undef __LA_DECL
1036228753Smm
1037228753Smm/* These need to remain defined because they're used in the
1038228753Smm * callback type definitions.  XXX Fix this.  This is ugly. XXX */
1039228753Smm/* #undef __LA_INT64_T */
1040228753Smm/* #undef __LA_SSIZE_T */
1041228753Smm
1042228753Smm#endif /* !ARCHIVE_H_INCLUDED */
1043