archive.h 53 KB

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