archive.h 51 KB

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