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