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