1228753Smm/*- 2228753Smm * Copyright (c) 2003-2007 Tim Kientzle 3228753Smm * All rights reserved. 4228753Smm * 5228753Smm * Redistribution and use in source and binary forms, with or without 6228753Smm * modification, are permitted provided that the following conditions 7228753Smm * are met: 8228753Smm * 1. Redistributions of source code must retain the above copyright 9228753Smm * notice, this list of conditions and the following disclaimer. 10228753Smm * 2. Redistributions in binary form must reproduce the above copyright 11228753Smm * notice, this list of conditions and the following disclaimer in the 12228753Smm * documentation and/or other materials provided with the distribution. 13228753Smm * 14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 24228753Smm * 25229592Smm * $FreeBSD$ 26228753Smm */ 27228753Smm 28228753Smm#ifndef ARCHIVE_H_INCLUDED 29228753Smm#define ARCHIVE_H_INCLUDED 30228753Smm 31228753Smm/* 32228753Smm * Note: archive.h is for use outside of libarchive; the configuration 33228753Smm * headers (config.h, archive_platform.h, etc.) are purely internal. 34228753Smm * Do NOT use HAVE_XXX configuration macros to control the behavior of 35228753Smm * this header! If you must conditionalize, use predefined compiler and/or 36228753Smm * platform macros. 37228753Smm */ 38228753Smm#if defined(__BORLANDC__) && __BORLANDC__ >= 0x560 39228753Smm# define __LA_STDINT_H <stdint.h> 40228753Smm#elif !defined(__WATCOMC__) && !defined(_MSC_VER) && !defined(__INTERIX) && !defined(__BORLANDC__) 41228753Smm# define __LA_STDINT_H <inttypes.h> 42228753Smm#endif 43228753Smm 44228753Smm#include <sys/stat.h> 45228753Smm#include <sys/types.h> /* Linux requires this for off_t */ 46228753Smm#ifdef __LA_STDINT_H 47228753Smm# include __LA_STDINT_H /* int64_t, etc. */ 48228753Smm#endif 49228753Smm#include <stdio.h> /* For FILE * */ 50228753Smm 51228753Smm/* Get appropriate definitions of standard POSIX-style types. */ 52228753Smm/* These should match the types used in 'struct stat' */ 53228753Smm#if defined(_WIN32) && !defined(__CYGWIN__) 54228753Smm#define __LA_INT64_T __int64 55228753Smm# if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_) 56228753Smm# define __LA_SSIZE_T ssize_t 57228753Smm# elif defined(_WIN64) 58228753Smm# define __LA_SSIZE_T __int64 59228753Smm# else 60228753Smm# define __LA_SSIZE_T long 61228753Smm# endif 62228753Smm# if defined(__BORLANDC__) 63228753Smm# define __LA_UID_T uid_t 64228753Smm# define __LA_GID_T gid_t 65228753Smm# else 66228753Smm# define __LA_UID_T short 67228753Smm# define __LA_GID_T short 68228753Smm# endif 69228753Smm#else 70228753Smm#include <unistd.h> /* ssize_t, uid_t, and gid_t */ 71228753Smm#define __LA_INT64_T int64_t 72228753Smm#define __LA_SSIZE_T ssize_t 73228753Smm#define __LA_UID_T uid_t 74228753Smm#define __LA_GID_T gid_t 75228753Smm#endif 76228753Smm 77228753Smm/* 78228753Smm * On Windows, define LIBARCHIVE_STATIC if you're building or using a 79228753Smm * .lib. The default here assumes you're building a DLL. Only 80228753Smm * libarchive source should ever define __LIBARCHIVE_BUILD. 81228753Smm */ 82228753Smm#if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) 83228753Smm# ifdef __LIBARCHIVE_BUILD 84228753Smm# ifdef __GNUC__ 85228753Smm# define __LA_DECL __attribute__((dllexport)) extern 86228753Smm# else 87228753Smm# define __LA_DECL __declspec(dllexport) 88228753Smm# endif 89228753Smm# else 90228753Smm# ifdef __GNUC__ 91228753Smm# define __LA_DECL __attribute__((dllimport)) extern 92228753Smm# else 93228753Smm# define __LA_DECL __declspec(dllimport) 94228753Smm# endif 95228753Smm# endif 96228753Smm#else 97228753Smm/* Static libraries or non-Windows needs no special declaration. */ 98228753Smm# define __LA_DECL 99228753Smm#endif 100228753Smm 101228753Smm#if defined(__GNUC__) && __GNUC__ >= 3 102228753Smm#define __LA_PRINTF(fmtarg, firstvararg) \ 103228753Smm __attribute__((__format__ (__printf__, fmtarg, firstvararg))) 104228753Smm#else 105228753Smm#define __LA_PRINTF(fmtarg, firstvararg) /* nothing */ 106228753Smm#endif 107228753Smm 108228753Smm#ifdef __cplusplus 109228753Smmextern "C" { 110228753Smm#endif 111228753Smm 112228753Smm/* 113228753Smm * The version number is provided as both a macro and a function. 114228753Smm * The macro identifies the installed header; the function identifies 115228753Smm * the library version (which may not be the same if you're using a 116228753Smm * dynamically-linked version of the library). Of course, if the 117228753Smm * header and library are very different, you should expect some 118228753Smm * strangeness. Don't do that. 119228753Smm */ 120228753Smm 121228753Smm/* 122228753Smm * The version number is expressed as a single integer that makes it 123228753Smm * easy to compare versions at build time: for version a.b.c, the 124228753Smm * version number is printf("%d%03d%03d",a,b,c). For example, if you 125228753Smm * know your application requires version 2.12.108 or later, you can 126228753Smm * assert that ARCHIVE_VERSION >= 2012108. 127228753Smm * 128228753Smm * This single-number format was introduced with libarchive 1.9.0 in 129228753Smm * the libarchive 1.x family and libarchive 2.2.4 in the libarchive 130228753Smm * 2.x family. The following may be useful if you really want to do 131228753Smm * feature detection for earlier libarchive versions (which defined 132228753Smm * ARCHIVE_API_VERSION and ARCHIVE_API_FEATURE instead): 133228753Smm * 134228753Smm * #ifndef ARCHIVE_VERSION_NUMBER 135228753Smm * #define ARCHIVE_VERSION_NUMBER \ 136228753Smm * (ARCHIVE_API_VERSION * 1000000 + ARCHIVE_API_FEATURE * 1000) 137228753Smm * #endif 138228753Smm */ 139228753Smm#define ARCHIVE_VERSION_NUMBER 2008005 140228753Smm__LA_DECL int archive_version_number(void); 141228753Smm 142228753Smm/* 143228753Smm * Textual name/version of the library, useful for version displays. 144228753Smm */ 145228753Smm#define ARCHIVE_VERSION_STRING "libarchive 2.8.5" 146228753Smm__LA_DECL const char * archive_version_string(void); 147228753Smm 148228753Smm#if ARCHIVE_VERSION_NUMBER < 3000000 149228753Smm/* 150228753Smm * Deprecated; these are older names that will be removed in favor of 151228753Smm * the simpler definitions above. 152228753Smm */ 153228753Smm#define ARCHIVE_VERSION_STAMP ARCHIVE_VERSION_NUMBER 154228753Smm__LA_DECL int archive_version_stamp(void); 155228753Smm#define ARCHIVE_LIBRARY_VERSION ARCHIVE_VERSION_STRING 156228753Smm__LA_DECL const char * archive_version(void); 157228753Smm#define ARCHIVE_API_VERSION (ARCHIVE_VERSION_NUMBER / 1000000) 158228753Smm__LA_DECL int archive_api_version(void); 159228753Smm#define ARCHIVE_API_FEATURE ((ARCHIVE_VERSION_NUMBER / 1000) % 1000) 160228753Smm__LA_DECL int archive_api_feature(void); 161228753Smm#endif 162228753Smm 163228753Smm#if ARCHIVE_VERSION_NUMBER < 3000000 164228753Smm/* This should never have been here in the first place. */ 165228753Smm/* Legacy of old tar assumptions, will be removed in libarchive 3.0. */ 166228753Smm#define ARCHIVE_BYTES_PER_RECORD 512 167228753Smm#define ARCHIVE_DEFAULT_BYTES_PER_BLOCK 10240 168228753Smm#endif 169228753Smm 170228753Smm/* Declare our basic types. */ 171228753Smmstruct archive; 172228753Smmstruct archive_entry; 173228753Smm 174228753Smm/* 175228753Smm * Error codes: Use archive_errno() and archive_error_string() 176228753Smm * to retrieve details. Unless specified otherwise, all functions 177228753Smm * that return 'int' use these codes. 178228753Smm */ 179228753Smm#define ARCHIVE_EOF 1 /* Found end of archive. */ 180228753Smm#define ARCHIVE_OK 0 /* Operation was successful. */ 181228753Smm#define ARCHIVE_RETRY (-10) /* Retry might succeed. */ 182228753Smm#define ARCHIVE_WARN (-20) /* Partial success. */ 183228753Smm/* For example, if write_header "fails", then you can't push data. */ 184228753Smm#define ARCHIVE_FAILED (-25) /* Current operation cannot complete. */ 185228753Smm/* But if write_header is "fatal," then this archive is dead and useless. */ 186228753Smm#define ARCHIVE_FATAL (-30) /* No more operations are possible. */ 187228753Smm 188228753Smm/* 189228753Smm * As far as possible, archive_errno returns standard platform errno codes. 190228753Smm * Of course, the details vary by platform, so the actual definitions 191228753Smm * here are stored in "archive_platform.h". The symbols are listed here 192228753Smm * for reference; as a rule, clients should not need to know the exact 193228753Smm * platform-dependent error code. 194228753Smm */ 195228753Smm/* Unrecognized or invalid file format. */ 196228753Smm/* #define ARCHIVE_ERRNO_FILE_FORMAT */ 197228753Smm/* Illegal usage of the library. */ 198228753Smm/* #define ARCHIVE_ERRNO_PROGRAMMER_ERROR */ 199228753Smm/* Unknown or unclassified error. */ 200228753Smm/* #define ARCHIVE_ERRNO_MISC */ 201228753Smm 202228753Smm/* 203228753Smm * Callbacks are invoked to automatically read/skip/write/open/close the 204228753Smm * archive. You can provide your own for complex tasks (like breaking 205228753Smm * archives across multiple tapes) or use standard ones built into the 206228753Smm * library. 207228753Smm */ 208228753Smm 209228753Smm/* Returns pointer and size of next block of data from archive. */ 210228753Smmtypedef __LA_SSIZE_T archive_read_callback(struct archive *, 211228753Smm void *_client_data, const void **_buffer); 212228753Smm 213228753Smm/* Skips at most request bytes from archive and returns the skipped amount */ 214228753Smm#if ARCHIVE_VERSION_NUMBER < 2000000 215228753Smm/* Libarchive 1.0 used ssize_t for the return, which is only 32 bits 216228753Smm * on most 32-bit platforms; not large enough. */ 217228753Smmtypedef __LA_SSIZE_T archive_skip_callback(struct archive *, 218228753Smm void *_client_data, size_t request); 219228753Smm#elif ARCHIVE_VERSION_NUMBER < 3000000 220228753Smm/* Libarchive 2.0 used off_t here, but that is a bad idea on Linux and a 221228753Smm * few other platforms where off_t varies with build settings. */ 222228753Smmtypedef off_t archive_skip_callback(struct archive *, 223228753Smm void *_client_data, off_t request); 224228753Smm#else 225228753Smm/* Libarchive 3.0 uses int64_t here, which is actually guaranteed to be 226228753Smm * 64 bits on every platform. */ 227228753Smmtypedef __LA_INT64_T archive_skip_callback(struct archive *, 228228753Smm void *_client_data, __LA_INT64_T request); 229228753Smm#endif 230228753Smm 231228753Smm/* Returns size actually written, zero on EOF, -1 on error. */ 232228753Smmtypedef __LA_SSIZE_T archive_write_callback(struct archive *, 233228753Smm void *_client_data, 234228753Smm const void *_buffer, size_t _length); 235228753Smm 236228753Smm#if ARCHIVE_VERSION_NUMBER < 3000000 237228753Smm/* Open callback is actually never needed; remove it in libarchive 3.0. */ 238228753Smmtypedef int archive_open_callback(struct archive *, void *_client_data); 239228753Smm#endif 240228753Smm 241228753Smmtypedef int archive_close_callback(struct archive *, void *_client_data); 242228753Smm 243228753Smm/* 244228753Smm * Codes for archive_compression. 245228753Smm */ 246228753Smm#define ARCHIVE_COMPRESSION_NONE 0 247228753Smm#define ARCHIVE_COMPRESSION_GZIP 1 248228753Smm#define ARCHIVE_COMPRESSION_BZIP2 2 249228753Smm#define ARCHIVE_COMPRESSION_COMPRESS 3 250228753Smm#define ARCHIVE_COMPRESSION_PROGRAM 4 251228753Smm#define ARCHIVE_COMPRESSION_LZMA 5 252228753Smm#define ARCHIVE_COMPRESSION_XZ 6 253228753Smm#define ARCHIVE_COMPRESSION_UU 7 254228753Smm#define ARCHIVE_COMPRESSION_RPM 8 255228753Smm 256228753Smm/* 257228753Smm * Codes returned by archive_format. 258228753Smm * 259228753Smm * Top 16 bits identifies the format family (e.g., "tar"); lower 260228753Smm * 16 bits indicate the variant. This is updated by read_next_header. 261228753Smm * Note that the lower 16 bits will often vary from entry to entry. 262228753Smm * In some cases, this variation occurs as libarchive learns more about 263228753Smm * the archive (for example, later entries might utilize extensions that 264228753Smm * weren't necessary earlier in the archive; in this case, libarchive 265228753Smm * will change the format code to indicate the extended format that 266228753Smm * was used). In other cases, it's because different tools have 267228753Smm * modified the archive and so different parts of the archive 268228753Smm * actually have slightly different formts. (Both tar and cpio store 269228753Smm * format codes in each entry, so it is quite possible for each 270228753Smm * entry to be in a different format.) 271228753Smm */ 272228753Smm#define ARCHIVE_FORMAT_BASE_MASK 0xff0000 273228753Smm#define ARCHIVE_FORMAT_CPIO 0x10000 274228753Smm#define ARCHIVE_FORMAT_CPIO_POSIX (ARCHIVE_FORMAT_CPIO | 1) 275228753Smm#define ARCHIVE_FORMAT_CPIO_BIN_LE (ARCHIVE_FORMAT_CPIO | 2) 276228753Smm#define ARCHIVE_FORMAT_CPIO_BIN_BE (ARCHIVE_FORMAT_CPIO | 3) 277228753Smm#define ARCHIVE_FORMAT_CPIO_SVR4_NOCRC (ARCHIVE_FORMAT_CPIO | 4) 278228753Smm#define ARCHIVE_FORMAT_CPIO_SVR4_CRC (ARCHIVE_FORMAT_CPIO | 5) 279228753Smm#define ARCHIVE_FORMAT_SHAR 0x20000 280228753Smm#define ARCHIVE_FORMAT_SHAR_BASE (ARCHIVE_FORMAT_SHAR | 1) 281228753Smm#define ARCHIVE_FORMAT_SHAR_DUMP (ARCHIVE_FORMAT_SHAR | 2) 282228753Smm#define ARCHIVE_FORMAT_TAR 0x30000 283228753Smm#define ARCHIVE_FORMAT_TAR_USTAR (ARCHIVE_FORMAT_TAR | 1) 284228753Smm#define ARCHIVE_FORMAT_TAR_PAX_INTERCHANGE (ARCHIVE_FORMAT_TAR | 2) 285228753Smm#define ARCHIVE_FORMAT_TAR_PAX_RESTRICTED (ARCHIVE_FORMAT_TAR | 3) 286228753Smm#define ARCHIVE_FORMAT_TAR_GNUTAR (ARCHIVE_FORMAT_TAR | 4) 287228753Smm#define ARCHIVE_FORMAT_ISO9660 0x40000 288228753Smm#define ARCHIVE_FORMAT_ISO9660_ROCKRIDGE (ARCHIVE_FORMAT_ISO9660 | 1) 289228753Smm#define ARCHIVE_FORMAT_ZIP 0x50000 290228753Smm#define ARCHIVE_FORMAT_EMPTY 0x60000 291228753Smm#define ARCHIVE_FORMAT_AR 0x70000 292228753Smm#define ARCHIVE_FORMAT_AR_GNU (ARCHIVE_FORMAT_AR | 1) 293228753Smm#define ARCHIVE_FORMAT_AR_BSD (ARCHIVE_FORMAT_AR | 2) 294228753Smm#define ARCHIVE_FORMAT_MTREE 0x80000 295228753Smm#define ARCHIVE_FORMAT_RAW 0x90000 296228753Smm#define ARCHIVE_FORMAT_XAR 0xA0000 297228753Smm 298228753Smm/*- 299228753Smm * Basic outline for reading an archive: 300228753Smm * 1) Ask archive_read_new for an archive reader object. 301228753Smm * 2) Update any global properties as appropriate. 302228753Smm * In particular, you'll certainly want to call appropriate 303228753Smm * archive_read_support_XXX functions. 304228753Smm * 3) Call archive_read_open_XXX to open the archive 305228753Smm * 4) Repeatedly call archive_read_next_header to get information about 306228753Smm * successive archive entries. Call archive_read_data to extract 307228753Smm * data for entries of interest. 308228753Smm * 5) Call archive_read_finish to end processing. 309228753Smm */ 310228753Smm__LA_DECL struct archive *archive_read_new(void); 311228753Smm 312228753Smm/* 313228753Smm * The archive_read_support_XXX calls enable auto-detect for this 314228753Smm * archive handle. They also link in the necessary support code. 315228753Smm * For example, if you don't want bzlib linked in, don't invoke 316228753Smm * support_compression_bzip2(). The "all" functions provide the 317228753Smm * obvious shorthand. 318228753Smm */ 319228753Smm__LA_DECL int archive_read_support_compression_all(struct archive *); 320228753Smm__LA_DECL int archive_read_support_compression_bzip2(struct archive *); 321228753Smm__LA_DECL int archive_read_support_compression_compress(struct archive *); 322228753Smm__LA_DECL int archive_read_support_compression_gzip(struct archive *); 323228753Smm__LA_DECL int archive_read_support_compression_lzma(struct archive *); 324228753Smm__LA_DECL int archive_read_support_compression_none(struct archive *); 325228753Smm__LA_DECL int archive_read_support_compression_program(struct archive *, 326228753Smm const char *command); 327228753Smm__LA_DECL int archive_read_support_compression_program_signature 328228753Smm (struct archive *, const char *, 329228753Smm const void * /* match */, size_t); 330228753Smm 331228753Smm__LA_DECL int archive_read_support_compression_rpm(struct archive *); 332228753Smm__LA_DECL int archive_read_support_compression_uu(struct archive *); 333228753Smm__LA_DECL int archive_read_support_compression_xz(struct archive *); 334228753Smm 335228753Smm__LA_DECL int archive_read_support_format_all(struct archive *); 336228753Smm__LA_DECL int archive_read_support_format_ar(struct archive *); 337228753Smm__LA_DECL int archive_read_support_format_cpio(struct archive *); 338228753Smm__LA_DECL int archive_read_support_format_empty(struct archive *); 339228753Smm__LA_DECL int archive_read_support_format_gnutar(struct archive *); 340228753Smm__LA_DECL int archive_read_support_format_iso9660(struct archive *); 341228753Smm__LA_DECL int archive_read_support_format_mtree(struct archive *); 342228753Smm__LA_DECL int archive_read_support_format_raw(struct archive *); 343228753Smm__LA_DECL int archive_read_support_format_tar(struct archive *); 344228753Smm__LA_DECL int archive_read_support_format_xar(struct archive *); 345228753Smm__LA_DECL int archive_read_support_format_zip(struct archive *); 346228753Smm 347228753Smm 348228753Smm/* Open the archive using callbacks for archive I/O. */ 349228753Smm__LA_DECL int archive_read_open(struct archive *, void *_client_data, 350228753Smm archive_open_callback *, archive_read_callback *, 351228753Smm archive_close_callback *); 352228753Smm__LA_DECL int archive_read_open2(struct archive *, void *_client_data, 353228753Smm archive_open_callback *, archive_read_callback *, 354228753Smm archive_skip_callback *, archive_close_callback *); 355228753Smm 356228753Smm/* 357228753Smm * A variety of shortcuts that invoke archive_read_open() with 358228753Smm * canned callbacks suitable for common situations. The ones that 359228753Smm * accept a block size handle tape blocking correctly. 360228753Smm */ 361228753Smm/* Use this if you know the filename. Note: NULL indicates stdin. */ 362228753Smm__LA_DECL int archive_read_open_filename(struct archive *, 363228753Smm const char *_filename, size_t _block_size); 364228753Smm/* archive_read_open_file() is a deprecated synonym for ..._open_filename(). */ 365228753Smm__LA_DECL int archive_read_open_file(struct archive *, 366228753Smm const char *_filename, size_t _block_size); 367228753Smm/* Read an archive that's stored in memory. */ 368228753Smm__LA_DECL int archive_read_open_memory(struct archive *, 369228753Smm void * buff, size_t size); 370228753Smm/* A more involved version that is only used for internal testing. */ 371228753Smm__LA_DECL int archive_read_open_memory2(struct archive *a, void *buff, 372228753Smm size_t size, size_t read_size); 373228753Smm/* Read an archive that's already open, using the file descriptor. */ 374228753Smm__LA_DECL int archive_read_open_fd(struct archive *, int _fd, 375228753Smm size_t _block_size); 376228753Smm/* Read an archive that's already open, using a FILE *. */ 377228753Smm/* Note: DO NOT use this with tape drives. */ 378228753Smm__LA_DECL int archive_read_open_FILE(struct archive *, FILE *_file); 379228753Smm 380228753Smm/* Parses and returns next entry header. */ 381228753Smm__LA_DECL int archive_read_next_header(struct archive *, 382228753Smm struct archive_entry **); 383228753Smm 384228753Smm/* Parses and returns next entry header using the archive_entry passed in */ 385228753Smm__LA_DECL int archive_read_next_header2(struct archive *, 386228753Smm struct archive_entry *); 387228753Smm 388228753Smm/* 389228753Smm * Retrieve the byte offset in UNCOMPRESSED data where last-read 390228753Smm * header started. 391228753Smm */ 392228753Smm__LA_DECL __LA_INT64_T archive_read_header_position(struct archive *); 393228753Smm 394228753Smm/* Read data from the body of an entry. Similar to read(2). */ 395228753Smm__LA_DECL __LA_SSIZE_T archive_read_data(struct archive *, 396228753Smm void *, size_t); 397228753Smm 398228753Smm/* 399228753Smm * A zero-copy version of archive_read_data that also exposes the file offset 400228753Smm * of each returned block. Note that the client has no way to specify 401228753Smm * the desired size of the block. The API does guarantee that offsets will 402228753Smm * be strictly increasing and that returned blocks will not overlap. 403228753Smm */ 404228753Smm#if ARCHIVE_VERSION_NUMBER < 3000000 405228753Smm__LA_DECL int archive_read_data_block(struct archive *a, 406228753Smm const void **buff, size_t *size, off_t *offset); 407228753Smm#else 408228753Smm__LA_DECL int archive_read_data_block(struct archive *a, 409228753Smm const void **buff, size_t *size, 410228753Smm __LA_INT64_T *offset); 411228753Smm#endif 412228753Smm 413228753Smm/*- 414228753Smm * Some convenience functions that are built on archive_read_data: 415228753Smm * 'skip': skips entire entry 416228753Smm * 'into_buffer': writes data into memory buffer that you provide 417228753Smm * 'into_fd': writes data to specified filedes 418228753Smm */ 419228753Smm__LA_DECL int archive_read_data_skip(struct archive *); 420228753Smm__LA_DECL int archive_read_data_into_buffer(struct archive *, 421228753Smm void *buffer, __LA_SSIZE_T len); 422228753Smm__LA_DECL int archive_read_data_into_fd(struct archive *, int fd); 423228753Smm 424228753Smm/* 425228753Smm * Set read options. 426228753Smm */ 427228753Smm/* Apply option string to the format only. */ 428228753Smm__LA_DECL int archive_read_set_format_options(struct archive *_a, 429228753Smm const char *s); 430228753Smm/* Apply option string to the filter only. */ 431228753Smm__LA_DECL int archive_read_set_filter_options(struct archive *_a, 432228753Smm const char *s); 433228753Smm/* Apply option string to both the format and the filter. */ 434228753Smm__LA_DECL int archive_read_set_options(struct archive *_a, 435228753Smm const char *s); 436228753Smm 437228753Smm/*- 438228753Smm * Convenience function to recreate the current entry (whose header 439228753Smm * has just been read) on disk. 440228753Smm * 441228753Smm * This does quite a bit more than just copy data to disk. It also: 442228753Smm * - Creates intermediate directories as required. 443228753Smm * - Manages directory permissions: non-writable directories will 444228753Smm * be initially created with write permission enabled; when the 445228753Smm * archive is closed, dir permissions are edited to the values specified 446228753Smm * in the archive. 447228753Smm * - Checks hardlinks: hardlinks will not be extracted unless the 448228753Smm * linked-to file was also extracted within the same session. (TODO) 449228753Smm */ 450228753Smm 451228753Smm/* The "flags" argument selects optional behavior, 'OR' the flags you want. */ 452228753Smm 453228753Smm/* Default: Do not try to set owner/group. */ 454228753Smm#define ARCHIVE_EXTRACT_OWNER (0x0001) 455228753Smm/* Default: Do obey umask, do not restore SUID/SGID/SVTX bits. */ 456228753Smm#define ARCHIVE_EXTRACT_PERM (0x0002) 457228753Smm/* Default: Do not restore mtime/atime. */ 458228753Smm#define ARCHIVE_EXTRACT_TIME (0x0004) 459228753Smm/* Default: Replace existing files. */ 460228753Smm#define ARCHIVE_EXTRACT_NO_OVERWRITE (0x0008) 461228753Smm/* Default: Try create first, unlink only if create fails with EEXIST. */ 462228753Smm#define ARCHIVE_EXTRACT_UNLINK (0x0010) 463228753Smm/* Default: Do not restore ACLs. */ 464228753Smm#define ARCHIVE_EXTRACT_ACL (0x0020) 465228753Smm/* Default: Do not restore fflags. */ 466228753Smm#define ARCHIVE_EXTRACT_FFLAGS (0x0040) 467228753Smm/* Default: Do not restore xattrs. */ 468228753Smm#define ARCHIVE_EXTRACT_XATTR (0x0080) 469228753Smm/* Default: Do not try to guard against extracts redirected by symlinks. */ 470228753Smm/* Note: With ARCHIVE_EXTRACT_UNLINK, will remove any intermediate symlink. */ 471228753Smm#define ARCHIVE_EXTRACT_SECURE_SYMLINKS (0x0100) 472228753Smm/* Default: Do not reject entries with '..' as path elements. */ 473228753Smm#define ARCHIVE_EXTRACT_SECURE_NODOTDOT (0x0200) 474228753Smm/* Default: Create parent directories as needed. */ 475228753Smm#define ARCHIVE_EXTRACT_NO_AUTODIR (0x0400) 476228753Smm/* Default: Overwrite files, even if one on disk is newer. */ 477228753Smm#define ARCHIVE_EXTRACT_NO_OVERWRITE_NEWER (0x0800) 478228753Smm/* Detect blocks of 0 and write holes instead. */ 479228753Smm#define ARCHIVE_EXTRACT_SPARSE (0x1000) 480301044Sglebius/* Default: Do not reject entries with absolute paths */ 481301044Sglebius#define ARCHIVE_EXTRACT_SECURE_NOABSOLUTEPATHS (0x10000) 482228753Smm 483228753Smm__LA_DECL int archive_read_extract(struct archive *, struct archive_entry *, 484228753Smm int flags); 485228753Smm__LA_DECL int archive_read_extract2(struct archive *, struct archive_entry *, 486228753Smm struct archive * /* dest */); 487228753Smm__LA_DECL void archive_read_extract_set_progress_callback(struct archive *, 488228753Smm void (*_progress_func)(void *), void *_user_data); 489228753Smm 490228753Smm/* Record the dev/ino of a file that will not be written. This is 491228753Smm * generally set to the dev/ino of the archive being read. */ 492228753Smm__LA_DECL void archive_read_extract_set_skip_file(struct archive *, 493228753Smm dev_t, ino_t); 494228753Smm 495228753Smm/* Close the file and release most resources. */ 496228753Smm__LA_DECL int archive_read_close(struct archive *); 497228753Smm/* Release all resources and destroy the object. */ 498229592Smm/* Note that archive_read_free will call archive_read_close for you. */ 499229592Smm__LA_DECL int archive_read_free(struct archive *); 500229592Smm#if ARCHIVE_VERSION_NUMBER < 4000000 501229592Smm/* Synonym for archive_read_free() for backwards compatibility. */ 502228753Smm__LA_DECL int archive_read_finish(struct archive *); 503228753Smm#endif 504228753Smm 505228753Smm/*- 506228753Smm * To create an archive: 507228753Smm * 1) Ask archive_write_new for a archive writer object. 508228753Smm * 2) Set any global properties. In particular, you should set 509228753Smm * the compression and format to use. 510228753Smm * 3) Call archive_write_open to open the file (most people 511228753Smm * will use archive_write_open_file or archive_write_open_fd, 512228753Smm * which provide convenient canned I/O callbacks for you). 513228753Smm * 4) For each entry: 514228753Smm * - construct an appropriate struct archive_entry structure 515228753Smm * - archive_write_header to write the header 516228753Smm * - archive_write_data to write the entry data 517228753Smm * 5) archive_write_close to close the output 518229592Smm * 6) archive_write_free to cleanup the writer and release resources 519228753Smm */ 520228753Smm__LA_DECL struct archive *archive_write_new(void); 521228753Smm__LA_DECL int archive_write_set_bytes_per_block(struct archive *, 522228753Smm int bytes_per_block); 523228753Smm__LA_DECL int archive_write_get_bytes_per_block(struct archive *); 524228753Smm/* XXX This is badly misnamed; suggestions appreciated. XXX */ 525228753Smm__LA_DECL int archive_write_set_bytes_in_last_block(struct archive *, 526228753Smm int bytes_in_last_block); 527228753Smm__LA_DECL int archive_write_get_bytes_in_last_block(struct archive *); 528228753Smm 529228753Smm/* The dev/ino of a file that won't be archived. This is used 530228753Smm * to avoid recursively adding an archive to itself. */ 531228753Smm__LA_DECL int archive_write_set_skip_file(struct archive *, dev_t, ino_t); 532228753Smm 533228753Smm__LA_DECL int archive_write_set_compression_bzip2(struct archive *); 534228753Smm__LA_DECL int archive_write_set_compression_compress(struct archive *); 535228753Smm__LA_DECL int archive_write_set_compression_gzip(struct archive *); 536228753Smm__LA_DECL int archive_write_set_compression_lzma(struct archive *); 537228753Smm__LA_DECL int archive_write_set_compression_none(struct archive *); 538228753Smm__LA_DECL int archive_write_set_compression_program(struct archive *, 539228753Smm const char *cmd); 540228753Smm__LA_DECL int archive_write_set_compression_xz(struct archive *); 541228753Smm/* A convenience function to set the format based on the code or name. */ 542228753Smm__LA_DECL int archive_write_set_format(struct archive *, int format_code); 543228753Smm__LA_DECL int archive_write_set_format_by_name(struct archive *, 544228753Smm const char *name); 545228753Smm/* To minimize link pollution, use one or more of the following. */ 546228753Smm__LA_DECL int archive_write_set_format_ar_bsd(struct archive *); 547228753Smm__LA_DECL int archive_write_set_format_ar_svr4(struct archive *); 548228753Smm__LA_DECL int archive_write_set_format_cpio(struct archive *); 549228753Smm__LA_DECL int archive_write_set_format_cpio_newc(struct archive *); 550228753Smm__LA_DECL int archive_write_set_format_mtree(struct archive *); 551228753Smm/* TODO: int archive_write_set_format_old_tar(struct archive *); */ 552228753Smm__LA_DECL int archive_write_set_format_pax(struct archive *); 553228753Smm__LA_DECL int archive_write_set_format_pax_restricted(struct archive *); 554228753Smm__LA_DECL int archive_write_set_format_shar(struct archive *); 555228753Smm__LA_DECL int archive_write_set_format_shar_dump(struct archive *); 556228753Smm__LA_DECL int archive_write_set_format_ustar(struct archive *); 557228753Smm__LA_DECL int archive_write_set_format_zip(struct archive *); 558228753Smm__LA_DECL int archive_write_open(struct archive *, void *, 559228753Smm archive_open_callback *, archive_write_callback *, 560228753Smm archive_close_callback *); 561228753Smm__LA_DECL int archive_write_open_fd(struct archive *, int _fd); 562228753Smm__LA_DECL int archive_write_open_filename(struct archive *, const char *_file); 563228753Smm/* A deprecated synonym for archive_write_open_filename() */ 564228753Smm__LA_DECL int archive_write_open_file(struct archive *, const char *_file); 565228753Smm__LA_DECL int archive_write_open_FILE(struct archive *, FILE *); 566228753Smm/* _buffSize is the size of the buffer, _used refers to a variable that 567228753Smm * will be updated after each write into the buffer. */ 568228753Smm__LA_DECL int archive_write_open_memory(struct archive *, 569228753Smm void *_buffer, size_t _buffSize, size_t *_used); 570228753Smm 571228753Smm/* 572228753Smm * Note that the library will truncate writes beyond the size provided 573228753Smm * to archive_write_header or pad if the provided data is short. 574228753Smm */ 575228753Smm__LA_DECL int archive_write_header(struct archive *, 576228753Smm struct archive_entry *); 577228753Smm#if ARCHIVE_VERSION_NUMBER < 2000000 578228753Smm/* This was erroneously declared to return "int" in libarchive 1.x. */ 579228753Smm__LA_DECL int archive_write_data(struct archive *, 580228753Smm const void *, size_t); 581228753Smm#else 582228753Smm/* Libarchive 2.0 and later return ssize_t here. */ 583228753Smm__LA_DECL __LA_SSIZE_T archive_write_data(struct archive *, 584228753Smm const void *, size_t); 585228753Smm#endif 586228753Smm 587228753Smm#if ARCHIVE_VERSION_NUMBER < 3000000 588228753Smm/* Libarchive 1.x and 2.x use off_t for the argument, but that's not 589228753Smm * stable on Linux. */ 590228753Smm__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, 591228753Smm const void *, size_t, off_t); 592228753Smm#else 593228753Smm/* Libarchive 3.0 uses explicit int64_t to ensure consistent 64-bit support. */ 594228753Smm__LA_DECL __LA_SSIZE_T archive_write_data_block(struct archive *, 595228753Smm const void *, size_t, __LA_INT64_T); 596228753Smm#endif 597228753Smm__LA_DECL int archive_write_finish_entry(struct archive *); 598228753Smm__LA_DECL int archive_write_close(struct archive *); 599229592Smm 600229592Smm/* This can fail if the archive wasn't already closed, in which case 601229592Smm * archive_write_free() will implicitly call archive_write_close(). */ 602229592Smm__LA_DECL int archive_write_free(struct archive *); 603229592Smm#if ARCHIVE_VERSION_NUMBER < 4000000 604229592Smm/* Synonym for archive_write_free() for backwards compatibility. */ 605228753Smm__LA_DECL int archive_write_finish(struct archive *); 606228753Smm#endif 607228753Smm 608228753Smm/* 609228753Smm * Set write options. 610228753Smm */ 611228753Smm/* Apply option string to the format only. */ 612228753Smm__LA_DECL int archive_write_set_format_options(struct archive *_a, 613228753Smm const char *s); 614228753Smm/* Apply option string to the compressor only. */ 615228753Smm__LA_DECL int archive_write_set_compressor_options(struct archive *_a, 616228753Smm const char *s); 617228753Smm/* Apply option string to both the format and the compressor. */ 618228753Smm__LA_DECL int archive_write_set_options(struct archive *_a, 619228753Smm const char *s); 620228753Smm 621228753Smm 622228753Smm/*- 623228753Smm * ARCHIVE_WRITE_DISK API 624228753Smm * 625228753Smm * To create objects on disk: 626228753Smm * 1) Ask archive_write_disk_new for a new archive_write_disk object. 627228753Smm * 2) Set any global properties. In particular, you probably 628228753Smm * want to set the options. 629228753Smm * 3) For each entry: 630228753Smm * - construct an appropriate struct archive_entry structure 631228753Smm * - archive_write_header to create the file/dir/etc on disk 632228753Smm * - archive_write_data to write the entry data 633229592Smm * 4) archive_write_free to cleanup the writer and release resources 634228753Smm * 635228753Smm * In particular, you can use this in conjunction with archive_read() 636228753Smm * to pull entries out of an archive and create them on disk. 637228753Smm */ 638228753Smm__LA_DECL struct archive *archive_write_disk_new(void); 639228753Smm/* This file will not be overwritten. */ 640228753Smm__LA_DECL int archive_write_disk_set_skip_file(struct archive *, 641228753Smm dev_t, ino_t); 642228753Smm/* Set flags to control how the next item gets created. 643228753Smm * This accepts a bitmask of ARCHIVE_EXTRACT_XXX flags defined above. */ 644228753Smm__LA_DECL int archive_write_disk_set_options(struct archive *, 645228753Smm int flags); 646228753Smm/* 647228753Smm * The lookup functions are given uname/uid (or gname/gid) pairs and 648228753Smm * return a uid (gid) suitable for this system. These are used for 649228753Smm * restoring ownership and for setting ACLs. The default functions 650228753Smm * are naive, they just return the uid/gid. These are small, so reasonable 651228753Smm * for applications that don't need to preserve ownership; they 652228753Smm * are probably also appropriate for applications that are doing 653228753Smm * same-system backup and restore. 654228753Smm */ 655228753Smm/* 656228753Smm * The "standard" lookup functions use common system calls to lookup 657228753Smm * the uname/gname, falling back to the uid/gid if the names can't be 658228753Smm * found. They cache lookups and are reasonably fast, but can be very 659228753Smm * large, so they are not used unless you ask for them. In 660228753Smm * particular, these match the specifications of POSIX "pax" and old 661228753Smm * POSIX "tar". 662228753Smm */ 663228753Smm__LA_DECL int archive_write_disk_set_standard_lookup(struct archive *); 664228753Smm/* 665228753Smm * If neither the default (naive) nor the standard (big) functions suit 666228753Smm * your needs, you can write your own and register them. Be sure to 667228753Smm * include a cleanup function if you have allocated private data. 668228753Smm */ 669228753Smm__LA_DECL int archive_write_disk_set_group_lookup(struct archive *, 670228753Smm void * /* private_data */, 671228753Smm __LA_GID_T (*)(void *, const char *, __LA_GID_T), 672228753Smm void (* /* cleanup */)(void *)); 673228753Smm__LA_DECL int archive_write_disk_set_user_lookup(struct archive *, 674228753Smm void * /* private_data */, 675228753Smm __LA_UID_T (*)(void *, const char *, __LA_UID_T), 676228753Smm void (* /* cleanup */)(void *)); 677228753Smm 678228753Smm/* 679228753Smm * ARCHIVE_READ_DISK API 680228753Smm * 681228753Smm * This is still evolving and somewhat experimental. 682228753Smm */ 683228753Smm__LA_DECL struct archive *archive_read_disk_new(void); 684228753Smm/* The names for symlink modes here correspond to an old BSD 685228753Smm * command-line argument convention: -L, -P, -H */ 686228753Smm/* Follow all symlinks. */ 687228753Smm__LA_DECL int archive_read_disk_set_symlink_logical(struct archive *); 688228753Smm/* Follow no symlinks. */ 689228753Smm__LA_DECL int archive_read_disk_set_symlink_physical(struct archive *); 690228753Smm/* Follow symlink initially, then not. */ 691228753Smm__LA_DECL int archive_read_disk_set_symlink_hybrid(struct archive *); 692228753Smm/* TODO: Handle Linux stat32/stat64 ugliness. <sigh> */ 693228753Smm__LA_DECL int archive_read_disk_entry_from_file(struct archive *, 694228753Smm struct archive_entry *, int /* fd */, const struct stat *); 695228753Smm/* Look up gname for gid or uname for uid. */ 696228753Smm/* Default implementations are very, very stupid. */ 697228753Smm__LA_DECL const char *archive_read_disk_gname(struct archive *, __LA_GID_T); 698228753Smm__LA_DECL const char *archive_read_disk_uname(struct archive *, __LA_UID_T); 699228753Smm/* "Standard" implementation uses getpwuid_r, getgrgid_r and caches the 700228753Smm * results for performance. */ 701228753Smm__LA_DECL int archive_read_disk_set_standard_lookup(struct archive *); 702228753Smm/* You can install your own lookups if you like. */ 703228753Smm__LA_DECL int archive_read_disk_set_gname_lookup(struct archive *, 704228753Smm void * /* private_data */, 705228753Smm const char *(* /* lookup_fn */)(void *, __LA_GID_T), 706228753Smm void (* /* cleanup_fn */)(void *)); 707228753Smm__LA_DECL int archive_read_disk_set_uname_lookup(struct archive *, 708228753Smm void * /* private_data */, 709228753Smm const char *(* /* lookup_fn */)(void *, __LA_UID_T), 710228753Smm void (* /* cleanup_fn */)(void *)); 711228753Smm 712228753Smm/* 713228753Smm * Accessor functions to read/set various information in 714228753Smm * the struct archive object: 715228753Smm */ 716228753Smm/* Bytes written after compression or read before decompression. */ 717228753Smm__LA_DECL __LA_INT64_T archive_position_compressed(struct archive *); 718228753Smm/* Bytes written to compressor or read from decompressor. */ 719228753Smm__LA_DECL __LA_INT64_T archive_position_uncompressed(struct archive *); 720228753Smm 721228753Smm__LA_DECL const char *archive_compression_name(struct archive *); 722228753Smm__LA_DECL int archive_compression(struct archive *); 723228753Smm__LA_DECL int archive_errno(struct archive *); 724228753Smm__LA_DECL const char *archive_error_string(struct archive *); 725228753Smm__LA_DECL const char *archive_format_name(struct archive *); 726228753Smm__LA_DECL int archive_format(struct archive *); 727228753Smm__LA_DECL void archive_clear_error(struct archive *); 728228753Smm__LA_DECL void archive_set_error(struct archive *, int _err, 729228753Smm const char *fmt, ...) __LA_PRINTF(3, 4); 730228753Smm__LA_DECL void archive_copy_error(struct archive *dest, 731228753Smm struct archive *src); 732228753Smm__LA_DECL int archive_file_count(struct archive *); 733228753Smm 734228753Smm#ifdef __cplusplus 735228753Smm} 736228753Smm#endif 737228753Smm 738228753Smm/* These are meaningless outside of this header. */ 739228753Smm#undef __LA_DECL 740228753Smm#undef __LA_GID_T 741228753Smm#undef __LA_UID_T 742228753Smm 743228753Smm/* These need to remain defined because they're used in the 744228753Smm * callback type definitions. XXX Fix this. This is ugly. XXX */ 745228753Smm/* #undef __LA_INT64_T */ 746228753Smm/* #undef __LA_SSIZE_T */ 747228753Smm 748228753Smm#endif /* !ARCHIVE_H_INCLUDED */ 749