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