]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libarchive/archive.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libarchive / archive.h
1 /*-
2  * Copyright (c) 2003-2007 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$
26  */
27
28 #ifndef ARCHIVE_H_INCLUDED
29 #define ARCHIVE_H_INCLUDED
30
31 /*
32  * Note: archive.h is for use outside of libarchive; the configuration
33  * headers (config.h, archive_platform.h, etc.) are purely internal.
34  * Do NOT use HAVE_XXX configuration macros to control the behavior of
35  * this header!  If you must conditionalize, use predefined compiler and/or
36  * platform macros.
37  */
38
39 #include <sys/stat.h>
40 #include <sys/types.h>  /* Linux requires this for off_t */
41 #if !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX)
42 /* Header unavailable on Watcom C or MS Visual C++ or SFU. */
43 #include <inttypes.h> /* int64_t, etc. */
44 #endif
45 #include <stdio.h> /* For FILE * */
46
47 /* Get appropriate definitions of standard POSIX-style types. */
48 /* These should match the types used in 'struct stat' */
49 #if defined(_WIN32) && !defined(__CYGWIN__)
50 #define __LA_INT64_T    __int64
51 # if    defined(_WIN64)
52 #  define       __LA_SSIZE_T    __int64
53 # else
54 #  define       __LA_SSIZE_T    long
55 # endif
56 #define __LA_UID_T      unsigned int
57 #define __LA_GID_T      unsigned int
58 #else
59 #include <unistd.h>  /* ssize_t, uid_t, and gid_t */
60 #define __LA_INT64_T    int64_t
61 #define __LA_SSIZE_T    ssize_t
62 #define __LA_UID_T      uid_t
63 #define __LA_GID_T      gid_t
64 #endif
65
66 /*
67  * On Windows, define LIBARCHIVE_STATIC if you're building or using a
68  * .lib.  The default here assumes you're building a DLL.  Only
69  * libarchive source should ever define __LIBARCHIVE_BUILD.
70  */
71 #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
72 # ifdef __LIBARCHIVE_BUILD
73 #  ifdef __GNUC__
74 #   define __LA_DECL    __attribute__((dllexport)) extern
75 #  else
76 #   define __LA_DECL    __declspec(dllexport)
77 #  endif
78 # else
79 #  ifdef __GNUC__
80 #   define __LA_DECL    __attribute__((dllimport)) extern
81 #  else
82 #   define __LA_DECL    __declspec(dllimport)
83 #  endif
84 # endif
85 #else
86 /* Static libraries or non-Windows needs no special declaration. */
87 # define __LA_DECL
88 #endif
89
90 #ifdef __cplusplus
91 extern "C" {
92 #endif
93
94 /*
95  * The version number is provided as both a macro and a function.
96  * The macro identifies the installed header; the function identifies
97  * the library version (which may not be the same if you're using a
98  * dynamically-linked version of the library).  Of course, if the
99  * header and library are very different, you should expect some
100  * strangeness.  Don't do that.
101  */
102
103 /*
104  * The version number is expressed as a single integer that makes it
105  * easy to compare versions at build time: for version a.b.c, the
106  * version number is printf("%d%03d%03d",a,b,c).  For example, if you
107  * know your application requires version 2.12.108 or later, you can
108  * assert that ARCHIVE_VERSION >= 2012108.
109  *
110  * This single-number format was introduced with libarchive 1.9.0 in
111  * the libarchive 1.x family and libarchive 2.2.4 in the libarchive
112  * 2.x family.  The following may be useful if you really want to do
113  * feature detection for earlier libarchive versions (which defined
114  * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead):
115  *
116  * #ifndef ARCHIVE_VERSION_NUMBER
117  * #define ARCHIVE_VERSION_NUMBER       \
118  *             (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000)
119  * #endif
120  */
121 #define ARCHIVE_VERSION_NUMBER 2007000
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 2.7.0"
128 __LA_DECL const char *  archive_version_string(void);
129
130 #if ARCHIVE_VERSION_NUMBER < 3000000
131 /*
132  * Deprecated; these are older names that will be removed in favor of
133  * the simpler definitions above.
134  */
135 #define ARCHIVE_VERSION_STAMP   ARCHIVE_VERSION_NUMBER
136 __LA_DECL int           archive_version_stamp(void);
137 #define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING
138 __LA_DECL const char *  archive_version(void);
139 #define ARCHIVE_API_VERSION     (ARCHIVE_VERSION_NUMBER / 1000000)
140 __LA_DECL int           archive_api_version(void);
141 #define ARCHIVE_API_FEATURE     ((ARCHIVE_VERSION_NUMBER / 1000) % 1000)
142 __LA_DECL int           archive_api_feature(void);
143 #endif
144
145 #if ARCHIVE_VERSION_NUMBER < 3000000
146 /* This should never have been here in the first place. */
147 /* Legacy of old tar assumptions, will be removed in libarchive 3.0. */
148 #define ARCHIVE_BYTES_PER_RECORD          512
149 #define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240
150 #endif
151
152 /* Declare our basic types. */
153 struct archive;
154 struct archive_entry;
155
156 /*
157  * Error codes: Use archive_errno() and archive_error_string()
158  * to retrieve details.  Unless specified otherwise, all functions
159  * that return 'int' use these codes.
160  */
161 #define ARCHIVE_EOF       1     /* Found end of archive. */
162 #define ARCHIVE_OK        0     /* Operation was successful. */
163 #define ARCHIVE_RETRY   (-10)   /* Retry might succeed. */
164 #define ARCHIVE_WARN    (-20)   /* Partial success. */
165 /* For example, if write_header "fails", then you can't push data. */
166 #define ARCHIVE_FAILED  (-25)   /* Current operation cannot complete. */
167 /* But if write_header is "fatal," then this archive is dead and useless. */
168 #define ARCHIVE_FATAL   (-30)   /* No more operations are possible. */
169
170 /*
171  * As far as possible, archive_errno returns standard platform errno codes.
172  * Of course, the details vary by platform, so the actual definitions
173  * here are stored in "archive_platform.h".  The symbols are listed here
174  * for reference; as a rule, clients should not need to know the exact
175  * platform-dependent error code.
176  */
177 /* Unrecognized or invalid file format. */
178 /* #define      ARCHIVE_ERRNO_FILE_FORMAT */
179 /* Illegal usage of the library. */
180 /* #define      ARCHIVE_ERRNO_PROGRAMMER_ERROR */
181 /* Unknown or unclassified error. */
182 /* #define      ARCHIVE_ERRNO_MISC */
183
184 /*
185  * Callbacks are invoked to automatically read/skip/write/open/close the
186  * archive. You can provide your own for complex tasks (like breaking
187  * archives across multiple tapes) or use standard ones built into the
188  * library.
189  */
190
191 /* Returns pointer and size of next block of data from archive. */
192 typedef __LA_SSIZE_T    archive_read_callback(struct archive *,
193                             void *_client_data, const void **_buffer);
194
195 /* Skips at most request bytes from archive and returns the skipped amount */
196 #if ARCHIVE_VERSION_NUMBER < 2000000
197 /* Libarchive 1.0 used ssize_t for the return, which is only 32 bits
198  * on most 32-bit platforms; not large enough. */
199 typedef __LA_SSIZE_T    archive_skip_callback(struct archive *,
200                             void *_client_data, size_t request);
201 #elif ARCHIVE_VERSION_NUMBER < 3000000
202 /* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a
203  * few other platforms where off_t varies with build settings. */
204 typedef off_t           archive_skip_callback(struct archive *,
205                             void *_client_data, off_t request);
206 #else
207 /* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be
208  * 64 bits on every platform. */
209 typedef __LA_INT64_T    archive_skip_callback(struct archive *,
210                             void *_client_data, __LA_INT64_T request);
211 #endif
212
213 /* Returns size actually written, zero on EOF, -1 on error. */
214 typedef __LA_SSIZE_T    archive_write_callback(struct archive *,
215                             void *_client_data,
216                             const void *_buffer, size_t _length);
217
218 #if ARCHIVE_VERSION_NUMBER < 3000000
219 /* Open callback is actually never needed; remove it in libarchive 3.0. */
220 typedef int     archive_open_callback(struct archive *, void *_client_data);
221 #endif
222
223 typedef int     archive_close_callback(struct archive *, void *_client_data);
224
225 /*
226  * Codes for archive_compression.
227  */
228 #define ARCHIVE_COMPRESSION_NONE        0
229 #define ARCHIVE_COMPRESSION_GZIP        1
230 #define ARCHIVE_COMPRESSION_BZIP2       2
231 #define ARCHIVE_COMPRESSION_COMPRESS    3
232 #define ARCHIVE_COMPRESSION_PROGRAM     4
233 #define ARCHIVE_COMPRESSION_LZMA        5
234 #define ARCHIVE_COMPRESSION_XZ          6
235
236 /*
237  * Codes returned by archive_format.
238  *
239  * Top 16 bits identifies the format family (e.g., "tar"); lower
240  * 16 bits indicate the variant.  This is updated by read_next_header.
241  * Note that the lower 16 bits will often vary from entry to entry.
242  * In some cases, this variation occurs as libarchive learns more about
243  * the archive (for example, later entries might utilize extensions that
244  * weren't necessary earlier in the archive; in this case, libarchive
245  * will change the format code to indicate the extended format that
246  * was used).  In other cases, it's because different tools have
247  * modified the archive and so different parts of the archive
248  * actually have slightly different formts.  (Both tar and cpio store
249  * format codes in each entry, so it is quite possible for each
250  * entry to be in a different format.)
251  */
252 #define ARCHIVE_FORMAT_BASE_MASK                0xff0000
253 #define ARCHIVE_FORMAT_CPIO                     0x10000
254 #define ARCHIVE_FORMAT_CPIO_POSIX               (ARCHIVE_FORMAT_CPIO | 1)
255 #define ARCHIVE_FORMAT_CPIO_BIN_LE              (ARCHIVE_FORMAT_CPIO | 2)
256 #define ARCHIVE_FORMAT_CPIO_BIN_BE              (ARCHIVE_FORMAT_CPIO | 3)
257 #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC          (ARCHIVE_FORMAT_CPIO | 4)
258 #define ARCHIVE_FORMAT_CPIO_SVR4_CRC            (ARCHIVE_FORMAT_CPIO | 5)
259 #define ARCHIVE_FORMAT_SHAR                     0x20000
260 #define ARCHIVE_FORMAT_SHAR_BASE                (ARCHIVE_FORMAT_SHAR | 1)
261 #define ARCHIVE_FORMAT_SHAR_DUMP                (ARCHIVE_FORMAT_SHAR | 2)
262 #define ARCHIVE_FORMAT_TAR                      0x30000
263 #define ARCHIVE_FORMAT_TAR_USTAR                (ARCHIVE_FORMAT_TAR | 1)
264 #define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE      (ARCHIVE_FORMAT_TAR | 2)
265 #define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED       (ARCHIVE_FORMAT_TAR | 3)
266 #define ARCHIVE_FORMAT_TAR_GNUTAR               (ARCHIVE_FORMAT_TAR | 4)
267 #define ARCHIVE_FORMAT_ISO9660                  0x40000
268 #define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE        (ARCHIVE_FORMAT_ISO9660 | 1)
269 #define ARCHIVE_FORMAT_ZIP                      0x50000
270 #define ARCHIVE_FORMAT_EMPTY                    0x60000
271 #define ARCHIVE_FORMAT_AR                       0x70000
272 #define ARCHIVE_FORMAT_AR_GNU                   (ARCHIVE_FORMAT_AR | 1)
273 #define ARCHIVE_FORMAT_AR_BSD                   (ARCHIVE_FORMAT_AR | 2)
274 #define ARCHIVE_FORMAT_MTREE                    0x80000
275 #define ARCHIVE_FORMAT_RAW                      0x90000
276
277 /*-
278  * Basic outline for reading an archive:
279  *   1) Ask archive_read_new for an archive reader object.
280  *   2) Update any global properties as appropriate.
281  *      In particular, you'll certainly want to call appropriate
282  *      archive_read_support_XXX functions.
283  *   3) Call archive_read_open_XXX to open the archive
284  *   4) Repeatedly call archive_read_next_header to get information about
285  *      successive archive entries.  Call archive_read_data to extract
286  *      data for entries of interest.
287  *   5) Call archive_read_finish to end processing.
288  */
289 __LA_DECL struct archive        *archive_read_new(void);
290
291 /*
292  * The archive_read_support_XXX calls enable auto-detect for this
293  * archive handle.  They also link in the necessary support code.
294  * For example, if you don't want bzlib linked in, don't invoke
295  * support_compression_bzip2().  The "all" functions provide the
296  * obvious shorthand.
297  */
298 __LA_DECL int            archive_read_support_compression_all(struct archive *);
299 __LA_DECL int            archive_read_support_compression_bzip2(struct archive *);
300 __LA_DECL int            archive_read_support_compression_compress(struct archive *);
301 __LA_DECL int            archive_read_support_compression_gzip(struct archive *);
302 __LA_DECL int            archive_read_support_compression_lzma(struct archive *);
303 __LA_DECL int            archive_read_support_compression_none(struct archive *);
304 __LA_DECL int            archive_read_support_compression_program(struct archive *,
305                      const char *command);
306 __LA_DECL int            archive_read_support_compression_program_signature
307                                 (struct archive *, const char *,
308                                     const void * /* match */, size_t);
309
310 __LA_DECL int            archive_read_support_compression_xz(struct archive *);
311
312 __LA_DECL int            archive_read_support_format_all(struct archive *);
313 __LA_DECL int            archive_read_support_format_ar(struct archive *);
314 __LA_DECL int            archive_read_support_format_cpio(struct archive *);
315 __LA_DECL int            archive_read_support_format_empty(struct archive *);
316 __LA_DECL int            archive_read_support_format_gnutar(struct archive *);
317 __LA_DECL int            archive_read_support_format_iso9660(struct archive *);
318 __LA_DECL int            archive_read_support_format_mtree(struct archive *);
319 __LA_DECL int            archive_read_support_format_raw(struct archive *);
320 __LA_DECL int            archive_read_support_format_tar(struct archive *);
321 __LA_DECL int            archive_read_support_format_zip(struct archive *);
322
323
324 /* Open the archive using callbacks for archive I/O. */
325 __LA_DECL int            archive_read_open(struct archive *, void *_client_data,
326                      archive_open_callback *, archive_read_callback *,
327                      archive_close_callback *);
328 __LA_DECL int            archive_read_open2(struct archive *, void *_client_data,
329                      archive_open_callback *, archive_read_callback *,
330                      archive_skip_callback *, archive_close_callback *);
331
332 /*
333  * A variety of shortcuts that invoke archive_read_open() with
334  * canned callbacks suitable for common situations.  The ones that
335  * accept a block size handle tape blocking correctly.
336  */
337 /* Use this if you know the filename.  Note: NULL indicates stdin. */
338 __LA_DECL int            archive_read_open_filename(struct archive *,
339                      const char *_filename, size_t _block_size);
340 /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
341 __LA_DECL int            archive_read_open_file(struct archive *,
342                      const char *_filename, size_t _block_size);
343 /* Read an archive that's stored in memory. */
344 __LA_DECL int            archive_read_open_memory(struct archive *,
345                      void * buff, size_t size);
346 /* A more involved version that is only used for internal testing. */
347 __LA_DECL int           archive_read_open_memory2(struct archive *a, void *buff,
348                      size_t size, size_t read_size);
349 /* Read an archive that's already open, using the file descriptor. */
350 __LA_DECL int            archive_read_open_fd(struct archive *, int _fd,
351                      size_t _block_size);
352 /* Read an archive that's already open, using a FILE *. */
353 /* Note: DO NOT use this with tape drives. */
354 __LA_DECL int            archive_read_open_FILE(struct archive *, FILE *_file);
355
356 /* Parses and returns next entry header. */
357 __LA_DECL int            archive_read_next_header(struct archive *,
358                      struct archive_entry **);
359
360 /* Parses and returns next entry header using the archive_entry passed in */
361 __LA_DECL int            archive_read_next_header2(struct archive *,
362                      struct archive_entry *);
363
364 /*
365  * Retrieve the byte offset in UNCOMPRESSED data where last-read
366  * header started.
367  */
368 __LA_DECL __LA_INT64_T           archive_read_header_position(struct archive *);
369
370 /* Read data from the body of an entry.  Similar to read(2). */
371 __LA_DECL __LA_SSIZE_T           archive_read_data(struct archive *,
372                                     void *, size_t);
373
374 /*
375  * A zero-copy version of archive_read_data that also exposes the file offset
376  * of each returned block.  Note that the client has no way to specify
377  * the desired size of the block.  The API does guarantee that offsets will
378  * be strictly increasing and that returned blocks will not overlap.
379  */
380 #if ARCHIVE_VERSION_NUMBER < 3000000
381 __LA_DECL int            archive_read_data_block(struct archive *a,
382                             const void **buff, size_t *size, off_t *offset);
383 #else
384 __LA_DECL int            archive_read_data_block(struct archive *a,
385                             const void **buff, size_t *size,
386                             __LA_INT64_T *offset);
387 #endif
388
389 /*-
390  * Some convenience functions that are built on archive_read_data:
391  *  'skip': skips entire entry
392  *  'into_buffer': writes data into memory buffer that you provide
393  *  'into_fd': writes data to specified filedes
394  */
395 __LA_DECL int            archive_read_data_skip(struct archive *);
396 __LA_DECL int            archive_read_data_into_buffer(struct archive *,
397                             void *buffer, __LA_SSIZE_T len);
398 __LA_DECL int            archive_read_data_into_fd(struct archive *, int fd);
399
400 /*
401  * Set read options.
402  */
403 /* Apply option string to the format only. */
404 __LA_DECL int           archive_read_set_format_options(struct archive *_a,
405                             const char *s);
406 /* Apply option string to the filter only. */
407 __LA_DECL int           archive_read_set_filter_options(struct archive *_a,
408                             const char *s);
409 /* Apply option string to both the format and the filter. */
410 __LA_DECL int           archive_read_set_options(struct archive *_a,
411                             const char *s);
412
413 /*-
414  * Convenience function to recreate the current entry (whose header
415  * has just been read) on disk.
416  *
417  * This does quite a bit more than just copy data to disk. It also:
418  *  - Creates intermediate directories as required.
419  *  - Manages directory permissions:  non-writable directories will
420  *    be initially created with write permission enabled; when the
421  *    archive is closed, dir permissions are edited to the values specified
422  *    in the archive.
423  *  - Checks hardlinks:  hardlinks will not be extracted unless the
424  *    linked-to file was also extracted within the same session. (TODO)
425  */
426
427 /* The "flags" argument selects optional behavior, 'OR' the flags you want. */
428
429 /* Default: Do not try to set owner/group. */
430 #define ARCHIVE_EXTRACT_OWNER                   (0x0001)
431 /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */
432 #define ARCHIVE_EXTRACT_PERM                    (0x0002)
433 /* Default: Do not restore mtime/atime. */
434 #define ARCHIVE_EXTRACT_TIME                    (0x0004)
435 /* Default: Replace existing files. */
436 #define ARCHIVE_EXTRACT_NO_OVERWRITE            (0x0008)
437 /* Default: Try create first, unlink only if create fails with EEXIST. */
438 #define ARCHIVE_EXTRACT_UNLINK                  (0x0010)
439 /* Default: Do not restore ACLs. */
440 #define ARCHIVE_EXTRACT_ACL                     (0x0020)
441 /* Default: Do not restore fflags. */
442 #define ARCHIVE_EXTRACT_FFLAGS                  (0x0040)
443 /* Default: Do not restore xattrs. */
444 #define ARCHIVE_EXTRACT_XATTR                   (0x0080)
445 /* Default: Do not try to guard against extracts redirected by symlinks. */
446 /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */
447 #define ARCHIVE_EXTRACT_SECURE_SYMLINKS         (0x0100)
448 /* Default: Do not reject entries with '..' as path elements. */
449 #define ARCHIVE_EXTRACT_SECURE_NODOTDOT         (0x0200)
450 /* Default: Create parent directories as needed. */
451 #define ARCHIVE_EXTRACT_NO_AUTODIR              (0x0400)
452 /* Default: Overwrite files, even if one on disk is newer. */
453 #define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER      (0x0800)
454 /* Detect blocks of 0 and write holes instead. */
455 #define ARCHIVE_EXTRACT_SPARSE                  (0x1000)
456
457 __LA_DECL int    archive_read_extract(struct archive *, struct archive_entry *,
458                      int flags);
459 __LA_DECL int    archive_read_extract2(struct archive *, struct archive_entry *,
460                      struct archive * /* dest */);
461 __LA_DECL void   archive_read_extract_set_progress_callback(struct archive *,
462                      void (*_progress_func)(void *), void *_user_data);
463
464 /* Record the dev/ino of a file that will not be written.  This is
465  * generally set to the dev/ino of the archive being read. */
466 __LA_DECL void          archive_read_extract_set_skip_file(struct archive *,
467                      dev_t, ino_t);
468
469 /* Close the file and release most resources. */
470 __LA_DECL int            archive_read_close(struct archive *);
471 /* Release all resources and destroy the object. */
472 /* Note that archive_read_finish will call archive_read_close for you. */
473 #if ARCHIVE_VERSION_NUMBER < 2000000
474 /* Erroneously declared to return void in libarchive 1.x */
475 __LA_DECL void           archive_read_finish(struct archive *);
476 #else
477 __LA_DECL int            archive_read_finish(struct archive *);
478 #endif
479
480 /*-
481  * To create an archive:
482  *   1) Ask archive_write_new for a archive writer object.
483  *   2) Set any global properties.  In particular, you should set
484  *      the compression and format to use.
485  *   3) Call archive_write_open to open the file (most people
486  *       will use archive_write_open_file or archive_write_open_fd,
487  *       which provide convenient canned I/O callbacks for you).
488  *   4) For each entry:
489  *      - construct an appropriate struct archive_entry structure
490  *      - archive_write_header to write the header
491  *      - archive_write_data to write the entry data
492  *   5) archive_write_close to close the output
493  *   6) archive_write_finish to cleanup the writer and release resources
494  */
495 __LA_DECL struct archive        *archive_write_new(void);
496 __LA_DECL int            archive_write_set_bytes_per_block(struct archive *,
497                      int bytes_per_block);
498 __LA_DECL int            archive_write_get_bytes_per_block(struct archive *);
499 /* XXX This is badly misnamed; suggestions appreciated. XXX */
500 __LA_DECL int            archive_write_set_bytes_in_last_block(struct archive *,
501                      int bytes_in_last_block);
502 __LA_DECL int            archive_write_get_bytes_in_last_block(struct archive *);
503
504 /* The dev/ino of a file that won't be archived.  This is used
505  * to avoid recursively adding an archive to itself. */
506 __LA_DECL int            archive_write_set_skip_file(struct archive *, dev_t, ino_t);
507
508 __LA_DECL int            archive_write_set_compression_bzip2(struct archive *);
509 __LA_DECL int            archive_write_set_compression_compress(struct archive *);
510 __LA_DECL int            archive_write_set_compression_gzip(struct archive *);
511 __LA_DECL int            archive_write_set_compression_lzma(struct archive *);
512 __LA_DECL int            archive_write_set_compression_none(struct archive *);
513 __LA_DECL int            archive_write_set_compression_program(struct archive *,
514                      const char *cmd);
515 __LA_DECL int            archive_write_set_compression_xz(struct archive *);
516 /* A convenience function to set the format based on the code or name. */
517 __LA_DECL int            archive_write_set_format(struct archive *, int format_code);
518 __LA_DECL int            archive_write_set_format_by_name(struct archive *,
519                      const char *name);
520 /* To minimize link pollution, use one or more of the following. */
521 __LA_DECL int            archive_write_set_format_ar_bsd(struct archive *);
522 __LA_DECL int            archive_write_set_format_ar_svr4(struct archive *);
523 __LA_DECL int            archive_write_set_format_cpio(struct archive *);
524 __LA_DECL int            archive_write_set_format_cpio_newc(struct archive *);
525 __LA_DECL int            archive_write_set_format_mtree(struct archive *);
526 /* TODO: int archive_write_set_format_old_tar(struct archive *); */
527 __LA_DECL int            archive_write_set_format_pax(struct archive *);
528 __LA_DECL int            archive_write_set_format_pax_restricted(struct archive *);
529 __LA_DECL int            archive_write_set_format_shar(struct archive *);
530 __LA_DECL int            archive_write_set_format_shar_dump(struct archive *);
531 __LA_DECL int            archive_write_set_format_ustar(struct archive *);
532 __LA_DECL int            archive_write_open(struct archive *, void *,
533                      archive_open_callback *, archive_write_callback *,
534                      archive_close_callback *);
535 __LA_DECL int            archive_write_open_fd(struct archive *, int _fd);
536 __LA_DECL int            archive_write_open_filename(struct archive *, const char *_file);
537 /* A deprecated synonym for archive_write_open_filename() */
538 __LA_DECL int            archive_write_open_file(struct archive *, const char *_file);
539 __LA_DECL int            archive_write_open_FILE(struct archive *, FILE *);
540 /* _buffSize is the size of the buffer, _used refers to a variable that
541  * will be updated after each write into the buffer. */
542 __LA_DECL int            archive_write_open_memory(struct archive *,
543                         void *_buffer, size_t _buffSize, size_t *_used);
544
545 /*
546  * Note that the library will truncate writes beyond the size provided
547  * to archive_write_header or pad if the provided data is short.
548  */
549 __LA_DECL int            archive_write_header(struct archive *,
550                      struct archive_entry *);
551 #if ARCHIVE_VERSION_NUMBER < 2000000
552 /* This was erroneously declared to return "int" in libarchive 1.x. */
553 __LA_DECL int            archive_write_data(struct archive *,
554                             const void *, size_t);
555 #else
556 /* Libarchive 2.0 and later return ssize_t here. */
557 __LA_DECL __LA_SSIZE_T   archive_write_data(struct archive *,
558                             const void *, size_t);
559 #endif
560
561 #if ARCHIVE_VERSION_NUMBER < 3000000
562 /* Libarchive 1.x and 2.x use off_t for the argument, but that's not
563  * stable on Linux. */
564 __LA_DECL __LA_SSIZE_T   archive_write_data_block(struct archive *,
565                                     const void *, size_t, off_t);
566 #else
567 /* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */
568 __LA_DECL __LA_SSIZE_T   archive_write_data_block(struct archive *,
569                                     const void *, size_t, __LA_INT64_T);
570 #endif
571 __LA_DECL int            archive_write_finish_entry(struct archive *);
572 __LA_DECL int            archive_write_close(struct archive *);
573 #if ARCHIVE_VERSION_NUMBER < 2000000
574 /* Return value was incorrect in libarchive 1.x. */
575 __LA_DECL void           archive_write_finish(struct archive *);
576 #else
577 /* Libarchive 2.x and later returns an error if this fails. */
578 /* It can fail if the archive wasn't already closed, in which case
579  * archive_write_finish() will implicitly call archive_write_close(). */
580 __LA_DECL int            archive_write_finish(struct archive *);
581 #endif
582
583 /*
584  * Set write options.
585  */
586 /* Apply option string to the format only. */
587 __LA_DECL int           archive_write_set_format_options(struct archive *_a,
588                             const char *s);
589 /* Apply option string to the compressor only. */
590 __LA_DECL int           archive_write_set_compressor_options(struct archive *_a,
591                             const char *s);
592 /* Apply option string to both the format and the compressor. */
593 __LA_DECL int           archive_write_set_options(struct archive *_a,
594                             const char *s);
595
596
597 /*-
598  * ARCHIVE_WRITE_DISK API
599  *
600  * To create objects on disk:
601  *   1) Ask archive_write_disk_new for a new archive_write_disk object.
602  *   2) Set any global properties.  In particular, you probably
603  *      want to set the options.
604  *   3) For each entry:
605  *      - construct an appropriate struct archive_entry structure
606  *      - archive_write_header to create the file/dir/etc on disk
607  *      - archive_write_data to write the entry data
608  *   4) archive_write_finish to cleanup the writer and release resources
609  *
610  * In particular, you can use this in conjunction with archive_read()
611  * to pull entries out of an archive and create them on disk.
612  */
613 __LA_DECL struct archive        *archive_write_disk_new(void);
614 /* This file will not be overwritten. */
615 __LA_DECL int            archive_write_disk_set_skip_file(struct archive *,
616                      dev_t, ino_t);
617 /* Set flags to control how the next item gets created.
618  * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */
619 __LA_DECL int            archive_write_disk_set_options(struct archive *,
620                      int flags);
621 /*
622  * The lookup functions are given uname/uid (or gname/gid) pairs and
623  * return a uid (gid) suitable for this system.  These are used for
624  * restoring ownership and for setting ACLs.  The default functions
625  * are naive, they just return the uid/gid.  These are small, so reasonable
626  * for applications that don't need to preserve ownership; they
627  * are probably also appropriate for applications that are doing
628  * same-system backup and restore.
629  */
630 /*
631  * The "standard" lookup functions use common system calls to lookup
632  * the uname/gname, falling back to the uid/gid if the names can't be
633  * found.  They cache lookups and are reasonably fast, but can be very
634  * large, so they are not used unless you ask for them.  In
635  * particular, these match the specifications of POSIX "pax" and old
636  * POSIX "tar".
637  */
638 __LA_DECL int    archive_write_disk_set_standard_lookup(struct archive *);
639 /*
640  * If neither the default (naive) nor the standard (big) functions suit
641  * your needs, you can write your own and register them.  Be sure to
642  * include a cleanup function if you have allocated private data.
643  */
644 __LA_DECL int    archive_write_disk_set_group_lookup(struct archive *,
645                             void * /* private_data */,
646                             __LA_GID_T (*)(void *, const char *, __LA_GID_T),
647                             void (* /* cleanup */)(void *));
648 __LA_DECL int    archive_write_disk_set_user_lookup(struct archive *,
649                             void * /* private_data */,
650                             __LA_UID_T (*)(void *, const char *, __LA_UID_T),
651                             void (* /* cleanup */)(void *));
652
653 /*
654  * ARCHIVE_READ_DISK API
655  *
656  * This is still evolving and somewhat experimental.
657  */
658 __LA_DECL struct archive *archive_read_disk_new(void);
659 /* The names for symlink modes here correspond to an old BSD
660  * command-line argument convention: -L, -P, -H */
661 /* Follow all symlinks. */
662 __LA_DECL int archive_read_disk_set_symlink_logical(struct archive *);
663 /* Follow no symlinks. */
664 __LA_DECL int archive_read_disk_set_symlink_physical(struct archive *);
665 /* Follow symlink initially, then not. */
666 __LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *);
667 /* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */
668 __LA_DECL int archive_read_disk_entry_from_file(struct archive *,
669     struct archive_entry *, int /* fd */, const struct stat *);
670 /* Look up gname for gid or uname for uid. */
671 /* Default implementations are very, very stupid. */
672 __LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_GID_T);
673 __LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_UID_T);
674 /* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the
675  * results for performance. */
676 __LA_DECL int   archive_read_disk_set_standard_lookup(struct archive *);
677 /* You can install your own lookups if you like. */
678 __LA_DECL int   archive_read_disk_set_gname_lookup(struct archive *,
679     void * /* private_data */,
680     const char *(* /* lookup_fn */)(void *, __LA_GID_T),
681     void (* /* cleanup_fn */)(void *));
682 __LA_DECL int   archive_read_disk_set_uname_lookup(struct archive *,
683     void * /* private_data */,
684     const char *(* /* lookup_fn */)(void *, __LA_UID_T),
685     void (* /* cleanup_fn */)(void *));
686
687 /*
688  * Accessor functions to read/set various information in
689  * the struct archive object:
690  */
691 /* Bytes written after compression or read before decompression. */
692 __LA_DECL __LA_INT64_T   archive_position_compressed(struct archive *);
693 /* Bytes written to compressor or read from decompressor. */
694 __LA_DECL __LA_INT64_T   archive_position_uncompressed(struct archive *);
695
696 __LA_DECL const char    *archive_compression_name(struct archive *);
697 __LA_DECL int            archive_compression(struct archive *);
698 __LA_DECL int            archive_errno(struct archive *);
699 __LA_DECL const char    *archive_error_string(struct archive *);
700 __LA_DECL const char    *archive_format_name(struct archive *);
701 __LA_DECL int            archive_format(struct archive *);
702 __LA_DECL void           archive_clear_error(struct archive *);
703 __LA_DECL void           archive_set_error(struct archive *, int _err,
704                             const char *fmt, ...);
705 __LA_DECL void           archive_copy_error(struct archive *dest,
706                             struct archive *src);
707
708 #ifdef __cplusplus
709 }
710 #endif
711
712 /* These are meaningless outside of this header. */
713 #undef __LA_DECL
714 #undef __LA_GID_T
715 #undef __LA_UID_T
716
717 /* These need to remain defined because they're used in the
718  * callback type definitions.  XXX Fix this.  This is ugly. XXX */
719 /* #undef __LA_INT64_T */
720 /* #undef __LA_SSIZE_T */
721
722 #endif /* !ARCHIVE_H_INCLUDED */