Merge from vendor branch LIBARCHIVE:
[dragonfly.git] / contrib / libarchive-1.3.1 / libarchive / archive.h.in
1 /*-
2  * Copyright (c) 2003-2004 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  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/lib/libarchive/archive.h.in,v 1.31 2006/09/05 05:59:45 kientzle Exp $
27  */
28
29 #ifndef ARCHIVE_H_INCLUDED
30 #define ARCHIVE_H_INCLUDED
31
32 /*
33  * This header file corresponds to:
34  *   Library version @VERSION@
35  *   Shared library version @SHLIB_MAJOR@
36  */
37
38 #include <sys/types.h>  /* Linux requires this for off_t */
39 @ARCHIVE_H_INCLUDE_INTTYPES_H@
40 #include <stdio.h> /* For FILE * */
41 #include <unistd.h>  /* For ssize_t and size_t */
42
43 #ifdef __cplusplus
44 extern "C" {
45 #endif
46
47
48 /*
49  * If ARCHIVE_API_VERSION != archive_api_version(), then the library you
50  * were linked with is using an incompatible API to the one you were
51  * compiled with.  This is almost certainly a fatal problem.
52  *
53  * ARCHIVE_API_FEATURE is incremented with each significant feature
54  * addition, so you can test (at compile or run time) if a particular
55  * feature is implemented.  It's no big deal if ARCHIVE_API_FEATURE !=
56  * archive_api_feature(), as long as both are high enough to include
57  * the features you're relying on.  Specific values of FEATURE are
58  * documented here:
59  *
60  *    1 - Version tests are available.
61  *    2 - archive_{read,write}_close available separately from _finish.
62  *    3 - open_memory, open_memory2, open_FILE, open_fd available
63  */
64 #define ARCHIVE_API_VERSION     @ARCHIVE_API_MAJOR@
65 int             archive_api_version(void);
66 #define ARCHIVE_API_FEATURE     @ARCHIVE_API_MINOR@
67 int             archive_api_feature(void);
68 /* Textual name/version of the library. */
69 #define ARCHIVE_LIBRARY_VERSION "libarchive @VERSION@"
70 const char *    archive_version(void);
71
72 #define ARCHIVE_BYTES_PER_RECORD          512
73 #define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240
74
75 /* Declare our basic types. */
76 struct archive;
77 struct archive_entry;
78
79 /*
80  * Error codes: Use archive_errno() and archive_error_string()
81  * to retrieve details.  Unless specified otherwise, all functions
82  * that return 'int' use these codes.
83  */
84 #define ARCHIVE_EOF       1     /* Found end of archive. */
85 #define ARCHIVE_OK        0     /* Operation was successful. */
86 #define ARCHIVE_RETRY   (-10)   /* Retry might succeed. */
87 #define ARCHIVE_WARN    (-20)   /* Partial sucess. */
88 #define ARCHIVE_FATAL   (-30)   /* No more operations are possible. */
89
90 /*
91  * As far as possible, archive_errno returns standard platform errno codes.
92  * Of course, the details vary by platform, so the actual definitions
93  * here are stored in "archive_platform.h".  The symbols are listed here
94  * for reference; as a rule, clients should not need to know the exact
95  * platform-dependent error code.
96  */
97 /* Unrecognized or invalid file format. */
98 /* #define      ARCHIVE_ERRNO_FILE_FORMAT */
99 /* Illegal usage of the library. */
100 /* #define      ARCHIVE_ERRNO_PROGRAMMER_ERROR */
101 /* Unknown or unclassified error. */
102 /* #define      ARCHIVE_ERRNO_MISC */
103
104 /*
105  * Callbacks are invoked to automatically read/skip/write/open/close the
106  * archive. You can provide your own for complex tasks (like breaking
107  * archives across multiple tapes) or use standard ones built into the
108  * library.
109  */
110
111 /* Returns pointer and size of next block of data from archive. */
112 typedef ssize_t archive_read_callback(struct archive *, void *_client_data,
113                     const void **_buffer);
114 /* Skips at most request bytes from archive and returns the skipped amount */
115 typedef ssize_t archive_skip_callback(struct archive *, void *_client_data,
116                     size_t request);
117 /* Returns size actually written, zero on EOF, -1 on error. */
118 typedef ssize_t archive_write_callback(struct archive *, void *_client_data,
119                     void *_buffer, size_t _length);
120 typedef int     archive_open_callback(struct archive *, void *_client_data);
121 typedef int     archive_close_callback(struct archive *, void *_client_data);
122
123 /*
124  * Codes for archive_compression.
125  */
126 #define ARCHIVE_COMPRESSION_NONE        0
127 #define ARCHIVE_COMPRESSION_GZIP        1
128 #define ARCHIVE_COMPRESSION_BZIP2       2
129 #define ARCHIVE_COMPRESSION_COMPRESS    3
130
131 /*
132  * Codes returned by archive_format.
133  *
134  * Top 16 bits identifies the format family (e.g., "tar"); lower
135  * 16 bits indicate the variant.  This is updated by read_next_header.
136  * Note that the lower 16 bits will often vary from entry to entry.
137  */
138 #define ARCHIVE_FORMAT_BASE_MASK                0xff0000U
139 #define ARCHIVE_FORMAT_CPIO                     0x10000
140 #define ARCHIVE_FORMAT_CPIO_POSIX               (ARCHIVE_FORMAT_CPIO | 1)
141 #define ARCHIVE_FORMAT_CPIO_BIN_LE              (ARCHIVE_FORMAT_CPIO | 2)
142 #define ARCHIVE_FORMAT_CPIO_BIN_BE              (ARCHIVE_FORMAT_CPIO | 3)
143 #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC          (ARCHIVE_FORMAT_CPIO | 4)
144 #define ARCHIVE_FORMAT_CPIO_SVR4_CRC            (ARCHIVE_FORMAT_CPIO | 5)
145 #define ARCHIVE_FORMAT_SHAR                     0x20000
146 #define ARCHIVE_FORMAT_SHAR_BASE                (ARCHIVE_FORMAT_SHAR | 1)
147 #define ARCHIVE_FORMAT_SHAR_DUMP                (ARCHIVE_FORMAT_SHAR | 2)
148 #define ARCHIVE_FORMAT_TAR                      0x30000
149 #define ARCHIVE_FORMAT_TAR_USTAR                (ARCHIVE_FORMAT_TAR | 1)
150 #define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE      (ARCHIVE_FORMAT_TAR | 2)
151 #define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED       (ARCHIVE_FORMAT_TAR | 3)
152 #define ARCHIVE_FORMAT_TAR_GNUTAR               (ARCHIVE_FORMAT_TAR | 4)
153 #define ARCHIVE_FORMAT_ISO9660                  0x40000
154 #define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE        (ARCHIVE_FORMAT_ISO9660 | 1)
155 #define ARCHIVE_FORMAT_ZIP                      0x50000
156
157 /*-
158  * Basic outline for reading an archive:
159  *   1) Ask archive_read_new for an archive reader object.
160  *   2) Update any global properties as appropriate.
161  *      In particular, you'll certainly want to call appropriate
162  *      archive_read_support_XXX functions.
163  *   3) Call archive_read_open_XXX to open the archive
164  *   4) Repeatedly call archive_read_next_header to get information about
165  *      successive archive entries.  Call archive_read_data to extract
166  *      data for entries of interest.
167  *   5) Call archive_read_finish to end processing.
168  */
169 struct archive  *archive_read_new(void);
170
171 /*
172  * The archive_read_support_XXX calls enable auto-detect for this
173  * archive handle.  They also link in the necessary support code.
174  * For example, if you don't want bzlib linked in, don't invoke
175  * support_compression_bzip2().  The "all" functions provide the
176  * obvious shorthand.
177  */
178 int              archive_read_support_compression_all(struct archive *);
179 int              archive_read_support_compression_bzip2(struct archive *);
180 int              archive_read_support_compression_compress(struct archive *);
181 int              archive_read_support_compression_gzip(struct archive *);
182 int              archive_read_support_compression_none(struct archive *);
183
184 int              archive_read_support_format_all(struct archive *);
185 int              archive_read_support_format_cpio(struct archive *);
186 int              archive_read_support_format_gnutar(struct archive *);
187 int              archive_read_support_format_iso9660(struct archive *);
188 int              archive_read_support_format_tar(struct archive *);
189 int              archive_read_support_format_zip(struct archive *);
190
191
192 /* Open the archive using callbacks for archive I/O. */
193 int              archive_read_open(struct archive *, void *_client_data,
194                      archive_open_callback *, archive_read_callback *,
195                      archive_close_callback *);
196 int              archive_read_open2(struct archive *, void *_client_data,
197                      archive_open_callback *, archive_read_callback *,
198                      archive_skip_callback *, archive_close_callback *);
199
200 /*
201  * A variety of shortcuts that invoke archive_read_open() with
202  * canned callbacks suitable for common situations.  The ones that
203  * accept a block size handle tape blocking correctly.
204  */
205 /* Use this if you know the filename.  Note: NULL indicates stdin. */
206 int              archive_read_open_filename(struct archive *,
207                      const char *_filename, size_t _block_size);
208 /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */
209 int              archive_read_open_file(struct archive *,
210                      const char *_filename, size_t _block_size);
211 /* Read an archive that's stored in memory. */
212 int              archive_read_open_memory(struct archive *,
213                      void * buff, size_t size);
214 /* A more involved version that is only used for internal testing. */
215 int             archive_read_open_memory2(struct archive *a, void *buff,
216                      size_t size, size_t read_size);
217 /* Read an archive that's already open, using the file descriptor. */
218 int              archive_read_open_fd(struct archive *, int _fd,
219                      size_t _block_size);
220 /* Read an archive that's already open, using a FILE *. */
221 /* Note: DO NOT use this with tape drives. */
222 int              archive_read_open_FILE(struct archive *, FILE *_file);
223
224 /* Parses and returns next entry header. */
225 int              archive_read_next_header(struct archive *,
226                      struct archive_entry **);
227
228 /*
229  * Retrieve the byte offset in UNCOMPRESSED data where last-read
230  * header started.
231  */
232 int64_t          archive_read_header_position(struct archive *);
233
234 /* Read data from the body of an entry.  Similar to read(2). */
235 ssize_t          archive_read_data(struct archive *, void *, size_t);
236 /*
237  * A zero-copy version of archive_read_data that also exposes the file offset
238  * of each returned block.  Note that the client has no way to specify
239  * the desired size of the block.  The API does gaurantee that offsets will
240  * be strictly increasing and that returned blocks will not overlap.
241  */
242 int              archive_read_data_block(struct archive *a,
243                     const void **buff, size_t *size, off_t *offset);
244
245 /*-
246  * Some convenience functions that are built on archive_read_data:
247  *  'skip': skips entire entry
248  *  'into_buffer': writes data into memory buffer that you provide
249  *  'into_fd': writes data to specified filedes
250  */
251 int              archive_read_data_skip(struct archive *);
252 int              archive_read_data_into_buffer(struct archive *, void *buffer,
253                      ssize_t len);
254 int              archive_read_data_into_fd(struct archive *, int fd);
255
256 /*-
257  * Convenience function to recreate the current entry (whose header
258  * has just been read) on disk.
259  *
260  * This does quite a bit more than just copy data to disk. It also:
261  *  - Creates intermediate directories as required.
262  *  - Manages directory permissions:  non-writable directories will
263  *    be initially created with write permission enabled; when the
264  *    archive is closed, dir permissions are edited to the values specified
265  *    in the archive.
266  *  - Checks hardlinks:  hardlinks will not be extracted unless the
267  *    linked-to file was also extracted within the same session. (TODO)
268  */
269
270 /* The "flags" argument selects optional behavior, 'OR' the flags you want. */
271 /* TODO: The 'Default' comments here are not quite correct; clean this up. */
272 #define ARCHIVE_EXTRACT_OWNER   (1) /* Default: owner/group not restored */
273 #define ARCHIVE_EXTRACT_PERM    (2) /* Default: restore perm only for reg file*/
274 #define ARCHIVE_EXTRACT_TIME    (4) /* Default: mod time not restored */
275 #define ARCHIVE_EXTRACT_NO_OVERWRITE (8) /* Default: Replace files on disk */
276 #define ARCHIVE_EXTRACT_UNLINK  (16) /* Default: don't unlink existing files */
277 #define ARCHIVE_EXTRACT_ACL     (32) /* Default: don't restore ACLs */
278 #define ARCHIVE_EXTRACT_FFLAGS  (64) /* Default: don't restore fflags */
279 #define ARCHIVE_EXTRACT_XATTR   (128) /* Default: don't restore xattrs */
280
281 int              archive_read_extract(struct archive *, struct archive_entry *,
282                      int flags);
283 void             archive_read_extract_set_progress_callback(struct archive *,
284                      void (*_progress_func)(void *), void *_user_data);
285
286 /* Record the dev/ino of a file that will not be written.  This is
287  * generally set to the dev/ino of the archive being read. */
288 void            archive_read_extract_set_skip_file(struct archive *,
289                      dev_t, ino_t);
290
291 /* Close the file and release most resources. */
292 int              archive_read_close(struct archive *);
293 /* Release all resources and destroy the object. */
294 /* Note that archive_read_finish will call archive_read_close for you. */
295 #if ARCHIVE_API_VERSION > 1
296 int              archive_read_finish(struct archive *);
297 #else
298 /* Temporarily allow library to compile with either 1.x or 2.0 API. */
299 /* Erroneously declared to return void in libarchive 1.x */
300 void             archive_read_finish(struct archive *);
301 #endif
302
303 /*-
304  * To create an archive:
305  *   1) Ask archive_write_new for a archive writer object.
306  *   2) Set any global properties.  In particular, you should set
307  *      the compression and format to use.
308  *   3) Call archive_write_open to open the file (most people
309  *       will use archive_write_open_file or archive_write_open_fd,
310  *       which provide convenient canned I/O callbacks for you).
311  *   4) For each entry:
312  *      - construct an appropriate struct archive_entry structure
313  *      - archive_write_header to write the header
314  *      - archive_write_data to write the entry data
315  *   5) archive_write_close to close the output
316  *   6) archive_write_finish to cleanup the writer and release resources
317  */
318 struct archive  *archive_write_new(void);
319 int              archive_write_set_bytes_per_block(struct archive *,
320                      int bytes_per_block);
321 int              archive_write_get_bytes_per_block(struct archive *);
322 /* XXX This is badly misnamed; suggestions appreciated. XXX */
323 int              archive_write_set_bytes_in_last_block(struct archive *,
324                      int bytes_in_last_block);
325 int              archive_write_get_bytes_in_last_block(struct archive *);
326
327 /* The dev/ino of a file that won't be archived.  This is used
328  * to avoid recursively adding an archive to itself. */
329 int              archive_write_set_skip_file(struct archive *, dev_t, ino_t);
330
331 int              archive_write_set_compression_bzip2(struct archive *);
332 int              archive_write_set_compression_gzip(struct archive *);
333 int              archive_write_set_compression_none(struct archive *);
334 /* A convenience function to set the format based on the code or name. */
335 int              archive_write_set_format(struct archive *, int format_code);
336 int              archive_write_set_format_by_name(struct archive *,
337                      const char *name);
338 /* To minimize link pollution, use one or more of the following. */
339 int              archive_write_set_format_cpio(struct archive *);
340 /* TODO: int archive_write_set_format_old_tar(struct archive *); */
341 int              archive_write_set_format_pax(struct archive *);
342 int              archive_write_set_format_pax_restricted(struct archive *);
343 int              archive_write_set_format_shar(struct archive *);
344 int              archive_write_set_format_shar_dump(struct archive *);
345 int              archive_write_set_format_ustar(struct archive *);
346 int              archive_write_open(struct archive *, void *,
347                      archive_open_callback *, archive_write_callback *,
348                      archive_close_callback *);
349 int              archive_write_open_fd(struct archive *, int _fd);
350 int              archive_write_open_filename(struct archive *, const char *_file);
351 /* A deprecated synonym for archive_write_open_filename() */
352 int              archive_write_open_file(struct archive *, const char *_file);
353 int              archive_write_open_FILE(struct archive *, FILE *);
354 /* _buffSize is the size of the buffer, _used refers to a variable that
355  * will be updated after each write into the buffer. */
356 int              archive_write_open_memory(struct archive *,
357                         void *_buffer, size_t _buffSize, size_t *_used);
358
359 /*
360  * Note that the library will truncate writes beyond the size provided
361  * to archive_write_header or pad if the provided data is short.
362  */
363 int              archive_write_header(struct archive *,
364                      struct archive_entry *);
365 #if ARCHIVE_API_VERSION > 1
366 ssize_t          archive_write_data(struct archive *, const void *, size_t);
367 #else
368 /* Temporarily allow library to compile with either 1.x or 2.0 API. */
369 /* This was erroneously declared to return "int" in libarchive 1.x. */
370 int              archive_write_data(struct archive *, const void *, size_t);
371 #endif
372 int              archive_write_close(struct archive *);
373 #if ARCHIVE_API_VERSION > 1
374 int              archive_write_finish(struct archive *);
375 #else
376 /* Temporarily allow library to compile with either 1.x or 2.0 API. */
377 /* Return value was incorrect in libarchive 1.x. */
378 void             archive_write_finish(struct archive *);
379 #endif
380
381 /*
382  * Accessor functions to read/set various information in
383  * the struct archive object:
384  */
385 /* Bytes written after compression or read before decompression. */
386 int64_t          archive_position_compressed(struct archive *);
387 /* Bytes written to compressor or read from decompressor. */
388 int64_t          archive_position_uncompressed(struct archive *);
389
390 const char      *archive_compression_name(struct archive *);
391 int              archive_compression(struct archive *);
392 int              archive_errno(struct archive *);
393 const char      *archive_error_string(struct archive *);
394 const char      *archive_format_name(struct archive *);
395 int              archive_format(struct archive *);
396 void             archive_set_error(struct archive *, int _err, const char *fmt, ...);
397
398 #ifdef __cplusplus
399 }
400 #endif
401
402 #endif /* !ARCHIVE_H_INCLUDED */