1 /*- 2 * Copyright (c) 2003-2010 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 26 #ifndef ARCHIVE_H_INCLUDED 27 #define ARCHIVE_H_INCLUDED 28 29 /* 30 * The version number is expressed as a single integer that makes it 31 * easy to compare versions at build time: for version a.b.c, the 32 * version number is printf("%d%03d%03d",a,b,c). For example, if you 33 * know your application requires version 2.12.108 or later, you can 34 * assert that ARCHIVE_VERSION_NUMBER >= 2012108. 35 */ 36 /* Note: Compiler will complain if this does not match archive_entry.h! */ 37 #define ARCHIVE_VERSION_NUMBER 3008009 38 39 #include <sys/stat.h> 40 #include <stddef.h> /* for wchar_t */ 41 #include <stdio.h> /* For FILE * */ 42 #if ARCHIVE_VERSION_NUMBER < 4000000 43 /* time_t is slated to be removed from public includes in 4.0 */ 44 #include <time.h> /* For time_t */ 45 #endif 46 47 /* 48 * Note: archive.h is for use outside of libarchive; the configuration 49 * headers (config.h, archive_platform.h, etc.) are purely internal. 50 * Do NOT use HAVE_XXX configuration macros to control the behavior of 51 * this header! If you must conditionalize, use predefined compiler and/or 52 * platform macros. 53 */ 54 #if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 55 # include <stdint.h> 56 #elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) && !defined(_SCO_DS) && !defined(__osf__) && !defined(__CLANG_INTTYPES_H) 57 # include <inttypes.h> 58 #endif 59 60 /* Get appropriate definitions of 64-bit integer */ 61 #if !defined(__LA_INT64_T_DEFINED) 62 /* Older code relied on the __LA_INT64_T macro; after 4.0 we'll switch to the typedef exclusively. */ 63 # if ARCHIVE_VERSION_NUMBER < 4000000 64 #define __LA_INT64_T la_int64_t 65 # endif 66 #define __LA_INT64_T_DEFINED 67 # if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) 68 typedef __int64 la_int64_t; 69 typedef unsigned __int64 la_uint64_t; 70 # else 71 # include <unistd.h> /* ssize_t */ 72 # if defined(_SCO_DS) || defined(__osf__) 73 typedef long long la_int64_t; 74 typedef unsigned long long la_uint64_t; 75 # else 76 typedef int64_t la_int64_t; 77 typedef uint64_t la_uint64_t; 78 # endif 79 # endif 80 #endif 81 82 /* The la_ssize_t should match the type used in 'struct stat' */ 83 #if !defined(__LA_SSIZE_T_DEFINED) 84 /* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */ 85 # if ARCHIVE_VERSION_NUMBER < 4000000 86 #define __LA_SSIZE_T la_ssize_t 87 # endif 88 #define __LA_SSIZE_T_DEFINED 89 # if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__) 90 # if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) 91 typedef ssize_t la_ssize_t; 92 # elif defined(_WIN64) 93 typedef __int64 la_ssize_t; 94 # else 95 typedef long la_ssize_t; 96 # endif 97 # else 98 # include <unistd.h> /* ssize_t */ 99 typedef ssize_t la_ssize_t; 100 # endif 101 #endif 102 103 #if ARCHIVE_VERSION_NUMBER < 4000000 104 /* Use the platform types for time_t */ 105 #define __LA_TIME_T time_t 106 #else 107 /* Use 64-bits integer types for time_t */ 108 #define __LA_TIME_T la_int64_t 109 #endif 110 111 #if ARCHIVE_VERSION_NUMBER < 4000000 112 /* Use the platform types for dev_t */ 113 #define __LA_DEV_T dev_t 114 #else 115 /* Use 64-bits integer types for dev_t */ 116 #define __LA_DEV_T la_int64_t 117 #endif 118 119 /* Large file support for Android */ 120 #if defined(__LIBARCHIVE_BUILD) && defined(__ANDROID__) 121 #include "android_lf.h" 122 #endif 123 124 /* 125 * On Windows, define LIBARCHIVE_STATIC if you're building or using a 126 * .lib. The default here assumes you're building a DLL. Only 127 * libarchive source should ever define __LIBARCHIVE_BUILD. 128 */ 129 #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) 130 # ifdef __LIBARCHIVE_BUILD 131 # ifdef __GNUC__ 132 # define __LA_DECL __attribute__((dllexport)) extern 133 # else 134 # define __LA_DECL __declspec(dllexport) 135 # endif 136 # else 137 # ifdef __GNUC__ 138 # define __LA_DECL 139 # else 140 # define __LA_DECL __declspec(dllimport) 141 # endif 142 # endif 143 #elif defined __LIBARCHIVE_ENABLE_VISIBILITY 144 # define __LA_DECL __attribute__((visibility("default"))) 145 #else 146 /* Static libraries or non-Windows needs no special declaration. */ 147 # define __LA_DECL 148 #endif 149 150 #if defined(__GNUC__) && __GNUC__ >= 3 && !defined(__MINGW32__) 151 #define __LA_PRINTF(fmtarg, firstvararg) \ 152 __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 153 #else 154 #define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ 155 #endif 156 157 #if defined(__GNUC__) && (__GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ >= 1)) 158 # define __LA_DEPRECATED __attribute__((deprecated)) 159 #else 160 # define __LA_DEPRECATED 161 #endif 162 163 #ifdef __cplusplus 164 extern "C" { 165 #endif 166 167 /* 168 * The version number is provided as both a macro and a function. 169 * The macro identifies the installed header; the function identifies 170 * the library version (which may not be the same if you're using a 171 * dynamically-linked version of the library). Of course, if the 172 * header and library are very different, you should expect some 173 * strangeness. Don't do that. 174 */ 175 __LA_DECL int archive_version_number(void); 176 177 /* 178 * Textual name/version of the library, useful for version displays. 179 */ 180 #define ARCHIVE_VERSION_ONLY_STRING "3.8.9" 181 #define ARCHIVE_VERSION_STRING "libarchive " ARCHIVE_VERSION_ONLY_STRING 182 __LA_DECL const char * archive_version_string(void); 183 184 /* 185 * Detailed textual name/version of the library and its dependencies. 186 * This has the form: 187 * "libarchive x.y.z zlib/a.b.c liblzma/d.e.f ... etc ..." 188 * the list of libraries described here will vary depending on how 189 * libarchive was compiled. 190 */ 191 __LA_DECL const char * archive_version_details(void); 192 193 /* 194 * Returns NULL if libarchive was compiled without the associated library. 195 * Otherwise, returns the version number that libarchive was compiled 196 * against. 197 */ 198 __LA_DECL const char * archive_zlib_version(void); 199 __LA_DECL const char * archive_liblzma_version(void); 200 __LA_DECL const char * archive_bzlib_version(void); 201 __LA_DECL const char * archive_liblz4_version(void); 202 __LA_DECL const char * archive_libzstd_version(void); 203 __LA_DECL const char * archive_liblzo2_version(void); 204 __LA_DECL const char * archive_libexpat_version(void); 205 __LA_DECL const char * archive_libbsdxml_version(void); 206 __LA_DECL const char * archive_libxml2_version(void); 207 __LA_DECL const char * archive_mbedtls_version(void); 208 __LA_DECL const char * archive_nettle_version(void); 209 __LA_DECL const char * archive_openssl_version(void); 210 __LA_DECL const char * archive_libmd_version(void); 211 __LA_DECL const char * archive_commoncrypto_version(void); 212 __LA_DECL const char * archive_cng_version(void); 213 #if ARCHIVE_VERSION_NUMBER < 4000000 214 __LA_DECL const char * archive_wincrypt_version(void); 215 #endif 216 __LA_DECL const char * archive_librichacl_version(void); 217 __LA_DECL const char * archive_libacl_version(void); 218 __LA_DECL const char * archive_libattr_version(void); 219 __LA_DECL const char * archive_libiconv_version(void); 220 __LA_DECL const char * archive_libpcre_version(void); 221 __LA_DECL const char * archive_libpcre2_version(void); 222 223 /* Declare our basic types. */ 224 struct archive; 225 struct archive_entry; 226 227 /* 228 * Error codes: Use archive_errno() and archive_error_string() 229 * to retrieve details. Unless specified otherwise, all functions 230 * that return 'int' use these codes. 231 */ 232 #define ARCHIVE_EOF 1 /* Found end of archive. */ 233 #define ARCHIVE_OK 0 /* Operation was successful. */ 234 #define ARCHIVE_RETRY (-10) /* Retry might succeed. */ 235 #define ARCHIVE_WARN (-20) /* Partial success. */ 236 /* For example, if write_header "fails", then you can't push data. */ 237 #define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ 238 /* But if write_header is "fatal," then this archive is dead and useless. */ 239 #define ARCHIVE_FATAL (-30) /* No more operations are possible. */ 240 241 /* 242 * As far as possible, archive_errno returns standard platform errno codes. 243 * Of course, the details vary by platform, so the actual definitions 244 * here are stored in "archive_platform.h". The symbols are listed here 245 * for reference; as a rule, clients should not need to know the exact 246 * platform-dependent error code. 247 */ 248 /* Unrecognized or invalid file format. */ 249 /* #define ARCHIVE_ERRNO_FILE_FORMAT */ 250 /* Illegal usage of the library. */ 251 /* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ 252 /* Unknown or unclassified error. */ 253 /* #define ARCHIVE_ERRNO_MISC */ 254 255 /* 256 * Callbacks are invoked to automatically read/skip/write/open/close the 257 * archive. You can provide your own for complex tasks (like breaking 258 * archives across multiple tapes) or use standard ones built into the 259 * library. 260 */ 261 262 /* Returns pointer and size of next block of data from archive. */ 263 typedef la_ssize_t archive_read_callback(struct archive *, 264 void *_client_data, const void **_buffer); 265 266 /* Skips at most request bytes from archive and returns the skipped amount. 267 * This may skip fewer bytes than requested; it may even skip zero bytes. 268 * If you do skip fewer bytes than requested, libarchive will invoke your 269 * read callback and discard data as necessary to make up the full skip. 270 */ 271 typedef la_int64_t archive_skip_callback(struct archive *, 272 void *_client_data, la_int64_t request); 273 274 /* Seeks to specified location in the file and returns the position. 275 * Whence values are SEEK_SET, SEEK_CUR, SEEK_END from stdio.h. 276 * Return ARCHIVE_FATAL if the seek fails for any reason. 277 */ 278 typedef la_int64_t archive_seek_callback(struct archive *, 279 void *_client_data, la_int64_t offset, int whence); 280 281 /* Returns size actually written, zero on EOF, -1 on error. */ 282 typedef la_ssize_t archive_write_callback(struct archive *, 283 void *_client_data, 284 const void *_buffer, size_t _length); 285 286 typedef int archive_open_callback(struct archive *, void *_client_data); 287 288 typedef int archive_close_callback(struct archive *, void *_client_data); 289 290 typedef int archive_free_callback(struct archive *, void *_client_data); 291 292 /* Switches from one client data object to the next/prev client data object. 293 * This is useful for reading from different data blocks such as a set of files 294 * that make up one large file. 295 */ 296 typedef int archive_switch_callback(struct archive *, void *_client_data1, 297 void *_client_data2); 298 299 /* 300 * Returns a passphrase used for encryption or decryption, NULL on nothing 301 * to do and give it up. 302 */ 303 typedef const char *archive_passphrase_callback(struct archive *, 304 void *_client_data); 305 306 /* 307 * Codes to identify various stream filters. 308 */ 309 #define ARCHIVE_FILTER_NONE 0 310 #define ARCHIVE_FILTER_GZIP 1 311 #define ARCHIVE_FILTER_BZIP2 2 312 #define ARCHIVE_FILTER_COMPRESS 3 313 #define ARCHIVE_FILTER_PROGRAM 4 314 #define ARCHIVE_FILTER_LZMA 5 315 #define ARCHIVE_FILTER_XZ 6 316 #define ARCHIVE_FILTER_UU 7 317 #define ARCHIVE_FILTER_RPM 8 318 #define ARCHIVE_FILTER_LZIP 9 319 #define ARCHIVE_FILTER_LRZIP 10 320 #define ARCHIVE_FILTER_LZOP 11 321 #define ARCHIVE_FILTER_GRZIP 12 322 #define ARCHIVE_FILTER_LZ4 13 323 #define ARCHIVE_FILTER_ZSTD 14 324 325 #if ARCHIVE_VERSION_NUMBER < 4000000 326 #define ARCHIVE_COMPRESSION_NONE ARCHIVE_FILTER_NONE 327 #define ARCHIVE_COMPRESSION_GZIP ARCHIVE_FILTER_GZIP 328 #define ARCHIVE_COMPRESSION_BZIP2 ARCHIVE_FILTER_BZIP2 329 #define ARCHIVE_COMPRESSION_COMPRESS ARCHIVE_FILTER_COMPRESS 330 #define ARCHIVE_COMPRESSION_PROGRAM ARCHIVE_FILTER_PROGRAM 331 #define ARCHIVE_COMPRESSION_LZMA ARCHIVE_FILTER_LZMA 332 #define ARCHIVE_COMPRESSION_XZ ARCHIVE_FILTER_XZ 333 #define ARCHIVE_COMPRESSION_UU ARCHIVE_FILTER_UU 334 #define ARCHIVE_COMPRESSION_RPM ARCHIVE_FILTER_RPM 335 #define ARCHIVE_COMPRESSION_LZIP ARCHIVE_FILTER_LZIP 336 #define ARCHIVE_COMPRESSION_LRZIP ARCHIVE_FILTER_LRZIP 337 #endif 338 339 /* 340 * Codes returned by archive_format. 341 * 342 * Top 16 bits identifies the format family (e.g., "tar"); lower 343 * 16 bits indicate the variant. This is updated by read_next_header. 344 * Note that the lower 16 bits will often vary from entry to entry. 345 * In some cases, this variation occurs as libarchive learns more about 346 * the archive (for example, later entries might utilize extensions that 347 * weren't necessary earlier in the archive; in this case, libarchive 348 * will change the format code to indicate the extended format that 349 * was used). In other cases, it's because different tools have 350 * modified the archive and so different parts of the archive 351 * actually have slightly different formats. (Both tar and cpio store 352 * format codes in each entry, so it is quite possible for each 353 * entry to be in a different format.) 354 */ 355 #define ARCHIVE_FORMAT_BASE_MASK 0xff0000 356 #define ARCHIVE_FORMAT_CPIO 0x10000 357 #define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) 358 #define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) 359 #define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) 360 #define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) 361 #define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) 362 #define ARCHIVE_FORMAT_CPIO_AFIO_LARGE (ARCHIVE_FORMAT_CPIO | 6) 363 #define ARCHIVE_FORMAT_CPIO_PWB (ARCHIVE_FORMAT_CPIO | 7) 364 #define ARCHIVE_FORMAT_SHAR 0x20000 365 #define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) 366 #define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) 367 #define ARCHIVE_FORMAT_TAR 0x30000 368 #define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) 369 #define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) 370 #define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) 371 #define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) 372 #define ARCHIVE_FORMAT_ISO9660 0x40000 373 #define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) 374 #define ARCHIVE_FORMAT_ZIP 0x50000 375 #define ARCHIVE_FORMAT_EMPTY 0x60000 376 #define ARCHIVE_FORMAT_AR 0x70000 377 #define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) 378 #define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) 379 #define ARCHIVE_FORMAT_MTREE 0x80000 380 #define ARCHIVE_FORMAT_RAW 0x90000 381 #define ARCHIVE_FORMAT_XAR 0xA0000 382 #define ARCHIVE_FORMAT_LHA 0xB0000 383 #define ARCHIVE_FORMAT_CAB 0xC0000 384 #define ARCHIVE_FORMAT_RAR 0xD0000 385 #define ARCHIVE_FORMAT_7ZIP 0xE0000 386 #define ARCHIVE_FORMAT_WARC 0xF0000 387 #define ARCHIVE_FORMAT_RAR_V5 0x100000 388 389 /* 390 * Codes returned by archive_read_format_capabilities(). 391 * 392 * This list can be extended with values between 0 and 0xffff. 393 * The original purpose of this list was to let different archive 394 * format readers expose their general capabilities in terms of 395 * encryption. 396 */ 397 #define ARCHIVE_READ_FORMAT_CAPS_NONE (0) /* no special capabilities */ 398 #define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_DATA (1<<0) /* reader can detect encrypted data */ 399 #define ARCHIVE_READ_FORMAT_CAPS_ENCRYPT_METADATA (1<<1) /* reader can detect encryptable metadata (pathname, mtime, etc.) */ 400 401 /* 402 * Codes returned by archive_read_has_encrypted_entries(). 403 * 404 * In case the archive does not support encryption detection at all 405 * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. If the reader 406 * for some other reason (e.g. not enough bytes read) cannot say if 407 * there are encrypted entries, ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW 408 * is returned. 409 */ 410 #define ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED -2 411 #define ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW -1 412 413 /*- 414 * Basic outline for reading an archive: 415 * 1) Ask archive_read_new for an archive reader object. 416 * 2) Update any global properties as appropriate. 417 * In particular, you'll certainly want to call appropriate 418 * archive_read_support_XXX functions. 419 * 3) Call archive_read_open_XXX to open the archive 420 * 4) Repeatedly call archive_read_next_header to get information about 421 * successive archive entries. Call archive_read_data to extract 422 * data for entries of interest. 423 * 5) Call archive_read_free to end processing. 424 */ 425 __LA_DECL struct archive *archive_read_new(void); 426 427 /* 428 * The archive_read_support_XXX calls enable auto-detect for this 429 * archive handle. They also link in the necessary support code. 430 * For example, if you don't want bzlib linked in, don't invoke 431 * support_compression_bzip2(). The "all" functions provide the 432 * obvious shorthand. 433 */ 434 435 #if ARCHIVE_VERSION_NUMBER < 4000000 436 __LA_DECL int archive_read_support_compression_all(struct archive *) 437 __LA_DEPRECATED; 438 __LA_DECL int archive_read_support_compression_bzip2(struct archive *) 439 __LA_DEPRECATED; 440 __LA_DECL int archive_read_support_compression_compress(struct archive *) 441 __LA_DEPRECATED; 442 __LA_DECL int archive_read_support_compression_gzip(struct archive *) 443 __LA_DEPRECATED; 444 __LA_DECL int archive_read_support_compression_lzip(struct archive *) 445 __LA_DEPRECATED; 446 __LA_DECL int archive_read_support_compression_lzma(struct archive *) 447 __LA_DEPRECATED; 448 __LA_DECL int archive_read_support_compression_none(struct archive *) 449 __LA_DEPRECATED; 450 __LA_DECL int archive_read_support_compression_program(struct archive *, 451 const char *command) __LA_DEPRECATED; 452 __LA_DECL int archive_read_support_compression_program_signature 453 (struct archive *, const char *, 454 const void * /* match */, size_t) __LA_DEPRECATED; 455 456 __LA_DECL int archive_read_support_compression_rpm(struct archive *) 457 __LA_DEPRECATED; 458 __LA_DECL int archive_read_support_compression_uu(struct archive *) 459 __LA_DEPRECATED; 460 __LA_DECL int archive_read_support_compression_xz(struct archive *) 461 __LA_DEPRECATED; 462 #endif 463 464 __LA_DECL int archive_read_support_filter_all(struct archive *); 465 __LA_DECL int archive_read_support_filter_by_code(struct archive *, int); 466 __LA_DECL int archive_read_support_filter_bzip2(struct archive *); 467 __LA_DECL int archive_read_support_filter_compress(struct archive *); 468 __LA_DECL int archive_read_support_filter_gzip(struct archive *); 469 __LA_DECL int archive_read_support_filter_grzip(struct archive *); 470 __LA_DECL int archive_read_support_filter_lrzip(struct archive *); 471 __LA_DECL int archive_read_support_filter_lz4(struct archive *); 472 __LA_DECL int archive_read_support_filter_lzip(struct archive *); 473 __LA_DECL int archive_read_support_filter_lzma(struct archive *); 474 __LA_DECL int archive_read_support_filter_lzop(struct archive *); 475 __LA_DECL int archive_read_support_filter_none(struct archive *); 476 __LA_DECL int archive_read_support_filter_program(struct archive *, 477 const char *command); 478 __LA_DECL int archive_read_support_filter_program_signature 479 (struct archive *, const char * /* cmd */, 480 const void * /* match */, size_t); 481 __LA_DECL int archive_read_support_filter_rpm(struct archive *); 482 __LA_DECL int archive_read_support_filter_uu(struct archive *); 483 __LA_DECL int archive_read_support_filter_xz(struct archive *); 484 __LA_DECL int archive_read_support_filter_zstd(struct archive *); 485 486 __LA_DECL int archive_read_support_format_7zip(struct archive *); 487 __LA_DECL int archive_read_support_format_all(struct archive *); 488 __LA_DECL int archive_read_support_format_ar(struct archive *); 489 __LA_DECL int archive_read_support_format_by_code(struct archive *, int); 490 __LA_DECL int archive_read_support_format_cab(struct archive *); 491 __LA_DECL int archive_read_support_format_cpio(struct archive *); 492 __LA_DECL int archive_read_support_format_empty(struct archive *); 493 /* archive_read_support_format_gnutar() is an alias for historical reasons 494 * of archive_read_support_format_tar(). */ 495 __LA_DECL int archive_read_support_format_gnutar(struct archive *); 496 __LA_DECL int archive_read_support_format_iso9660(struct archive *); 497 __LA_DECL int archive_read_support_format_lha(struct archive *); 498 __LA_DECL int archive_read_support_format_mtree(struct archive *); 499 __LA_DECL int archive_read_support_format_rar(struct archive *); 500 __LA_DECL int archive_read_support_format_rar5(struct archive *); 501 __LA_DECL int archive_read_support_format_raw(struct archive *); 502 __LA_DECL int archive_read_support_format_tar(struct archive *); 503 __LA_DECL int archive_read_support_format_warc(struct archive *); 504 __LA_DECL int archive_read_support_format_xar(struct archive *); 505 /* archive_read_support_format_zip() enables both streamable and seekable 506 * zip readers. */ 507 __LA_DECL int archive_read_support_format_zip(struct archive *); 508 /* Reads Zip archives as stream from beginning to end. Doesn't 509 * correctly handle SFX ZIP files or ZIP archives that have been modified 510 * in-place. */ 511 __LA_DECL int archive_read_support_format_zip_streamable(struct archive *); 512 /* Reads starting from central directory; requires seekable input. */ 513 __LA_DECL int archive_read_support_format_zip_seekable(struct archive *); 514 515 /* Functions to manually set the format and filters to be used. This is 516 * useful to bypass the bidding process when the format and filters to use 517 * is known in advance. 518 */ 519 __LA_DECL int archive_read_set_format(struct archive *, int); 520 __LA_DECL int archive_read_append_filter(struct archive *, int); 521 __LA_DECL int archive_read_append_filter_program(struct archive *, 522 const char *); 523 __LA_DECL int archive_read_append_filter_program_signature 524 (struct archive *, const char *, const void * /* match */, size_t); 525 526 /* Set various callbacks. */ 527 __LA_DECL int archive_read_set_open_callback(struct archive *, 528 archive_open_callback *); 529 __LA_DECL int archive_read_set_read_callback(struct archive *, 530 archive_read_callback *); 531 __LA_DECL int archive_read_set_seek_callback(struct archive *, 532 archive_seek_callback *); 533 __LA_DECL int archive_read_set_skip_callback(struct archive *, 534 archive_skip_callback *); 535 __LA_DECL int archive_read_set_close_callback(struct archive *, 536 archive_close_callback *); 537 /* Callback used to switch between one data object to the next */ 538 __LA_DECL int archive_read_set_switch_callback(struct archive *, 539 archive_switch_callback *); 540 541 /* This sets the first data object. */ 542 __LA_DECL int archive_read_set_callback_data(struct archive *, void *); 543 /* This sets data object at specified index */ 544 __LA_DECL int archive_read_set_callback_data2(struct archive *, void *, 545 unsigned int); 546 /* This adds a data object at the specified index. */ 547 __LA_DECL int archive_read_add_callback_data(struct archive *, void *, 548 unsigned int); 549 /* This appends a data object to the end of list */ 550 __LA_DECL int archive_read_append_callback_data(struct archive *, void *); 551 /* This prepends a data object to the beginning of list */ 552 __LA_DECL int archive_read_prepend_callback_data(struct archive *, void *); 553 554 /* Opening freezes the callbacks. */ 555 __LA_DECL int archive_read_open1(struct archive *); 556 557 /* Convenience wrappers around the above. */ 558 __LA_DECL int archive_read_open(struct archive *, void *_client_data, 559 archive_open_callback *, archive_read_callback *, 560 archive_close_callback *); 561 __LA_DECL int archive_read_open2(struct archive *, void *_client_data, 562 archive_open_callback *, archive_read_callback *, 563 archive_skip_callback *, archive_close_callback *); 564 565 /* 566 * A variety of shortcuts that invoke archive_read_open() with 567 * canned callbacks suitable for common situations. The ones that 568 * accept a block size handle tape blocking correctly. 569 */ 570 /* Use this if you know the filename. Note: NULL indicates stdin. */ 571 __LA_DECL int archive_read_open_filename(struct archive *, 572 const char *_filename, size_t _block_size); 573 /* Use this for reading multivolume files by filenames. 574 * NOTE: Must be NULL terminated. Sorting is NOT done. */ 575 __LA_DECL int archive_read_open_filenames(struct archive *, 576 const char **_filenames, size_t _block_size); 577 __LA_DECL int archive_read_open_filename_w(struct archive *, 578 const wchar_t *_filename, size_t _block_size); 579 #if defined(_WIN32) && !defined(__CYGWIN__) 580 __LA_DECL int archive_read_open_filenames_w(struct archive *, 581 const wchar_t **_filenames, size_t _block_size); 582 #endif 583 /* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ 584 __LA_DECL int archive_read_open_file(struct archive *, 585 const char *_filename, size_t _block_size) __LA_DEPRECATED; 586 /* Read an archive that's stored in memory. */ 587 __LA_DECL int archive_read_open_memory(struct archive *, 588 const void * buff, size_t size); 589 /* A more involved version that is only used for internal testing. */ 590 __LA_DECL int archive_read_open_memory2(struct archive *a, const void *buff, 591 size_t size, size_t read_size); 592 /* Read an archive that's already open, using the file descriptor. */ 593 __LA_DECL int archive_read_open_fd(struct archive *, int _fd, 594 size_t _block_size); 595 /* Read an archive that's already open, using a FILE *. */ 596 /* Note: DO NOT use this with tape drives. */ 597 __LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); 598 599 /* Parses and returns next entry header. */ 600 __LA_DECL int archive_read_next_header(struct archive *, 601 struct archive_entry **); 602 603 /* Parses and returns next entry header using the archive_entry passed in */ 604 __LA_DECL int archive_read_next_header2(struct archive *, 605 struct archive_entry *); 606 607 /* 608 * Retrieve the byte offset in UNCOMPRESSED data where last-read 609 * header started. 610 */ 611 __LA_DECL la_int64_t archive_read_header_position(struct archive *); 612 613 /* 614 * Returns 1 if the archive contains at least one encrypted entry. 615 * If the archive format not support encryption at all 616 * ARCHIVE_READ_FORMAT_ENCRYPTION_UNSUPPORTED is returned. 617 * If for any other reason (e.g. not enough data read so far) 618 * we cannot say whether there are encrypted entries, then 619 * ARCHIVE_READ_FORMAT_ENCRYPTION_DONT_KNOW is returned. 620 * In general, this function will return values below zero when the 621 * reader is uncertain or totally incapable of encryption support. 622 * When this function returns 0 you can be sure that the reader 623 * supports encryption detection but no encrypted entries have 624 * been found yet. 625 * 626 * NOTE: If the metadata/header of an archive is also encrypted, you 627 * cannot rely on the number of encrypted entries. That is why this 628 * function does not return the number of encrypted entries but# 629 * just shows that there are some. 630 */ 631 __LA_DECL int archive_read_has_encrypted_entries(struct archive *); 632 633 /* 634 * Returns a bitmask of capabilities that are supported by the archive format reader. 635 * If the reader has no special capabilities, ARCHIVE_READ_FORMAT_CAPS_NONE is returned. 636 */ 637 __LA_DECL int archive_read_format_capabilities(struct archive *); 638 639 /* Read data from the body of an entry. Similar to read(2). */ 640 __LA_DECL la_ssize_t archive_read_data(struct archive *, 641 void *, size_t); 642 643 /* Seek within the body of an entry. Similar to lseek(2). */ 644 __LA_DECL la_int64_t archive_seek_data(struct archive *, la_int64_t, int); 645 646 /* 647 * A zero-copy version of archive_read_data that also exposes the file offset 648 * of each returned block. Note that the client has no way to specify 649 * the desired size of the block. The API does guarantee that offsets will 650 * be strictly increasing and that returned blocks will not overlap. 651 */ 652 __LA_DECL int archive_read_data_block(struct archive *a, 653 const void **buff, size_t *size, la_int64_t *offset); 654 655 /*- 656 * Some convenience functions that are built on archive_read_data: 657 * 'skip': skips entire entry 658 * 'into_fd': writes data to specified filedes 659 */ 660 __LA_DECL int archive_read_data_skip(struct archive *); 661 __LA_DECL int archive_read_data_into_fd(struct archive *, int fd); 662 663 /* 664 * Set read options. 665 */ 666 /* Apply option to the format only. */ 667 __LA_DECL int archive_read_set_format_option(struct archive *_a, 668 const char *m, const char *o, 669 const char *v); 670 /* Apply option to the filter only. */ 671 __LA_DECL int archive_read_set_filter_option(struct archive *_a, 672 const char *m, const char *o, 673 const char *v); 674 /* Apply option to both the format and the filter. */ 675 __LA_DECL int archive_read_set_option(struct archive *_a, 676 const char *m, const char *o, 677 const char *v); 678 /* Apply option string to both the format and the filter. */ 679 __LA_DECL int archive_read_set_options(struct archive *_a, 680 const char *opts); 681 682 /* 683 * Add a decryption passphrase. 684 */ 685 __LA_DECL int archive_read_add_passphrase(struct archive *, const char *); 686 __LA_DECL int archive_read_set_passphrase_callback(struct archive *, 687 void *client_data, archive_passphrase_callback *); 688 689 690 /*- 691 * Convenience function to recreate the current entry (whose header 692 * has just been read) on disk. 693 * 694 * This does quite a bit more than just copy data to disk. It also: 695 * - Creates intermediate directories as required. 696 * - Manages directory permissions: non-writable directories will 697 * be initially created with write permission enabled; when the 698 * archive is closed, dir permissions are edited to the values specified 699 * in the archive. 700 * - Checks hardlinks: hardlinks will not be extracted unless the 701 * linked-to file was also extracted within the same session. (TODO) 702 */ 703 704 /* The "flags" argument selects optional behavior, 'OR' the flags you want. */ 705 706 /* Default: Do not try to set owner/group. */ 707 #define ARCHIVE_EXTRACT_OWNER (0x0001) 708 /* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ 709 #define ARCHIVE_EXTRACT_PERM (0x0002) 710 /* Default: Do not restore mtime/atime. */ 711 #define ARCHIVE_EXTRACT_TIME (0x0004) 712 /* Default: Replace existing files. */ 713 #define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) 714 /* Default: Try create first, unlink only if create fails with EEXIST. */ 715 #define ARCHIVE_EXTRACT_UNLINK (0x0010) 716 /* Default: Do not restore ACLs. */ 717 #define ARCHIVE_EXTRACT_ACL (0x0020) 718 /* Default: Do not restore fflags. */ 719 #define ARCHIVE_EXTRACT_FFLAGS (0x0040) 720 /* Default: Do not restore xattrs. */ 721 #define ARCHIVE_EXTRACT_XATTR (0x0080) 722 /* Default: Do not try to guard against extracts redirected by symlinks. */ 723 /* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ 724 #define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) 725 /* Default: Do not reject entries with '..' as path elements. */ 726 #define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) 727 /* Default: Create parent directories as needed. */ 728 #define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) 729 /* Default: Overwrite files, even if one on disk is newer. */ 730 #define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) 731 /* Detect blocks of 0 and write holes instead. */ 732 #define ARCHIVE_EXTRACT_SPARSE (0x1000) 733 /* Default: Do not restore Mac extended metadata. */ 734 /* This has no effect except on Mac OS. */ 735 #define ARCHIVE_EXTRACT_MAC_METADATA (0x2000) 736 /* Default: Use HFS+ compression if it was compressed. */ 737 /* This has no effect except on Mac OS v10.6 or later. */ 738 #define ARCHIVE_EXTRACT_NO_HFS_COMPRESSION (0x4000) 739 /* Default: Do not use HFS+ compression if it was not compressed. */ 740 /* This has no effect except on Mac OS v10.6 or later. */ 741 #define ARCHIVE_EXTRACT_HFS_COMPRESSION_FORCED (0x8000) 742 /* Default: Do not reject entries with absolute paths */ 743 #define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000) 744 /* Default: Do not clear no-change flags when unlinking object */ 745 #define ARCHIVE_EXTRACT_CLEAR_NOCHANGE_FFLAGS (0x20000) 746 /* Default: Do not extract atomically (using rename) */ 747 #define ARCHIVE_EXTRACT_SAFE_WRITES (0x40000) 748 749 __LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, 750 int flags); 751 __LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, 752 struct archive * /* dest */); 753 __LA_DECL void archive_read_extract_set_progress_callback(struct archive *, 754 void (*_progress_func)(void *), void *_user_data); 755 756 /* Record the dev/ino of a file that will not be written. This is 757 * generally set to the dev/ino of the archive being read. */ 758 __LA_DECL void archive_read_extract_set_skip_file(struct archive *, 759 la_int64_t, la_int64_t); 760 761 /* Close the file and release most resources. */ 762 __LA_DECL int archive_read_close(struct archive *); 763 /* Release all resources and destroy the object. */ 764 /* Note that archive_read_free will call archive_read_close for you. */ 765 __LA_DECL int archive_read_free(struct archive *); 766 #if ARCHIVE_VERSION_NUMBER < 4000000 767 /* Synonym for archive_read_free() for backwards compatibility. */ 768 __LA_DECL int archive_read_finish(struct archive *) __LA_DEPRECATED; 769 #endif 770 771 /*- 772 * To create an archive: 773 * 1) Ask archive_write_new for an archive writer object. 774 * 2) Set any global properties. In particular, you should set 775 * the compression and format to use. 776 * 3) Call archive_write_open to open the file (most people 777 * will use archive_write_open_file or archive_write_open_fd, 778 * which provide convenient canned I/O callbacks for you). 779 * 4) For each entry: 780 * - construct an appropriate struct archive_entry structure 781 * - archive_write_header to write the header 782 * - archive_write_data to write the entry data 783 * 5) archive_write_close to close the output 784 * 6) archive_write_free to cleanup the writer and release resources 785 */ 786 __LA_DECL struct archive *archive_write_new(void); 787 __LA_DECL int archive_write_set_bytes_per_block(struct archive *, 788 int bytes_per_block); 789 __LA_DECL int archive_write_get_bytes_per_block(struct archive *); 790 /* XXX This is badly misnamed; suggestions appreciated. XXX */ 791 __LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, 792 int bytes_in_last_block); 793 __LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); 794 795 /* The dev/ino of a file that won't be archived. This is used 796 * to avoid recursively adding an archive to itself. */ 797 __LA_DECL int archive_write_set_skip_file(struct archive *, 798 la_int64_t, la_int64_t); 799 800 #if ARCHIVE_VERSION_NUMBER < 4000000 801 __LA_DECL int archive_write_set_compression_bzip2(struct archive *) 802 __LA_DEPRECATED; 803 __LA_DECL int archive_write_set_compression_compress(struct archive *) 804 __LA_DEPRECATED; 805 __LA_DECL int archive_write_set_compression_gzip(struct archive *) 806 __LA_DEPRECATED; 807 __LA_DECL int archive_write_set_compression_lzip(struct archive *) 808 __LA_DEPRECATED; 809 __LA_DECL int archive_write_set_compression_lzma(struct archive *) 810 __LA_DEPRECATED; 811 __LA_DECL int archive_write_set_compression_none(struct archive *) 812 __LA_DEPRECATED; 813 __LA_DECL int archive_write_set_compression_program(struct archive *, 814 const char *cmd) __LA_DEPRECATED; 815 __LA_DECL int archive_write_set_compression_xz(struct archive *) 816 __LA_DEPRECATED; 817 #endif 818 819 /* A convenience function to set the filter based on the code. */ 820 __LA_DECL int archive_write_add_filter(struct archive *, int filter_code); 821 __LA_DECL int archive_write_add_filter_by_name(struct archive *, 822 const char *name); 823 __LA_DECL int archive_write_add_filter_b64encode(struct archive *); 824 __LA_DECL int archive_write_add_filter_bzip2(struct archive *); 825 __LA_DECL int archive_write_add_filter_compress(struct archive *); 826 __LA_DECL int archive_write_add_filter_grzip(struct archive *); 827 __LA_DECL int archive_write_add_filter_gzip(struct archive *); 828 __LA_DECL int archive_write_add_filter_lrzip(struct archive *); 829 __LA_DECL int archive_write_add_filter_lz4(struct archive *); 830 __LA_DECL int archive_write_add_filter_lzip(struct archive *); 831 __LA_DECL int archive_write_add_filter_lzma(struct archive *); 832 __LA_DECL int archive_write_add_filter_lzop(struct archive *); 833 __LA_DECL int archive_write_add_filter_none(struct archive *); 834 __LA_DECL int archive_write_add_filter_program(struct archive *, 835 const char *cmd); 836 __LA_DECL int archive_write_add_filter_uuencode(struct archive *); 837 __LA_DECL int archive_write_add_filter_xz(struct archive *); 838 __LA_DECL int archive_write_add_filter_zstd(struct archive *); 839 840 841 /* A convenience function to set the format based on the code or name. */ 842 __LA_DECL int archive_write_set_format(struct archive *, int format_code); 843 __LA_DECL int archive_write_set_format_by_name(struct archive *, 844 const char *name); 845 /* To minimize link pollution, use one or more of the following. */ 846 __LA_DECL int archive_write_set_format_7zip(struct archive *); 847 __LA_DECL int archive_write_set_format_ar_bsd(struct archive *); 848 __LA_DECL int archive_write_set_format_ar_svr4(struct archive *); 849 __LA_DECL int archive_write_set_format_cpio(struct archive *); 850 __LA_DECL int archive_write_set_format_cpio_bin(struct archive *); 851 __LA_DECL int archive_write_set_format_cpio_newc(struct archive *); 852 __LA_DECL int archive_write_set_format_cpio_odc(struct archive *); 853 __LA_DECL int archive_write_set_format_cpio_pwb(struct archive *); 854 __LA_DECL int archive_write_set_format_gnutar(struct archive *); 855 __LA_DECL int archive_write_set_format_iso9660(struct archive *); 856 __LA_DECL int archive_write_set_format_mtree(struct archive *); 857 __LA_DECL int archive_write_set_format_mtree_classic(struct archive *); 858 /* TODO: int archive_write_set_format_old_tar(struct archive *); */ 859 __LA_DECL int archive_write_set_format_pax(struct archive *); 860 __LA_DECL int archive_write_set_format_pax_restricted(struct archive *); 861 __LA_DECL int archive_write_set_format_raw(struct archive *); 862 __LA_DECL int archive_write_set_format_shar(struct archive *); 863 __LA_DECL int archive_write_set_format_shar_dump(struct archive *); 864 __LA_DECL int archive_write_set_format_ustar(struct archive *); 865 __LA_DECL int archive_write_set_format_v7tar(struct archive *); 866 __LA_DECL int archive_write_set_format_warc(struct archive *); 867 __LA_DECL int archive_write_set_format_xar(struct archive *); 868 __LA_DECL int archive_write_set_format_zip(struct archive *); 869 __LA_DECL int archive_write_set_format_filter_by_ext(struct archive *a, const char *filename); 870 __LA_DECL int archive_write_set_format_filter_by_ext_def(struct archive *a, const char *filename, const char * def_ext); 871 __LA_DECL int archive_write_zip_set_compression_deflate(struct archive *); 872 __LA_DECL int archive_write_zip_set_compression_store(struct archive *); 873 __LA_DECL int archive_write_zip_set_compression_lzma(struct archive *); 874 __LA_DECL int archive_write_zip_set_compression_xz(struct archive *); 875 __LA_DECL int archive_write_zip_set_compression_bzip2(struct archive *); 876 __LA_DECL int archive_write_zip_set_compression_zstd(struct archive *); 877 /* Deprecated; use archive_write_open2 instead */ 878 __LA_DECL int archive_write_open(struct archive *, void *, 879 archive_open_callback *, archive_write_callback *, 880 archive_close_callback *); 881 __LA_DECL int archive_write_open2(struct archive *, void *, 882 archive_open_callback *, archive_write_callback *, 883 archive_close_callback *, archive_free_callback *); 884 __LA_DECL int archive_write_open_fd(struct archive *, int _fd); 885 __LA_DECL int archive_write_open_filename(struct archive *, const char *_file); 886 __LA_DECL int archive_write_open_filename_w(struct archive *, 887 const wchar_t *_file); 888 /* A deprecated synonym for archive_write_open_filename() */ 889 __LA_DECL int archive_write_open_file(struct archive *, const char *_file) 890 __LA_DEPRECATED; 891 __LA_DECL int archive_write_open_FILE(struct archive *, FILE *); 892 /* _buffSize is the size of the buffer, _used refers to a variable that 893 * will be updated after each write into the buffer. */ 894 __LA_DECL int archive_write_open_memory(struct archive *, 895 void *_buffer, size_t _buffSize, size_t *_used); 896 897 /* 898 * Note that the library will truncate writes beyond the size provided 899 * to archive_write_header or pad if the provided data is short. 900 */ 901 __LA_DECL int archive_write_header(struct archive *, 902 struct archive_entry *); 903 __LA_DECL la_ssize_t archive_write_data(struct archive *, 904 const void *, size_t); 905 906 /* This interface is currently only available for archive_write_disk handles. */ 907 __LA_DECL la_ssize_t archive_write_data_block(struct archive *, 908 const void *, size_t, la_int64_t); 909 910 __LA_DECL int archive_write_finish_entry(struct archive *); 911 __LA_DECL int archive_write_close(struct archive *); 912 /* Marks the archive as FATAL so that a subsequent free() operation 913 * won't try to close() cleanly. Provides a fast abort capability 914 * when the client discovers that things have gone wrong. */ 915 __LA_DECL int archive_write_fail(struct archive *); 916 /* This can fail if the archive wasn't already closed, in which case 917 * archive_write_free() will implicitly call archive_write_close(). */ 918 __LA_DECL int archive_write_free(struct archive *); 919 #if ARCHIVE_VERSION_NUMBER < 4000000 920 /* Synonym for archive_write_free() for backwards compatibility. */ 921 __LA_DECL int archive_write_finish(struct archive *) __LA_DEPRECATED; 922 #endif 923 924 /* 925 * Set write options. 926 */ 927 /* Apply option to the format only. */ 928 __LA_DECL int archive_write_set_format_option(struct archive *_a, 929 const char *m, const char *o, 930 const char *v); 931 /* Apply option to the filter only. */ 932 __LA_DECL int archive_write_set_filter_option(struct archive *_a, 933 const char *m, const char *o, 934 const char *v); 935 /* Apply option to both the format and the filter. */ 936 __LA_DECL int archive_write_set_option(struct archive *_a, 937 const char *m, const char *o, 938 const char *v); 939 /* Apply option string to both the format and the filter. */ 940 __LA_DECL int archive_write_set_options(struct archive *_a, 941 const char *opts); 942 943 /* 944 * Set an encryption passphrase. 945 */ 946 __LA_DECL int archive_write_set_passphrase(struct archive *_a, const char *p); 947 __LA_DECL int archive_write_set_passphrase_callback(struct archive *, 948 void *client_data, archive_passphrase_callback *); 949 950 /*- 951 * ARCHIVE_WRITE_DISK API 952 * 953 * To create objects on disk: 954 * 1) Ask archive_write_disk_new for a new archive_write_disk object. 955 * 2) Set any global properties. In particular, you probably 956 * want to set the options. 957 * 3) For each entry: 958 * - construct an appropriate struct archive_entry structure 959 * - archive_write_header to create the file/dir/etc on disk 960 * - archive_write_data to write the entry data 961 * 4) archive_write_free to cleanup the writer and release resources 962 * 963 * In particular, you can use this in conjunction with archive_read() 964 * to pull entries out of an archive and create them on disk. 965 */ 966 __LA_DECL struct archive *archive_write_disk_new(void); 967 /* This file will not be overwritten. */ 968 __LA_DECL int archive_write_disk_set_skip_file(struct archive *, 969 la_int64_t, la_int64_t); 970 /* Set flags to control how the next item gets created. 971 * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */ 972 __LA_DECL int archive_write_disk_set_options(struct archive *, 973 int flags); 974 /* 975 * The lookup functions are given uname/uid (or gname/gid) pairs and 976 * return a uid (gid) suitable for this system. These are used for 977 * restoring ownership and for setting ACLs. The default functions 978 * are naive, they just return the uid/gid. These are small, so reasonable 979 * for applications that don't need to preserve ownership; they 980 * are probably also appropriate for applications that are doing 981 * same-system backup and restore. 982 */ 983 /* 984 * The "standard" lookup functions use common system calls to lookup 985 * the uname/gname, falling back to the uid/gid if the names can't be 986 * found. They cache lookups and are reasonably fast, but can be very 987 * large, so they are not used unless you ask for them. In 988 * particular, these match the specifications of POSIX "pax" and old 989 * POSIX "tar". 990 */ 991 __LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); 992 /* 993 * If neither the default (naive) nor the standard (big) functions suit 994 * your needs, you can write your own and register them. Be sure to 995 * include a cleanup function if you have allocated private data. 996 */ 997 __LA_DECL int archive_write_disk_set_group_lookup(struct archive *, 998 void * /* private_data */, 999 la_int64_t (*)(void *, const char *, la_int64_t), 1000 void (* /* cleanup */)(void *)); 1001 __LA_DECL int archive_write_disk_set_user_lookup(struct archive *, 1002 void * /* private_data */, 1003 la_int64_t (*)(void *, const char *, la_int64_t), 1004 void (* /* cleanup */)(void *)); 1005 __LA_DECL la_int64_t archive_write_disk_gid(struct archive *, const char *, la_int64_t); 1006 __LA_DECL la_int64_t archive_write_disk_uid(struct archive *, const char *, la_int64_t); 1007 1008 /* 1009 * ARCHIVE_READ_DISK API 1010 * 1011 * This is still evolving and somewhat experimental. 1012 */ 1013 __LA_DECL struct archive *archive_read_disk_new(void); 1014 /* The names for symlink modes here correspond to an old BSD 1015 * command-line argument convention: -L, -P, -H */ 1016 /* Follow all symlinks. */ 1017 __LA_DECL int archive_read_disk_set_symlink_logical(struct archive *); 1018 /* Follow no symlinks. */ 1019 __LA_DECL int archive_read_disk_set_symlink_physical(struct archive *); 1020 /* Follow symlink initially, then not. */ 1021 __LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *); 1022 /* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */ 1023 __LA_DECL int archive_read_disk_entry_from_file(struct archive *, 1024 struct archive_entry *, int /* fd */, const struct stat *); 1025 /* Look up gname for gid or uname for uid. */ 1026 /* Default implementations are very, very stupid. */ 1027 __LA_DECL const char *archive_read_disk_gname(struct archive *, la_int64_t); 1028 __LA_DECL const char *archive_read_disk_uname(struct archive *, la_int64_t); 1029 /* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the 1030 * results for performance. */ 1031 __LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); 1032 /* You can install your own lookups if you like. */ 1033 __LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, 1034 void * /* private_data */, 1035 const char *(* /* lookup_fn */)(void *, la_int64_t), 1036 void (* /* cleanup_fn */)(void *)); 1037 __LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, 1038 void * /* private_data */, 1039 const char *(* /* lookup_fn */)(void *, la_int64_t), 1040 void (* /* cleanup_fn */)(void *)); 1041 /* Start traversal. */ 1042 __LA_DECL int archive_read_disk_open(struct archive *, const char *); 1043 __LA_DECL int archive_read_disk_open_w(struct archive *, const wchar_t *); 1044 /* 1045 * Request that current entry be visited. If you invoke it on every 1046 * directory, you'll get a physical traversal. This is ignored if the 1047 * current entry isn't a directory or a link to a directory. So, if 1048 * you invoke this on every returned path, you'll get a full logical 1049 * traversal. 1050 */ 1051 __LA_DECL int archive_read_disk_descend(struct archive *); 1052 __LA_DECL int archive_read_disk_can_descend(struct archive *); 1053 __LA_DECL int archive_read_disk_current_filesystem(struct archive *); 1054 __LA_DECL int archive_read_disk_current_filesystem_is_synthetic(struct archive *); 1055 __LA_DECL int archive_read_disk_current_filesystem_is_remote(struct archive *); 1056 /* Request that the access time of the entry visited by traversal be restored. */ 1057 __LA_DECL int archive_read_disk_set_atime_restored(struct archive *); 1058 /* 1059 * Set behavior. The "flags" argument selects optional behavior. 1060 */ 1061 /* Request that the access time of the entry visited by traversal be restored. 1062 * This is the same as archive_read_disk_set_atime_restored. */ 1063 #define ARCHIVE_READDISK_RESTORE_ATIME (0x0001) 1064 /* Default: Do not skip an entry which has nodump flags. */ 1065 #define ARCHIVE_READDISK_HONOR_NODUMP (0x0002) 1066 /* Default: Skip a mac resource fork file whose prefix is "._" because of 1067 * using copyfile. */ 1068 #define ARCHIVE_READDISK_MAC_COPYFILE (0x0004) 1069 /* Default: Traverse mount points. */ 1070 #define ARCHIVE_READDISK_NO_TRAVERSE_MOUNTS (0x0008) 1071 /* Default: Xattrs are read from disk. */ 1072 #define ARCHIVE_READDISK_NO_XATTR (0x0010) 1073 /* Default: ACLs are read from disk. */ 1074 #define ARCHIVE_READDISK_NO_ACL (0x0020) 1075 /* Default: File flags are read from disk. */ 1076 #define ARCHIVE_READDISK_NO_FFLAGS (0x0040) 1077 /* Default: Sparse file information is read from disk. */ 1078 #define ARCHIVE_READDISK_NO_SPARSE (0x0080) 1079 1080 __LA_DECL int archive_read_disk_set_behavior(struct archive *, 1081 int flags); 1082 1083 /* 1084 * Set archive_match object that will be used in archive_read_disk to 1085 * know whether an entry should be skipped. The callback function 1086 * _excluded_func will be invoked when an entry is skipped by the result 1087 * of archive_match. 1088 */ 1089 __LA_DECL int archive_read_disk_set_matching(struct archive *, 1090 struct archive *_matching, void (*_excluded_func) 1091 (struct archive *, void *, struct archive_entry *), 1092 void *_client_data); 1093 __LA_DECL int archive_read_disk_set_metadata_filter_callback(struct archive *, 1094 int (*_metadata_filter_func)(struct archive *, void *, 1095 struct archive_entry *), void *_client_data); 1096 1097 /* Simplified cleanup interface; 1098 * This calls archive_read_free() or archive_write_free() as needed. */ 1099 __LA_DECL int archive_free(struct archive *); 1100 1101 /* 1102 * Accessor functions to read/set various information in 1103 * the struct archive object: 1104 */ 1105 1106 /* Number of filters in the current filter pipeline. */ 1107 /* Filter #0 is the one closest to the format, -1 is a synonym for the 1108 * last filter, which is always the pseudo-filter that wraps the 1109 * client callbacks. */ 1110 __LA_DECL int archive_filter_count(struct archive *); 1111 __LA_DECL la_int64_t archive_filter_bytes(struct archive *, int); 1112 __LA_DECL int archive_filter_code(struct archive *, int); 1113 __LA_DECL const char * archive_filter_name(struct archive *, int); 1114 1115 #if ARCHIVE_VERSION_NUMBER < 4000000 1116 /* These don't properly handle multiple filters, so are deprecated and 1117 * will eventually be removed. */ 1118 /* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, -1); */ 1119 __LA_DECL la_int64_t archive_position_compressed(struct archive *) 1120 __LA_DEPRECATED; 1121 /* As of libarchive 3.0, this is an alias for archive_filter_bytes(a, 0); */ 1122 __LA_DECL la_int64_t archive_position_uncompressed(struct archive *) 1123 __LA_DEPRECATED; 1124 /* As of libarchive 3.0, this is an alias for archive_filter_name(a, 0); */ 1125 __LA_DECL const char *archive_compression_name(struct archive *) 1126 __LA_DEPRECATED; 1127 /* As of libarchive 3.0, this is an alias for archive_filter_code(a, 0); */ 1128 __LA_DECL int archive_compression(struct archive *) 1129 __LA_DEPRECATED; 1130 #endif 1131 1132 /* Parses a date string relative to the current time. 1133 * NOTE: This is not intended for general date parsing, and the resulting timestamp should only be used for libarchive. */ 1134 __LA_DECL time_t archive_parse_date(time_t now, const char *datestr); 1135 1136 __LA_DECL int archive_errno(struct archive *); 1137 __LA_DECL const char *archive_error_string(struct archive *); 1138 __LA_DECL const char *archive_format_name(struct archive *); 1139 __LA_DECL int archive_format(struct archive *); 1140 __LA_DECL void archive_clear_error(struct archive *); 1141 __LA_DECL void archive_set_error(struct archive *, int _err, 1142 const char *fmt, ...) __LA_PRINTF(3, 4); 1143 __LA_DECL void archive_copy_error(struct archive *dest, 1144 struct archive *src); 1145 __LA_DECL int archive_file_count(struct archive *); 1146 1147 /* 1148 * ARCHIVE_MATCH API 1149 */ 1150 __LA_DECL struct archive *archive_match_new(void); 1151 __LA_DECL int archive_match_free(struct archive *); 1152 1153 /* 1154 * Test if archive_entry is excluded. 1155 * This is a convenience function. This is the same as calling all 1156 * archive_match_path_excluded, archive_match_time_excluded 1157 * and archive_match_owner_excluded. 1158 */ 1159 __LA_DECL int archive_match_excluded(struct archive *, 1160 struct archive_entry *); 1161 1162 /* 1163 * Test if pathname is excluded. The conditions are set by following functions. 1164 */ 1165 __LA_DECL int archive_match_path_excluded(struct archive *, 1166 struct archive_entry *); 1167 /* Control recursive inclusion of directory content when directory is included. Default on. */ 1168 __LA_DECL int archive_match_set_inclusion_recursion(struct archive *, int); 1169 /* Add exclusion pathname pattern. */ 1170 __LA_DECL int archive_match_exclude_pattern(struct archive *, const char *); 1171 __LA_DECL int archive_match_exclude_pattern_w(struct archive *, 1172 const wchar_t *); 1173 /* Add exclusion pathname pattern from file. */ 1174 __LA_DECL int archive_match_exclude_pattern_from_file(struct archive *, 1175 const char *, int _nullSeparator); 1176 __LA_DECL int archive_match_exclude_pattern_from_file_w(struct archive *, 1177 const wchar_t *, int _nullSeparator); 1178 /* Add inclusion pathname pattern. */ 1179 __LA_DECL int archive_match_include_pattern(struct archive *, const char *); 1180 __LA_DECL int archive_match_include_pattern_w(struct archive *, 1181 const wchar_t *); 1182 /* Add inclusion pathname pattern from file. */ 1183 __LA_DECL int archive_match_include_pattern_from_file(struct archive *, 1184 const char *, int _nullSeparator); 1185 __LA_DECL int archive_match_include_pattern_from_file_w(struct archive *, 1186 const wchar_t *, int _nullSeparator); 1187 /* 1188 * How to get statistic information for inclusion patterns. 1189 */ 1190 /* Return the amount number of unmatched inclusion patterns. */ 1191 __LA_DECL int archive_match_path_unmatched_inclusions(struct archive *); 1192 /* Return the pattern of unmatched inclusion with ARCHIVE_OK. 1193 * Return ARCHIVE_EOF if there is no inclusion pattern. */ 1194 __LA_DECL int archive_match_path_unmatched_inclusions_next( 1195 struct archive *, const char **); 1196 __LA_DECL int archive_match_path_unmatched_inclusions_next_w( 1197 struct archive *, const wchar_t **); 1198 1199 /* 1200 * Test if a file is excluded by its time stamp. 1201 * The conditions are set by following functions. 1202 */ 1203 __LA_DECL int archive_match_time_excluded(struct archive *, 1204 struct archive_entry *); 1205 1206 /* 1207 * Flags to tell a matching type of time stamps. These are used for 1208 * following functions. 1209 */ 1210 /* Time flag: mtime to be tested. */ 1211 #define ARCHIVE_MATCH_MTIME (0x0100) 1212 /* Time flag: ctime to be tested. */ 1213 #define ARCHIVE_MATCH_CTIME (0x0200) 1214 /* Comparison flag: Match the time if it is newer than. */ 1215 #define ARCHIVE_MATCH_NEWER (0x0001) 1216 /* Comparison flag: Match the time if it is older than. */ 1217 #define ARCHIVE_MATCH_OLDER (0x0002) 1218 /* Comparison flag: Match the time if it is equal to. */ 1219 #define ARCHIVE_MATCH_EQUAL (0x0010) 1220 /* Set inclusion time. */ 1221 __LA_DECL int archive_match_include_time(struct archive *, int _flag, 1222 time_t _sec, long _nsec); 1223 /* Set inclusion time by a date string. */ 1224 __LA_DECL int archive_match_include_date(struct archive *, int _flag, 1225 const char *_datestr); 1226 __LA_DECL int archive_match_include_date_w(struct archive *, int _flag, 1227 const wchar_t *_datestr); 1228 /* Set inclusion time by a particular file. */ 1229 __LA_DECL int archive_match_include_file_time(struct archive *, 1230 int _flag, const char *_pathname); 1231 __LA_DECL int archive_match_include_file_time_w(struct archive *, 1232 int _flag, const wchar_t *_pathname); 1233 /* Add exclusion entry. */ 1234 __LA_DECL int archive_match_exclude_entry(struct archive *, 1235 int _flag, struct archive_entry *); 1236 1237 /* 1238 * Test if a file is excluded by its uid, gid, uname or gname. 1239 * The conditions are set by following functions. 1240 */ 1241 __LA_DECL int archive_match_owner_excluded(struct archive *, 1242 struct archive_entry *); 1243 /* Add inclusion uid, gid, uname and gname. */ 1244 __LA_DECL int archive_match_include_uid(struct archive *, la_int64_t); 1245 __LA_DECL int archive_match_include_gid(struct archive *, la_int64_t); 1246 __LA_DECL int archive_match_include_uname(struct archive *, const char *); 1247 __LA_DECL int archive_match_include_uname_w(struct archive *, 1248 const wchar_t *); 1249 __LA_DECL int archive_match_include_gname(struct archive *, const char *); 1250 __LA_DECL int archive_match_include_gname_w(struct archive *, 1251 const wchar_t *); 1252 1253 /* Utility functions */ 1254 #if ARCHIVE_VERSION_NUMBER < 4000000 1255 /* Convenience function to sort a NULL terminated list of strings */ 1256 __LA_DECL int archive_utility_string_sort(char **); 1257 #endif 1258 1259 #ifdef __cplusplus 1260 } 1261 #endif 1262 1263 /* These are meaningless outside of this header. */ 1264 #undef __LA_DECL 1265 1266 #endif /* !ARCHIVE_H_INCLUDED */ 1267