archive.h 32 KB

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