archive.h revision 238856
1/*-
2 * Copyright (c) 2003-2010 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/contrib/libarchive/libarchive/archive.h 238856 2012-07-28 06:38:44Z mm $
26 */
27
28#ifndef ARCHIVE_H_INCLUDED
29#define	ARCHIVE_H_INCLUDED
30
31#include <sys/stat.h>
32#include <stddef.h>  /* for wchar_t */
33#include <stdio.h> /* For FILE * */
34
35/*
36 * Note: archive.h is for use outside of libarchive; the configuration
37 * headers (config.h, archive_platform.h, etc.) are purely internal.
38 * Do NOT use HAVE_XXX configuration macros to control the behavior of
39 * this header!  If you must conditionalize, use predefined compiler and/or
40 * platform macros.
41 */
42#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560
43# include <stdint.h>
44#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS)
45# include <inttypes.h>
46#endif
47
48/* Get appropriate definitions of standard POSIX-style types. */
49/* These should match the types used in 'struct stat' */
50#if defined(_WIN32) && !defined(__CYGWIN__)
51# define	__LA_INT64_T	__int64
52# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
53#  define	__LA_SSIZE_T	ssize_t
54# elif defined(_WIN64)
55#  define	__LA_SSIZE_T	__int64
56# else
57#  define	__LA_SSIZE_T	long
58# endif
59#else
60# include <unistd.h>  /* ssize_t */
61# if defined(_SCO_DS)
62#  define	__LA_INT64_T	long long
63# else
64#  define	__LA_INT64_T	int64_t
65# endif
66# define	__LA_SSIZE_T	ssize_t
67#endif
68
69/*
70 * On Windows, define LIBARCHIVE_STATIC if you're building or using a
71 * .lib.  The default here assumes you're building a DLL.  Only
72 * libarchive source should ever define __LIBARCHIVE_BUILD.
73 */
74#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
75# ifdef __LIBARCHIVE_BUILD
76#  ifdef __GNUC__
77#   define __LA_DECL	__attribute__((dllexport)) extern
78#  else
79#   define __LA_DECL	__declspec(dllexport)
80#  endif
81# else
82#  ifdef __GNUC__
83#   define __LA_DECL
84#  else
85#   define __LA_DECL	__declspec(dllimport)
86#  endif
87# endif
88#else
89/* Static libraries or non-Windows needs no special declaration. */
90# define __LA_DECL
91#endif
92
93#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__)
94#define	__LA_PRINTF(fmtarg, firstvararg) \
95	__attribute__((__format__ (__printf__, fmtarg, firstvararg)))
96#else
97#define	__LA_PRINTF(fmtarg, firstvararg)	/* nothing */
98#endif
99
100#ifdef __cplusplus
101extern "C" {
102#endif
103
104/*
105 * The version number is provided as both a macro and a function.
106 * The macro identifies the installed header; the function identifies
107 * the library version (which may not be the same if you're using a
108 * dynamically-linked version of the library).  Of course, if the
109 * header and library are very different, you should expect some
110 * strangeness.  Don't do that.
111 */
112
113/*
114 * The version number is expressed as a single integer that makes it
115 * easy to compare versions at build time: for version a.b.c, the
116 * version number is printf("%d%03d%03d",a,b,c).  For example, if you
117 * know your application requires version 2.12.108 or later, you can
118 * assert that ARCHIVE_VERSION_NUMBER >= 2012108.
119 */
120/* Note: Compiler will complain if this does not match archive_entry.h! */
121#define	ARCHIVE_VERSION_NUMBER 3000004
122__LA_DECL int		archive_version_number(void);
123
124/*
125 * Textual name/version of the library, useful for version displays.
126 */
127#define	ARCHIVE_VERSION_STRING "libarchive 3.0.4"
128__LA_DECL const char *	archive_version_string(void);
129
130/* Declare our basic types. */
131struct archive;
132struct archive_entry;
133
134/*
135 * Error codes: Use archive_errno() and archive_error_string()
136 * to retrieve details.  Unless specified otherwise, all functions
137 * that return 'int' use these codes.
138 */
139#define	ARCHIVE_EOF	  1	/* Found end of archive. */
140#define	ARCHIVE_OK	  0	/* Operation was successful. */
141#define	ARCHIVE_RETRY	(-10)	/* Retry might succeed. */
142#define	ARCHIVE_WARN	(-20)	/* Partial success. */
143/* For example, if write_header "fails", then you can't push data. */
144#define	ARCHIVE_FAILED	(-25)	/* Current operation cannot complete. */
145/* But if write_header is "fatal," then this archive is dead and useless. */
146#define	ARCHIVE_FATAL	(-30)	/* No more operations are possible. */
147
148/*
149 * As far as possible, archive_errno returns standard platform errno codes.
150 * Of course, the details vary by platform, so the actual definitions
151 * here are stored in "archive_platform.h".  The symbols are listed here
152 * for reference; as a rule, clients should not need to know the exact
153 * platform-dependent error code.
154 */
155/* Unrecognized or invalid file format. */
156/* #define	ARCHIVE_ERRNO_FILE_FORMAT */
157/* Illegal usage of the library. */
158/* #define	ARCHIVE_ERRNO_PROGRAMMER_ERROR */
159/* Unknown or unclassified error. */
160/* #define	ARCHIVE_ERRNO_MISC */
161
162/*
163 * Callbacks are invoked to automatically read/skip/write/open/close the
164 * archive. You can provide your own for complex tasks (like breaking
165 * archives across multiple tapes) or use standard ones built into the
166 * library.
167 */
168
169/* Returns pointer and size of next block of data from archive. */
170typedef __LA_SSIZE_T	archive_read_callback(struct archive *,
171			    void *_client_data, const void **_buffer);
172
173/* Skips at most request bytes from archive and returns the skipped amount.
174 * This may skip fewer bytes than requested; it may even skip zero bytes.
175 * If you do skip fewer bytes than requested, libarchive will invoke your
176 * read callback and discard data as necessary to make up the full skip.
177 */
178typedef __LA_INT64_T	archive_skip_callback(struct archive *,
179			    void *_client_data, __LA_INT64_T request);
180
181/* Seeks to specified location in the file and returns the position.
182 * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h.
183 * Return ARCHIVE_FATAL if the seek fails for any reason.
184 */
185typedef __LA_INT64_T	archive_seek_callback(struct archive *,
186    void *_client_data, __LA_INT64_T offset, int whence);
187
188/* Returns size actually written, zero on EOF, -1 on error. */
189typedef __LA_SSIZE_T	archive_write_callback(struct archive *,
190			    void *_client_data,
191			    const void *_buffer, size_t _length);
192
193typedef int	archive_open_callback(struct archive *, void *_client_data);
194
195typedef int	archive_close_callback(struct archive *, void *_client_data);
196
197/*
198 * Codes to identify various stream filters.
199 */
200#define	ARCHIVE_FILTER_NONE	0
201#define	ARCHIVE_FILTER_GZIP	1
202#define	ARCHIVE_FILTER_BZIP2	2
203#define	ARCHIVE_FILTER_COMPRESS	3
204#define	ARCHIVE_FILTER_PROGRAM	4
205#define	ARCHIVE_FILTER_LZMA	5
206#define	ARCHIVE_FILTER_XZ	6
207#define	ARCHIVE_FILTER_UU	7
208#define	ARCHIVE_FILTER_RPM	8
209#define	ARCHIVE_FILTER_LZIP	9
210
211#if ARCHIVE_VERSION_NUMBER < 4000000
212#define	ARCHIVE_COMPRESSION_NONE	ARCHIVE_FILTER_NONE
213#define	ARCHIVE_COMPRESSION_GZIP	ARCHIVE_FILTER_GZIP
214#define	ARCHIVE_COMPRESSION_BZIP2	ARCHIVE_FILTER_BZIP2
215#define	ARCHIVE_COMPRESSION_COMPRESS	ARCHIVE_FILTER_COMPRESS
216#define	ARCHIVE_COMPRESSION_PROGRAM	ARCHIVE_FILTER_PROGRAM
217#define	ARCHIVE_COMPRESSION_LZMA	ARCHIVE_FILTER_LZMA
218#define	ARCHIVE_COMPRESSION_XZ		ARCHIVE_FILTER_XZ
219#define	ARCHIVE_COMPRESSION_UU		ARCHIVE_FILTER_UU
220#define	ARCHIVE_COMPRESSION_RPM		ARCHIVE_FILTER_RPM
221#define	ARCHIVE_COMPRESSION_LZIP	ARCHIVE_FILTER_LZIP
222#endif
223
224/*
225 * Codes returned by archive_format.
226 *
227 * Top 16 bits identifies the format family (e.g., "tar"); lower
228 * 16 bits indicate the variant.  This is updated by read_next_header.
229 * Note that the lower 16 bits will often vary from entry to entry.
230 * In some cases, this variation occurs as libarchive learns more about
231 * the archive (for example, later entries might utilize extensions that
232 * weren't necessary earlier in the archive; in this case, libarchive
233 * will change the format code to indicate the extended format that
234 * was used).  In other cases, it's because different tools have
235 * modified the archive and so different parts of the archive
236 * actually have slightly different formats.  (Both tar and cpio store
237 * format codes in each entry, so it is quite possible for each
238 * entry to be in a different format.)
239 */
240#define	ARCHIVE_FORMAT_BASE_MASK		0xff0000
241#define	ARCHIVE_FORMAT_CPIO			0x10000
242#define	ARCHIVE_FORMAT_CPIO_POSIX		(ARCHIVE_FORMAT_CPIO | 1)
243#define	ARCHIVE_FORMAT_CPIO_BIN_LE		(ARCHIVE_FORMAT_CPIO | 2)
244#define	ARCHIVE_FORMAT_CPIO_BIN_BE		(ARCHIVE_FORMAT_CPIO | 3)
245#define	ARCHIVE_FORMAT_CPIO_SVR4_NOCRC		(ARCHIVE_FORMAT_CPIO | 4)
246#define	ARCHIVE_FORMAT_CPIO_SVR4_CRC		(ARCHIVE_FORMAT_CPIO | 5)
247#define	ARCHIVE_FORMAT_CPIO_AFIO_LARGE		(ARCHIVE_FORMAT_CPIO | 6)
248#define	ARCHIVE_FORMAT_SHAR			0x20000
249#define	ARCHIVE_FORMAT_SHAR_BASE		(ARCHIVE_FORMAT_SHAR | 1)
250#define	ARCHIVE_FORMAT_SHAR_DUMP		(ARCHIVE_FORMAT_SHAR | 2)
251#define	ARCHIVE_FORMAT_TAR			0x30000
252#define	ARCHIVE_FORMAT_TAR_USTAR		(ARCHIVE_FORMAT_TAR | 1)
253#define	ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE	(ARCHIVE_FORMAT_TAR | 2)
254#define	ARCHIVE_FORMAT_TAR_PAX_RESTRICTED	(ARCHIVE_FORMAT_TAR | 3)
255#define	ARCHIVE_FORMAT_TAR_GNUTAR		(ARCHIVE_FORMAT_TAR | 4)
256#define	ARCHIVE_FORMAT_ISO9660			0x40000
257#define	ARCHIVE_FORMAT_ISO9660_ROCKRIDGE	(ARCHIVE_FORMAT_ISO9660 | 1)
258#define	ARCHIVE_FORMAT_ZIP			0x50000
259#define	ARCHIVE_FORMAT_EMPTY			0x60000
260#define	ARCHIVE_FORMAT_AR			0x70000
261#define	ARCHIVE_FORMAT_AR_GNU			(ARCHIVE_FORMAT_AR | 1)
262#define	ARCHIVE_FORMAT_AR_BSD			(ARCHIVE_FORMAT_AR | 2)
263#define	ARCHIVE_FORMAT_MTREE			0x80000
264#define	ARCHIVE_FORMAT_RAW			0x90000
265#define	ARCHIVE_FORMAT_XAR			0xA0000
266#define	ARCHIVE_FORMAT_LHA			0xB0000
267#define	ARCHIVE_FORMAT_CAB			0xC0000
268#define	ARCHIVE_FORMAT_RAR			0xD0000
269#define	ARCHIVE_FORMAT_7ZIP			0xE0000
270
271/*-
272 * Basic outline for reading an archive:
273 *   1) Ask archive_read_new for an archive reader object.
274 *   2) Update any global properties as appropriate.
275 *      In particular, you'll certainly want to call appropriate
276 *      archive_read_support_XXX functions.
277 *   3) Call archive_read_open_XXX to open the archive
278 *   4) Repeatedly call archive_read_next_header to get information about
279 *      successive archive entries.  Call archive_read_data to extract
280 *      data for entries of interest.
281 *   5) Call archive_read_finish to end processing.
282 */
283__LA_DECL struct archive	*archive_read_new(void);
284
285/*
286 * The archive_read_support_XXX calls enable auto-detect for this
287 * archive handle.  They also link in the necessary support code.
288 * For example, if you don't want bzlib linked in, don't invoke
289 * support_compression_bzip2().  The "all" functions provide the
290 * obvious shorthand.
291 */
292
293#if ARCHIVE_VERSION_NUMBER < 4000000
294__LA_DECL int archive_read_support_compression_all(struct archive *);
295__LA_DECL int archive_read_support_compression_bzip2(struct archive *);
296__LA_DECL int archive_read_support_compression_compress(struct archive *);
297__LA_DECL int archive_read_support_compression_gzip(struct archive *);
298__LA_DECL int archive_read_support_compression_lzip(struct archive *);
299__LA_DECL int archive_read_support_compression_lzma(struct archive *);
300__LA_DECL int archive_read_support_compression_none(struct archive *);
301__LA_DECL int archive_read_support_compression_program(struct archive *,
302		     const char *command);
303__LA_DECL int archive_read_support_compression_program_signature
304		(struct archive *, const char *,
305				    const void * /* match */, size_t);
306
307__LA_DECL int archive_read_support_compression_rpm(struct archive *);
308__LA_DECL int archive_read_support_compression_uu(struct archive *);
309__LA_DECL int archive_read_support_compression_xz(struct archive *);
310#endif
311
312__LA_DECL int archive_read_support_filter_all(struct archive *);
313__LA_DECL int archive_read_support_filter_bzip2(struct archive *);
314__LA_DECL int archive_read_support_filter_compress(struct archive *);
315__LA_DECL int archive_read_support_filter_gzip(struct archive *);
316__LA_DECL int archive_read_support_filter_lzip(struct archive *);
317__LA_DECL int archive_read_support_filter_lzma(struct archive *);
318__LA_DECL int archive_read_support_filter_none(struct archive *);
319__LA_DECL int archive_read_support_filter_program(struct archive *,
320		     const char *command);
321__LA_DECL int archive_read_support_filter_program_signature
322		(struct archive *, const char *,
323				    const void * /* match */, size_t);
324
325__LA_DECL int archive_read_support_filter_rpm(struct archive *);
326__LA_DECL int archive_read_support_filter_uu(struct archive *);
327__LA_DECL int archive_read_support_filter_xz(struct archive *);
328
329__LA_DECL int archive_read_support_format_7zip(struct archive *);
330__LA_DECL int archive_read_support_format_all(struct archive *);
331__LA_DECL int archive_read_support_format_ar(struct archive *);
332__LA_DECL int archive_read_support_format_by_code(struct archive *, int);
333__LA_DECL int archive_read_support_format_cab(struct archive *);
334__LA_DECL int archive_read_support_format_cpio(struct archive *);
335__LA_DECL int archive_read_support_format_empty(struct archive *);
336__LA_DECL int archive_read_support_format_gnutar(struct archive *);
337__LA_DECL int archive_read_support_format_iso9660(struct archive *);
338__LA_DECL int archive_read_support_format_lha(struct archive *);
339__LA_DECL int archive_read_support_format_mtree(struct archive *);
340__LA_DECL int archive_read_support_format_rar(struct archive *);
341__LA_DECL int archive_read_support_format_raw(struct archive *);
342__LA_DECL int archive_read_support_format_tar(struct archive *);
343__LA_DECL int archive_read_support_format_xar(struct archive *);
344__LA_DECL int archive_read_support_format_zip(struct archive *);
345
346/* Set various callbacks. */
347__LA_DECL int archive_read_set_open_callback(struct archive *,
348    archive_open_callback *);
349__LA_DECL int archive_read_set_read_callback(struct archive *,
350    archive_read_callback *);
351__LA_DECL int archive_read_set_seek_callback(struct archive *,
352    archive_seek_callback *);
353__LA_DECL int archive_read_set_skip_callback(struct archive *,
354    archive_skip_callback *);
355__LA_DECL int archive_read_set_close_callback(struct archive *,
356    archive_close_callback *);
357/* The callback data is provided to all of the callbacks above. */
358__LA_DECL int archive_read_set_callback_data(struct archive *, void *);
359/* Opening freezes the callbacks. */
360__LA_DECL int archive_read_open1(struct archive *);
361
362/* Convenience wrappers around the above. */
363__LA_DECL int archive_read_open(struct archive *, void *_client_data,
364		     archive_open_callback *, archive_read_callback *,
365		     archive_close_callback *);
366__LA_DECL int archive_read_open2(struct archive *, void *_client_data,
367		     archive_open_callback *, archive_read_callback *,
368		     archive_skip_callback *, archive_close_callback *);
369
370/*
371 * A variety of shortcuts that invoke archive_read_open() with
372 * canned callbacks suitable for common situations.  The ones that
373 * accept a block size handle tape blocking correctly.
374 */
375/* Use this if you know the filename.  Note: NULL indicates stdin. */
376__LA_DECL int archive_read_open_filename(struct archive *,
377		     const char *_filename, size_t _block_size);
378__LA_DECL int archive_read_open_filename_w(struct archive *,
379		     const wchar_t *_filename, size_t _block_size);
380/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
381__LA_DECL int archive_read_open_file(struct archive *,
382		     const char *_filename, size_t _block_size);
383/* Read an archive that's stored in memory. */
384__LA_DECL int archive_read_open_memory(struct archive *,
385		     void * buff, size_t size);
386/* A more involved version that is only used for internal testing. */
387__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff,
388		     size_t size, size_t read_size);
389/* Read an archive that's already open, using the file descriptor. */
390__LA_DECL int archive_read_open_fd(struct archive *, int _fd,
391		     size_t _block_size);
392/* Read an archive that's already open, using a FILE *. */
393/* Note: DO NOT use this with tape drives. */
394__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file);
395
396/* Parses and returns next entry header. */
397__LA_DECL int archive_read_next_header(struct archive *,
398		     struct archive_entry **);
399
400/* Parses and returns next entry header using the archive_entry passed in */
401__LA_DECL int archive_read_next_header2(struct archive *,
402		     struct archive_entry *);
403
404/*
405 * Retrieve the byte offset in UNCOMPRESSED data where last-read
406 * header started.
407 */
408__LA_DECL __LA_INT64_T		 archive_read_header_position(struct archive *);
409
410/* Read data from the body of an entry.  Similar to read(2). */
411__LA_DECL __LA_SSIZE_T		 archive_read_data(struct archive *,
412				    void *, size_t);
413
414/*
415 * A zero-copy version of archive_read_data that also exposes the file offset
416 * of each returned block.  Note that the client has no way to specify
417 * the desired size of the block.  The API does guarantee that offsets will
418 * be strictly increasing and that returned blocks will not overlap.
419 */
420__LA_DECL int archive_read_data_block(struct archive *a,
421		    const void **buff, size_t *size, __LA_INT64_T *offset);
422
423/*-
424 * Some convenience functions that are built on archive_read_data:
425 *  'skip': skips entire entry
426 *  'into_buffer': writes data into memory buffer that you provide
427 *  'into_fd': writes data to specified filedes
428 */
429__LA_DECL int archive_read_data_skip(struct archive *);
430__LA_DECL int archive_read_data_into_fd(struct archive *, int fd);
431
432/*
433 * Set read options.
434 */
435/* Apply option to the format only. */
436__LA_DECL int archive_read_set_format_option(struct archive *_a,
437			    const char *m, const char *o,
438			    const char *v);
439/* Apply option to the filter only. */
440__LA_DECL int archive_read_set_filter_option(struct archive *_a,
441			    const char *m, const char *o,
442			    const char *v);
443/* Apply option to both the format and the filter. */
444__LA_DECL int archive_read_set_option(struct archive *_a,
445			    const char *m, const char *o,
446			    const char *v);
447/* Apply option string to both the format and the filter. */
448__LA_DECL int archive_read_set_options(struct archive *_a,
449			    const char *opts);
450
451/*-
452 * Convenience function to recreate the current entry (whose header
453 * has just been read) on disk.
454 *
455 * This does quite a bit more than just copy data to disk. It also:
456 *  - Creates intermediate directories as required.
457 *  - Manages directory permissions:  non-writable directories will
458 *    be initially created with write permission enabled; when the
459 *    archive is closed, dir permissions are edited to the values specified
460 *    in the archive.
461 *  - Checks hardlinks:  hardlinks will not be extracted unless the
462 *    linked-to file was also extracted within the same session. (TODO)
463 */
464
465/* The "flags" argument selects optional behavior, 'OR' the flags you want. */
466
467/* Default: Do not try to set owner/group. */
468#define	ARCHIVE_EXTRACT_OWNER			(0x0001)
469/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
470#define	ARCHIVE_EXTRACT_PERM			(0x0002)
471/* Default: Do not restore mtime/atime. */
472#define	ARCHIVE_EXTRACT_TIME			(0x0004)
473/* Default: Replace existing files. */
474#define	ARCHIVE_EXTRACT_NO_OVERWRITE 		(0x0008)
475/* Default: Try create first, unlink only if create fails with EEXIST. */
476#define	ARCHIVE_EXTRACT_UNLINK			(0x0010)
477/* Default: Do not restore ACLs. */
478#define	ARCHIVE_EXTRACT_ACL			(0x0020)
479/* Default: Do not restore fflags. */
480#define	ARCHIVE_EXTRACT_FFLAGS			(0x0040)
481/* Default: Do not restore xattrs. */
482#define	ARCHIVE_EXTRACT_XATTR 			(0x0080)
483/* Default: Do not try to guard against extracts redirected by symlinks. */
484/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
485#define	ARCHIVE_EXTRACT_SECURE_SYMLINKS		(0x0100)
486/* Default: Do not reject entries with '..' as path elements. */
487#define	ARCHIVE_EXTRACT_SECURE_NODOTDOT		(0x0200)
488/* Default: Create parent directories as needed. */
489#define	ARCHIVE_EXTRACT_NO_AUTODIR		(0x0400)
490/* Default: Overwrite files, even if one on disk is newer. */
491#define	ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER	(0x0800)
492/* Detect blocks of 0 and write holes instead. */
493#define	ARCHIVE_EXTRACT_SPARSE			(0x1000)
494/* Default: Do not restore Mac extended metadata. */
495/* This has no effect except on Mac OS. */
496#define	ARCHIVE_EXTRACT_MAC_METADATA		(0x2000)
497
498__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *,
499		     int flags);
500__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *,
501		     struct archive * /* dest */);
502__LA_DECL void	 archive_read_extract_set_progress_callback(struct archive *,
503		     void (*_progress_func)(void *), void *_user_data);
504
505/* Record the dev/ino of a file that will not be written.  This is
506 * generally set to the dev/ino of the archive being read. */
507__LA_DECL void		archive_read_extract_set_skip_file(struct archive *,
508		     __LA_INT64_T, __LA_INT64_T);
509
510/* Close the file and release most resources. */
511__LA_DECL int		 archive_read_close(struct archive *);
512/* Release all resources and destroy the object. */
513/* Note that archive_read_free will call archive_read_close for you. */
514__LA_DECL int		 archive_read_free(struct archive *);
515#if ARCHIVE_VERSION_NUMBER < 4000000
516/* Synonym for archive_read_free() for backwards compatibility. */
517__LA_DECL int		 archive_read_finish(struct archive *);
518#endif
519
520/*-
521 * To create an archive:
522 *   1) Ask archive_write_new for an archive writer object.
523 *   2) Set any global properties.  In particular, you should set
524 *      the compression and format to use.
525 *   3) Call archive_write_open to open the file (most people
526 *       will use archive_write_open_file or archive_write_open_fd,
527 *       which provide convenient canned I/O callbacks for you).
528 *   4) For each entry:
529 *      - construct an appropriate struct archive_entry structure
530 *      - archive_write_header to write the header
531 *      - archive_write_data to write the entry data
532 *   5) archive_write_close to close the output
533 *   6) archive_write_free to cleanup the writer and release resources
534 */
535__LA_DECL struct archive	*archive_write_new(void);
536__LA_DECL int archive_write_set_bytes_per_block(struct archive *,
537		     int bytes_per_block);
538__LA_DECL int archive_write_get_bytes_per_block(struct archive *);
539/* XXX This is badly misnamed; suggestions appreciated. XXX */
540__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *,
541		     int bytes_in_last_block);
542__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *);
543
544/* The dev/ino of a file that won't be archived.  This is used
545 * to avoid recursively adding an archive to itself. */
546__LA_DECL int archive_write_set_skip_file(struct archive *,
547    __LA_INT64_T, __LA_INT64_T);
548
549#if ARCHIVE_VERSION_NUMBER < 4000000
550__LA_DECL int archive_write_set_compression_bzip2(struct archive *);
551__LA_DECL int archive_write_set_compression_compress(struct archive *);
552__LA_DECL int archive_write_set_compression_gzip(struct archive *);
553__LA_DECL int archive_write_set_compression_lzip(struct archive *);
554__LA_DECL int archive_write_set_compression_lzma(struct archive *);
555__LA_DECL int archive_write_set_compression_none(struct archive *);
556__LA_DECL int archive_write_set_compression_program(struct archive *,
557		     const char *cmd);
558__LA_DECL int archive_write_set_compression_xz(struct archive *);
559#endif
560
561/* A convenience function to set the filter based on the code. */
562__LA_DECL int archive_write_add_filter(struct archive *, int filter_code);
563__LA_DECL int archive_write_add_filter_bzip2(struct archive *);
564__LA_DECL int archive_write_add_filter_compress(struct archive *);
565__LA_DECL int archive_write_add_filter_gzip(struct archive *);
566__LA_DECL int archive_write_add_filter_lzip(struct archive *);
567__LA_DECL int archive_write_add_filter_lzma(struct archive *);
568__LA_DECL int archive_write_add_filter_none(struct archive *);
569__LA_DECL int archive_write_add_filter_program(struct archive *,
570		     const char *cmd);
571__LA_DECL int archive_write_add_filter_xz(struct archive *);
572
573
574/* A convenience function to set the format based on the code or name. */
575__LA_DECL int archive_write_set_format(struct archive *, int format_code);
576__LA_DECL int archive_write_set_format_by_name(struct archive *,
577		     const char *name);
578/* To minimize link pollution, use one or more of the following. */
579__LA_DECL int archive_write_set_format_7zip(struct archive *);
580__LA_DECL int archive_write_set_format_ar_bsd(struct archive *);
581__LA_DECL int archive_write_set_format_ar_svr4(struct archive *);
582__LA_DECL int archive_write_set_format_cpio(struct archive *);
583__LA_DECL int archive_write_set_format_cpio_newc(struct archive *);
584__LA_DECL int archive_write_set_format_gnutar(struct archive *);
585__LA_DECL int archive_write_set_format_iso9660(struct archive *);
586__LA_DECL int archive_write_set_format_mtree(struct archive *);
587/* TODO: int archive_write_set_format_old_tar(struct archive *); */
588__LA_DECL int archive_write_set_format_pax(struct archive *);
589__LA_DECL int archive_write_set_format_pax_restricted(struct archive *);
590__LA_DECL int archive_write_set_format_shar(struct archive *);
591__LA_DECL int archive_write_set_format_shar_dump(struct archive *);
592__LA_DECL int archive_write_set_format_ustar(struct archive *);
593__LA_DECL int archive_write_set_format_xar(struct archive *);
594__LA_DECL int archive_write_set_format_zip(struct archive *);
595__LA_DECL int archive_write_open(struct archive *, void *,
596		     archive_open_callback *, archive_write_callback *,
597		     archive_close_callback *);
598__LA_DECL int archive_write_open_fd(struct archive *, int _fd);
599__LA_DECL int archive_write_open_filename(struct archive *, const char *_file);
600__LA_DECL int archive_write_open_filename_w(struct archive *,
601		     const wchar_t *_file);
602/* A deprecated synonym for archive_write_open_filename() */
603__LA_DECL int archive_write_open_file(struct archive *, const char *_file);
604__LA_DECL int archive_write_open_FILE(struct archive *, FILE *);
605/* _buffSize is the size of the buffer, _used refers to a variable that
606 * will be updated after each write into the buffer. */
607__LA_DECL int archive_write_open_memory(struct archive *,
608			void *_buffer, size_t _buffSize, size_t *_used);
609
610/*
611 * Note that the library will truncate writes beyond the size provided
612 * to archive_write_header or pad if the provided data is short.
613 */
614__LA_DECL int archive_write_header(struct archive *,
615		     struct archive_entry *);
616__LA_DECL __LA_SSIZE_T	archive_write_data(struct archive *,
617			    const void *, size_t);
618
619/* This interface is currently only available for archive_write_disk handles.  */
620__LA_DECL __LA_SSIZE_T	 archive_write_data_block(struct archive *,
621				    const void *, size_t, __LA_INT64_T);
622
623__LA_DECL int		 archive_write_finish_entry(struct archive *);
624__LA_DECL int		 archive_write_close(struct archive *);
625/* This can fail if the archive wasn't already closed, in which case
626 * archive_write_free() will implicitly call archive_write_close(). */
627__LA_DECL int		 archive_write_free(struct archive *);
628#if ARCHIVE_VERSION_NUMBER < 4000000
629/* Synonym for archive_write_free() for backwards compatibility. */
630__LA_DECL int		 archive_write_finish(struct archive *);
631#endif
632
633/*
634 * Set write options.
635 */
636/* Apply option to the format only. */
637__LA_DECL int archive_write_set_format_option(struct archive *_a,
638			    const char *m, const char *o,
639			    const char *v);
640/* Apply option to the filter only. */
641__LA_DECL int archive_write_set_filter_option(struct archive *_a,
642			    const char *m, const char *o,
643			    const char *v);
644/* Apply option to both the format and the filter. */
645__LA_DECL int archive_write_set_option(struct archive *_a,
646			    const char *m, const char *o,
647			    const char *v);
648/* Apply option string to both the format and the filter. */
649__LA_DECL int archive_write_set_options(struct archive *_a,
650			    const char *opts);
651
652/*-
653 * ARCHIVE_WRITE_DISK API
654 *
655 * To create objects on disk:
656 *   1) Ask archive_write_disk_new for a new archive_write_disk object.
657 *   2) Set any global properties.  In particular, you probably
658 *      want to set the options.
659 *   3) For each entry:
660 *      - construct an appropriate struct archive_entry structure
661 *      - archive_write_header to create the file/dir/etc on disk
662 *      - archive_write_data to write the entry data
663 *   4) archive_write_free to cleanup the writer and release resources
664 *
665 * In particular, you can use this in conjunction with archive_read()
666 * to pull entries out of an archive and create them on disk.
667 */
668__LA_DECL struct archive	*archive_write_disk_new(void);
669/* This file will not be overwritten. */
670__LA_DECL int archive_write_disk_set_skip_file(struct archive *,
671    __LA_INT64_T, __LA_INT64_T);
672/* Set flags to control how the next item gets created.
673 * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
674__LA_DECL int		 archive_write_disk_set_options(struct archive *,
675		     int flags);
676/*
677 * The lookup functions are given uname/uid (or gname/gid) pairs and
678 * return a uid (gid) suitable for this system.  These are used for
679 * restoring ownership and for setting ACLs.  The default functions
680 * are naive, they just return the uid/gid.  These are small, so reasonable
681 * for applications that don't need to preserve ownership; they
682 * are probably also appropriate for applications that are doing
683 * same-system backup and restore.
684 */
685/*
686 * The "standard" lookup functions use common system calls to lookup
687 * the uname/gname, falling back to the uid/gid if the names can't be
688 * found.  They cache lookups and are reasonably fast, but can be very
689 * large, so they are not used unless you ask for them.  In
690 * particular, these match the specifications of POSIX "pax" and old
691 * POSIX "tar".
692 */
693__LA_DECL int	 archive_write_disk_set_standard_lookup(struct archive *);
694/*
695 * If neither the default (naive) nor the standard (big) functions suit
696 * your needs, you can write your own and register them.  Be sure to
697 * include a cleanup function if you have allocated private data.
698 */
699__LA_DECL int archive_write_disk_set_group_lookup(struct archive *,
700    void * /* private_data */,
701    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
702    void (* /* cleanup */)(void *));
703__LA_DECL int archive_write_disk_set_user_lookup(struct archive *,
704    void * /* private_data */,
705    __LA_INT64_T (*)(void *, const char *, __LA_INT64_T),
706    void (* /* cleanup */)(void *));
707__LA_DECL __LA_INT64_T archive_write_disk_gid(struct archive *, const char *, __LA_INT64_T);
708__LA_DECL __LA_INT64_T archive_write_disk_uid(struct archive *, const char *, __LA_INT64_T);
709
710/*
711 * ARCHIVE_READ_DISK API
712 *
713 * This is still evolving and somewhat experimental.
714 */
715__LA_DECL struct archive *archive_read_disk_new(void);
716/* The names for symlink modes here correspond to an old BSD
717 * command-line argument convention: -L, -P, -H */
718/* Follow all symlinks. */
719__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
720/* Follow no symlinks. */
721__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
722/* Follow symlink initially, then not. */
723__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
724/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
725__LA_DECL int archive_read_disk_entry_from_file(struct archive *,
726    struct archive_entry *, int /* fd */, const struct stat *);
727/* Look up gname for gid or uname for uid. */
728/* Default implementations are very, very stupid. */
729__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_INT64_T);
730__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_INT64_T);
731/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
732 * results for performance. */
733__LA_DECL int	archive_read_disk_set_standard_lookup(struct archive *);
734/* You can install your own lookups if you like. */
735__LA_DECL int	archive_read_disk_set_gname_lookup(struct archive *,
736    void * /* private_data */,
737    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
738    void (* /* cleanup_fn */)(void *));
739__LA_DECL int	archive_read_disk_set_uname_lookup(struct archive *,
740    void * /* private_data */,
741    const char *(* /* lookup_fn */)(void *, __LA_INT64_T),
742    void (* /* cleanup_fn */)(void *));
743/* Start traversal. */
744__LA_DECL int	archive_read_disk_open(struct archive *, const char *);
745__LA_DECL int	archive_read_disk_open_w(struct archive *, const wchar_t *);
746/*
747 * Request that current entry be visited.  If you invoke it on every
748 * directory, you'll get a physical traversal.  This is ignored if the
749 * current entry isn't a directory or a link to a directory.  So, if
750 * you invoke this on every returned path, you'll get a full logical
751 * traversal.
752 */
753__LA_DECL int	archive_read_disk_descend(struct archive *);
754__LA_DECL int	archive_read_disk_can_descend(struct archive *);
755__LA_DECL int	archive_read_disk_current_filesystem(struct archive *);
756__LA_DECL int	archive_read_disk_current_filesystem_is_synthetic(struct archive *);
757__LA_DECL int	archive_read_disk_current_filesystem_is_remote(struct archive *);
758/* Request that the access time of the entry visited by travesal be restored. */
759__LA_DECL int  archive_read_disk_set_atime_restored(struct archive *);
760/*
761 * Set behavior. The "flags" argument selects optional behavior.
762 */
763/* Request that the access time of the entry visited by travesal be restored.
764 * This is the same as archive_read_disk_set_atime_restored. */
765#define	ARCHIVE_READDISK_RESTORE_ATIME		(0x0001)
766/* Default: Do not skip an entry which has nodump flags. */
767#define	ARCHIVE_READDISK_HONOR_NODUMP		(0x0002)
768/* Default: Skip a mac resource fork file whose prefix is "._" because of
769 * using copyfile. */
770#define	ARCHIVE_READDISK_MAC_COPYFILE		(0x0004)
771/* Default: Do not traverse mount points. */
772#define	ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS	(0x0008)
773
774__LA_DECL int  archive_read_disk_set_behavior(struct archive *,
775		    int flags);
776
777/*
778 * Set archive_match object that will be used in archive_read_disk to
779 * know whether an entry should be skipped. The callback function
780 * _excluded_func will be invoked when an entry is skipped by the result
781 * of archive_match.
782 */
783__LA_DECL int	archive_read_disk_set_matching(struct archive *,
784		    struct archive *_matching, void (*_excluded_func)
785		    (struct archive *, void *, struct archive_entry *),
786		    void *_client_data);
787__LA_DECL int	archive_read_disk_set_metadata_filter_callback(struct archive *,
788		    int (*_metadata_filter_func)(struct archive *, void *,
789		    	struct archive_entry *), void *_client_data);
790
791/*
792 * Accessor functions to read/set various information in
793 * the struct archive object:
794 */
795
796/* Number of filters in the current filter pipeline. */
797/* Filter #0 is the one closest to the format, -1 is a synonym for the
798 * last filter, which is always the pseudo-filter that wraps the
799 * client callbacks. */
800__LA_DECL int		 archive_filter_count(struct archive *);
801__LA_DECL __LA_INT64_T	 archive_filter_bytes(struct archive *, int);
802__LA_DECL int		 archive_filter_code(struct archive *, int);
803__LA_DECL const char *	 archive_filter_name(struct archive *, int);
804
805#if ARCHIVE_VERSION_NUMBER < 4000000
806/* These don't properly handle multiple filters, so are deprecated and
807 * will eventually be removed. */
808/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */
809__LA_DECL __LA_INT64_T	 archive_position_compressed(struct archive *);
810/* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */
811__LA_DECL __LA_INT64_T	 archive_position_uncompressed(struct archive *);
812/* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */
813__LA_DECL const char	*archive_compression_name(struct archive *);
814/* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */
815__LA_DECL int		 archive_compression(struct archive *);
816#endif
817
818__LA_DECL int		 archive_errno(struct archive *);
819__LA_DECL const char	*archive_error_string(struct archive *);
820__LA_DECL const char	*archive_format_name(struct archive *);
821__LA_DECL int		 archive_format(struct archive *);
822__LA_DECL void		 archive_clear_error(struct archive *);
823__LA_DECL void		 archive_set_error(struct archive *, int _err,
824			    const char *fmt, ...) __LA_PRINTF(3, 4);
825__LA_DECL void		 archive_copy_error(struct archive *dest,
826			    struct archive *src);
827__LA_DECL int		 archive_file_count(struct archive *);
828
829/*
830 * ARCHIVE_MATCH API
831 */
832__LA_DECL struct archive *archive_match_new(void);
833__LA_DECL int	archive_match_free(struct archive *);
834
835/*
836 * Test if archive_entry is excluded.
837 * This is a convenience function. This is the same as calling all
838 * archive_match_path_excluded, archive_match_time_excluded
839 * and archive_match_owner_excluded.
840 */
841__LA_DECL int	archive_match_excluded(struct archive *,
842		    struct archive_entry *);
843
844/*
845 * Test if pathname is excluded. The conditions are set by following functions.
846 */
847__LA_DECL int	archive_match_path_excluded(struct archive *,
848		    struct archive_entry *);
849/* Add exclusion pathname pattern. */
850__LA_DECL int	archive_match_exclude_pattern(struct archive *, const char *);
851__LA_DECL int	archive_match_exclude_pattern_w(struct archive *,
852		    const wchar_t *);
853/* Add exclusion pathname pattern from file. */
854__LA_DECL int	archive_match_exclude_pattern_from_file(struct archive *,
855		    const char *, int _nullSeparator);
856__LA_DECL int	archive_match_exclude_pattern_from_file_w(struct archive *,
857		    const wchar_t *, int _nullSeparator);
858/* Add inclusion pathname pattern. */
859__LA_DECL int	archive_match_include_pattern(struct archive *, const char *);
860__LA_DECL int	archive_match_include_pattern_w(struct archive *,
861		    const wchar_t *);
862/* Add inclusion pathname pattern from file. */
863__LA_DECL int	archive_match_include_pattern_from_file(struct archive *,
864		    const char *, int _nullSeparator);
865__LA_DECL int	archive_match_include_pattern_from_file_w(struct archive *,
866		    const wchar_t *, int _nullSeparator);
867/*
868 * How to get statistic information for inclusion patterns.
869 */
870/* Return the amount number of unmatched inclusion patterns. */
871__LA_DECL int	archive_match_path_unmatched_inclusions(struct archive *);
872/* Return the pattern of unmatched inclusion with ARCHIVE_OK.
873 * Return ARCHIVE_EOF if there is no inclusion pattern. */
874__LA_DECL int	archive_match_path_unmatched_inclusions_next(
875		    struct archive *, const char **);
876__LA_DECL int	archive_match_path_unmatched_inclusions_next_w(
877		    struct archive *, const wchar_t **);
878
879/*
880 * Test if a file is excluded by its time stamp.
881 * The conditions are set by following functions.
882 */
883__LA_DECL int	archive_match_time_excluded(struct archive *,
884		    struct archive_entry *);
885
886/*
887 * Flags to tell a matching type of time stamps. These are used for
888 * following functinos.
889 */
890/* Time flag: mtime to be tested. */
891#define ARCHIVE_MATCH_MTIME	(0x0100)
892/* Time flag: ctime to be tested. */
893#define ARCHIVE_MATCH_CTIME	(0x0200)
894/* Comparison flag: Match the time if it is newer than. */
895#define ARCHIVE_MATCH_NEWER	(0x0001)
896/* Comparison flag: Match the time if it is older than. */
897#define ARCHIVE_MATCH_OLDER	(0x0002)
898/* Comparison flag: Match the time if it is equal to. */
899#define ARCHIVE_MATCH_EQUAL	(0x0010)
900/* Set inclusion time. */
901__LA_DECL int	archive_match_include_time(struct archive *, int _flag,
902		    time_t _sec, long _nsec);
903/* Set inclusion time by a date string. */
904__LA_DECL int	archive_match_include_date(struct archive *, int _flag,
905		    const char *_datestr);
906__LA_DECL int	archive_match_include_date_w(struct archive *, int _flag,
907		    const wchar_t *_datestr);
908/* Set inclusion time by a particluar file. */
909__LA_DECL int	archive_match_include_file_time(struct archive *,
910		    int _flag, const char *_pathname);
911__LA_DECL int	archive_match_include_file_time_w(struct archive *,
912		    int _flag, const wchar_t *_pathname);
913/* Add exclusion entry. */
914__LA_DECL int	archive_match_exclude_entry(struct archive *,
915		    int _flag, struct archive_entry *);
916
917/*
918 * Test if a file is excluded by its uid ,gid, uname or gname.
919 * The conditions are set by following functions.
920 */
921__LA_DECL int	archive_match_owner_excluded(struct archive *,
922		    struct archive_entry *);
923/* Add inclusion uid, gid, uname and gname. */
924__LA_DECL int	archive_match_include_uid(struct archive *, __LA_INT64_T);
925__LA_DECL int	archive_match_include_gid(struct archive *, __LA_INT64_T);
926__LA_DECL int	archive_match_include_uname(struct archive *, const char *);
927__LA_DECL int	archive_match_include_uname_w(struct archive *,
928		    const wchar_t *);
929__LA_DECL int	archive_match_include_gname(struct archive *, const char *);
930__LA_DECL int	archive_match_include_gname_w(struct archive *,
931		    const wchar_t *);
932
933#ifdef __cplusplus
934}
935#endif
936
937/* These are meaningless outside of this header. */
938#undef __LA_DECL
939
940/* These need to remain defined because they're used in the
941 * callback type definitions.  XXX Fix this.  This is ugly. XXX */
942/* #undef __LA_INT64_T */
943/* #undef __LA_SSIZE_T */
944
945#endif /* !ARCHIVE_H_INCLUDED */
946