archive_entry.h 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*-
  2. * Copyright (c) 2003-2008 Tim Kientzle
  3. * Copyright (c) 2016 Martin Matuska
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. *
  15. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
  16. * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  17. * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  18. * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
  19. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  20. * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  21. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  22. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  23. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  24. * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  25. */
  26. #ifndef ARCHIVE_ENTRY_H_INCLUDED
  27. #define ARCHIVE_ENTRY_H_INCLUDED
  28. /* Note: Compiler will complain if this does not match archive.h! */
  29. #define ARCHIVE_VERSION_NUMBER 3007007
  30. /*
  31. * Note: archive_entry.h is for use outside of libarchive; the
  32. * configuration headers (config.h, archive_platform.h, etc.) are
  33. * purely internal. Do NOT use HAVE_XXX configuration macros to
  34. * control the behavior of this header! If you must conditionalize,
  35. * use predefined compiler and/or platform macros.
  36. */
  37. #include <sys/types.h>
  38. #include <stddef.h> /* for wchar_t */
  39. #include <stdint.h>
  40. #include <time.h>
  41. #if defined(_WIN32) && !defined(__CYGWIN__)
  42. #include <windows.h>
  43. #endif
  44. /* Get a suitable 64-bit integer type. */
  45. #if !defined(__LA_INT64_T_DEFINED)
  46. # if ARCHIVE_VERSION_NUMBER < 4000000
  47. #define __LA_INT64_T la_int64_t
  48. # endif
  49. #define __LA_INT64_T_DEFINED
  50. # if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
  51. typedef __int64 la_int64_t;
  52. # else
  53. #include <unistd.h>
  54. # if defined(_SCO_DS) || defined(__osf__)
  55. typedef long long la_int64_t;
  56. # else
  57. typedef int64_t la_int64_t;
  58. # endif
  59. # endif
  60. #endif
  61. /* The la_ssize_t should match the type used in 'struct stat' */
  62. #if !defined(__LA_SSIZE_T_DEFINED)
  63. /* Older code relied on the __LA_SSIZE_T macro; after 4.0 we'll switch to the typedef exclusively. */
  64. # if ARCHIVE_VERSION_NUMBER < 4000000
  65. #define __LA_SSIZE_T la_ssize_t
  66. # endif
  67. #define __LA_SSIZE_T_DEFINED
  68. # if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__WATCOMC__)
  69. # if defined(_SSIZE_T_DEFINED) || defined(_SSIZE_T_)
  70. typedef ssize_t la_ssize_t;
  71. # elif defined(_WIN64)
  72. typedef __int64 la_ssize_t;
  73. # else
  74. typedef long la_ssize_t;
  75. # endif
  76. # else
  77. # include <unistd.h> /* ssize_t */
  78. typedef ssize_t la_ssize_t;
  79. # endif
  80. #endif
  81. /* Get a suitable definition for mode_t */
  82. #if ARCHIVE_VERSION_NUMBER >= 3999000
  83. /* Switch to plain 'int' for libarchive 4.0. It's less broken than 'mode_t' */
  84. # define __LA_MODE_T int
  85. #elif defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__) && !defined(__WATCOMC__)
  86. # define __LA_MODE_T unsigned short
  87. #else
  88. # define __LA_MODE_T mode_t
  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 on all platforms and shared libraries on non-Windows. */
  117. # define __LA_DECL
  118. #endif
  119. #if defined(__GNUC__) && __GNUC__ >= 3 && __GNUC_MINOR__ >= 1
  120. # define __LA_DEPRECATED __attribute__((deprecated))
  121. #else
  122. # define __LA_DEPRECATED
  123. #endif
  124. #ifdef __cplusplus
  125. extern "C" {
  126. #endif
  127. /*
  128. * Description of an archive entry.
  129. *
  130. * You can think of this as "struct stat" with some text fields added in.
  131. *
  132. * TODO: Add "comment", "charset", and possibly other entries that are
  133. * supported by "pax interchange" format. However, GNU, ustar, cpio,
  134. * and other variants don't support these features, so they're not an
  135. * excruciatingly high priority right now.
  136. *
  137. * TODO: "pax interchange" format allows essentially arbitrary
  138. * key/value attributes to be attached to any entry. Supporting
  139. * such extensions may make this library useful for special
  140. * applications (e.g., a package manager could attach special
  141. * package-management attributes to each entry).
  142. */
  143. struct archive;
  144. struct archive_entry;
  145. /*
  146. * File-type constants. These are returned from archive_entry_filetype()
  147. * and passed to archive_entry_set_filetype().
  148. *
  149. * These values match S_XXX defines on every platform I've checked,
  150. * including Windows, AIX, Linux, Solaris, and BSD. They're
  151. * (re)defined here because platforms generally don't define the ones
  152. * they don't support. For example, Windows doesn't define S_IFLNK or
  153. * S_IFBLK. Instead of having a mass of conditional logic and system
  154. * checks to define any S_XXX values that aren't supported locally,
  155. * I've just defined a new set of such constants so that
  156. * libarchive-based applications can manipulate and identify archive
  157. * entries properly even if the hosting platform can't store them on
  158. * disk.
  159. *
  160. * These values are also used directly within some portable formats,
  161. * such as cpio. If you find a platform that varies from these, the
  162. * correct solution is to leave these alone and translate from these
  163. * portable values to platform-native values when entries are read from
  164. * or written to disk.
  165. */
  166. /*
  167. * In libarchive 4.0, we can drop the casts here.
  168. * They're needed to work around Borland C's broken mode_t.
  169. */
  170. #define AE_IFMT ((__LA_MODE_T)0170000)
  171. #define AE_IFREG ((__LA_MODE_T)0100000)
  172. #define AE_IFLNK ((__LA_MODE_T)0120000)
  173. #define AE_IFSOCK ((__LA_MODE_T)0140000)
  174. #define AE_IFCHR ((__LA_MODE_T)0020000)
  175. #define AE_IFBLK ((__LA_MODE_T)0060000)
  176. #define AE_IFDIR ((__LA_MODE_T)0040000)
  177. #define AE_IFIFO ((__LA_MODE_T)0010000)
  178. /*
  179. * Symlink types
  180. */
  181. #define AE_SYMLINK_TYPE_UNDEFINED 0
  182. #define AE_SYMLINK_TYPE_FILE 1
  183. #define AE_SYMLINK_TYPE_DIRECTORY 2
  184. /*
  185. * Basic object manipulation
  186. */
  187. __LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *);
  188. /* The 'clone' function does a deep copy; all of the strings are copied too. */
  189. __LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *);
  190. __LA_DECL void archive_entry_free(struct archive_entry *);
  191. __LA_DECL struct archive_entry *archive_entry_new(void);
  192. /*
  193. * This form of archive_entry_new2() will pull character-set
  194. * conversion information from the specified archive handle. The
  195. * older archive_entry_new(void) form is equivalent to calling
  196. * archive_entry_new2(NULL) and will result in the use of an internal
  197. * default character-set conversion.
  198. */
  199. __LA_DECL struct archive_entry *archive_entry_new2(struct archive *);
  200. /*
  201. * Retrieve fields from an archive_entry.
  202. *
  203. * There are a number of implicit conversions among these fields. For
  204. * example, if a regular string field is set and you read the _w wide
  205. * character field, the entry will implicitly convert narrow-to-wide
  206. * using the current locale. Similarly, dev values are automatically
  207. * updated when you write devmajor or devminor and vice versa.
  208. *
  209. * In addition, fields can be "set" or "unset." Unset string fields
  210. * return NULL, non-string fields have _is_set() functions to test
  211. * whether they've been set. You can "unset" a string field by
  212. * assigning NULL; non-string fields have _unset() functions to
  213. * unset them.
  214. *
  215. * Note: There is one ambiguity in the above; string fields will
  216. * also return NULL when implicit character set conversions fail.
  217. * This is usually what you want.
  218. */
  219. __LA_DECL time_t archive_entry_atime(struct archive_entry *);
  220. __LA_DECL long archive_entry_atime_nsec(struct archive_entry *);
  221. __LA_DECL int archive_entry_atime_is_set(struct archive_entry *);
  222. __LA_DECL time_t archive_entry_birthtime(struct archive_entry *);
  223. __LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *);
  224. __LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *);
  225. __LA_DECL time_t archive_entry_ctime(struct archive_entry *);
  226. __LA_DECL long archive_entry_ctime_nsec(struct archive_entry *);
  227. __LA_DECL int archive_entry_ctime_is_set(struct archive_entry *);
  228. __LA_DECL dev_t archive_entry_dev(struct archive_entry *);
  229. __LA_DECL int archive_entry_dev_is_set(struct archive_entry *);
  230. __LA_DECL dev_t archive_entry_devmajor(struct archive_entry *);
  231. __LA_DECL dev_t archive_entry_devminor(struct archive_entry *);
  232. __LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *);
  233. __LA_DECL int archive_entry_filetype_is_set(struct archive_entry *);
  234. __LA_DECL void archive_entry_fflags(struct archive_entry *,
  235. unsigned long * /* set */,
  236. unsigned long * /* clear */);
  237. __LA_DECL const char *archive_entry_fflags_text(struct archive_entry *);
  238. __LA_DECL la_int64_t archive_entry_gid(struct archive_entry *);
  239. __LA_DECL int archive_entry_gid_is_set(struct archive_entry *);
  240. __LA_DECL const char *archive_entry_gname(struct archive_entry *);
  241. __LA_DECL const char *archive_entry_gname_utf8(struct archive_entry *);
  242. __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *);
  243. __LA_DECL void archive_entry_set_link_to_hardlink(struct archive_entry *);
  244. __LA_DECL const char *archive_entry_hardlink(struct archive_entry *);
  245. __LA_DECL const char *archive_entry_hardlink_utf8(struct archive_entry *);
  246. __LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
  247. __LA_DECL int archive_entry_hardlink_is_set(struct archive_entry *);
  248. __LA_DECL la_int64_t archive_entry_ino(struct archive_entry *);
  249. __LA_DECL la_int64_t archive_entry_ino64(struct archive_entry *);
  250. __LA_DECL int archive_entry_ino_is_set(struct archive_entry *);
  251. __LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *);
  252. __LA_DECL time_t archive_entry_mtime(struct archive_entry *);
  253. __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *);
  254. __LA_DECL int archive_entry_mtime_is_set(struct archive_entry *);
  255. __LA_DECL unsigned int archive_entry_nlink(struct archive_entry *);
  256. __LA_DECL const char *archive_entry_pathname(struct archive_entry *);
  257. __LA_DECL const char *archive_entry_pathname_utf8(struct archive_entry *);
  258. __LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *);
  259. __LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *);
  260. __LA_DECL int archive_entry_perm_is_set(struct archive_entry *);
  261. __LA_DECL int archive_entry_rdev_is_set(struct archive_entry *);
  262. __LA_DECL dev_t archive_entry_rdev(struct archive_entry *);
  263. __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *);
  264. __LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *);
  265. __LA_DECL const char *archive_entry_sourcepath(struct archive_entry *);
  266. __LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *);
  267. __LA_DECL la_int64_t archive_entry_size(struct archive_entry *);
  268. __LA_DECL int archive_entry_size_is_set(struct archive_entry *);
  269. __LA_DECL const char *archive_entry_strmode(struct archive_entry *);
  270. __LA_DECL void archive_entry_set_link_to_symlink(struct archive_entry *);
  271. __LA_DECL const char *archive_entry_symlink(struct archive_entry *);
  272. __LA_DECL const char *archive_entry_symlink_utf8(struct archive_entry *);
  273. __LA_DECL int archive_entry_symlink_type(struct archive_entry *);
  274. __LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *);
  275. __LA_DECL la_int64_t archive_entry_uid(struct archive_entry *);
  276. __LA_DECL int archive_entry_uid_is_set(struct archive_entry *);
  277. __LA_DECL const char *archive_entry_uname(struct archive_entry *);
  278. __LA_DECL const char *archive_entry_uname_utf8(struct archive_entry *);
  279. __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *);
  280. __LA_DECL int archive_entry_is_data_encrypted(struct archive_entry *);
  281. __LA_DECL int archive_entry_is_metadata_encrypted(struct archive_entry *);
  282. __LA_DECL int archive_entry_is_encrypted(struct archive_entry *);
  283. /*
  284. * Set fields in an archive_entry.
  285. *
  286. * Note: Before libarchive 2.4, there were 'set' and 'copy' versions
  287. * of the string setters. 'copy' copied the actual string, 'set' just
  288. * stored the pointer. In libarchive 2.4 and later, strings are
  289. * always copied.
  290. */
  291. __LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long);
  292. __LA_DECL void archive_entry_unset_atime(struct archive_entry *);
  293. #if defined(_WIN32) && !defined(__CYGWIN__)
  294. __LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, BY_HANDLE_FILE_INFORMATION *);
  295. #endif
  296. __LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long);
  297. __LA_DECL void archive_entry_unset_birthtime(struct archive_entry *);
  298. __LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long);
  299. __LA_DECL void archive_entry_unset_ctime(struct archive_entry *);
  300. __LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t);
  301. __LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t);
  302. __LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t);
  303. __LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int);
  304. __LA_DECL void archive_entry_set_fflags(struct archive_entry *,
  305. unsigned long /* set */, unsigned long /* clear */);
  306. /* Returns pointer to start of first invalid token, or NULL if none. */
  307. /* Note that all recognized tokens are processed, regardless. */
  308. __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *,
  309. const char *);
  310. __LA_DECL const char *archive_entry_copy_fflags_text_len(struct archive_entry *,
  311. const char *, size_t);
  312. __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
  313. const wchar_t *);
  314. __LA_DECL void archive_entry_set_gid(struct archive_entry *, la_int64_t);
  315. __LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *);
  316. __LA_DECL void archive_entry_set_gname_utf8(struct archive_entry *, const char *);
  317. __LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *);
  318. __LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
  319. __LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *);
  320. __LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *);
  321. __LA_DECL void archive_entry_set_hardlink_utf8(struct archive_entry *, const char *);
  322. __LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *);
  323. __LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
  324. __LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *);
  325. __LA_DECL void archive_entry_set_ino(struct archive_entry *, la_int64_t);
  326. __LA_DECL void archive_entry_set_ino64(struct archive_entry *, la_int64_t);
  327. __LA_DECL void archive_entry_set_link(struct archive_entry *, const char *);
  328. __LA_DECL void archive_entry_set_link_utf8(struct archive_entry *, const char *);
  329. __LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *);
  330. __LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
  331. __LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *);
  332. __LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T);
  333. __LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long);
  334. __LA_DECL void archive_entry_unset_mtime(struct archive_entry *);
  335. __LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int);
  336. __LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *);
  337. __LA_DECL void archive_entry_set_pathname_utf8(struct archive_entry *, const char *);
  338. __LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *);
  339. __LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
  340. __LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
  341. __LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
  342. __LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t);
  343. __LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
  344. __LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
  345. __LA_DECL void archive_entry_set_size(struct archive_entry *, la_int64_t);
  346. __LA_DECL void archive_entry_unset_size(struct archive_entry *);
  347. __LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *);
  348. __LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *);
  349. __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *);
  350. __LA_DECL void archive_entry_set_symlink_type(struct archive_entry *, int);
  351. __LA_DECL void archive_entry_set_symlink_utf8(struct archive_entry *, const char *);
  352. __LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *);
  353. __LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
  354. __LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *);
  355. __LA_DECL void archive_entry_set_uid(struct archive_entry *, la_int64_t);
  356. __LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *);
  357. __LA_DECL void archive_entry_set_uname_utf8(struct archive_entry *, const char *);
  358. __LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *);
  359. __LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
  360. __LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *);
  361. __LA_DECL void archive_entry_set_is_data_encrypted(struct archive_entry *, char is_encrypted);
  362. __LA_DECL void archive_entry_set_is_metadata_encrypted(struct archive_entry *, char is_encrypted);
  363. /*
  364. * Routines to bulk copy fields to/from a platform-native "struct
  365. * stat." Libarchive used to just store a struct stat inside of each
  366. * archive_entry object, but this created issues when trying to
  367. * manipulate archives on systems different than the ones they were
  368. * created on.
  369. *
  370. * TODO: On Linux and other LFS systems, provide both stat32 and
  371. * stat64 versions of these functions and all of the macro glue so
  372. * that archive_entry_stat is magically defined to
  373. * archive_entry_stat32 or archive_entry_stat64 as appropriate.
  374. */
  375. __LA_DECL const struct stat *archive_entry_stat(struct archive_entry *);
  376. __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
  377. /*
  378. * Storage for Mac OS-specific AppleDouble metadata information.
  379. * Apple-format tar files store a separate binary blob containing
  380. * encoded metadata with ACL, extended attributes, etc.
  381. * This provides a place to store that blob.
  382. */
  383. __LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *);
  384. __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t);
  385. /*
  386. * Digest routine. This is used to query the raw hex digest for the
  387. * given entry. The type of digest is provided as an argument.
  388. */
  389. #define ARCHIVE_ENTRY_DIGEST_MD5 0x00000001
  390. #define ARCHIVE_ENTRY_DIGEST_RMD160 0x00000002
  391. #define ARCHIVE_ENTRY_DIGEST_SHA1 0x00000003
  392. #define ARCHIVE_ENTRY_DIGEST_SHA256 0x00000004
  393. #define ARCHIVE_ENTRY_DIGEST_SHA384 0x00000005
  394. #define ARCHIVE_ENTRY_DIGEST_SHA512 0x00000006
  395. __LA_DECL const unsigned char * archive_entry_digest(struct archive_entry *, int /* type */);
  396. /*
  397. * ACL routines. This used to simply store and return text-format ACL
  398. * strings, but that proved insufficient for a number of reasons:
  399. * = clients need control over uname/uid and gname/gid mappings
  400. * = there are many different ACL text formats
  401. * = would like to be able to read/convert archives containing ACLs
  402. * on platforms that lack ACL libraries
  403. *
  404. * This last point, in particular, forces me to implement a reasonably
  405. * complete set of ACL support routines.
  406. */
  407. /*
  408. * Permission bits.
  409. */
  410. #define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001
  411. #define ARCHIVE_ENTRY_ACL_WRITE 0x00000002
  412. #define ARCHIVE_ENTRY_ACL_READ 0x00000004
  413. #define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008
  414. #define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008
  415. #define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010
  416. #define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010
  417. #define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020
  418. #define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020
  419. #define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040
  420. #define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080
  421. #define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100
  422. #define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200
  423. #define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400
  424. #define ARCHIVE_ENTRY_ACL_DELETE 0x00000800
  425. #define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000
  426. #define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000
  427. #define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000
  428. #define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000
  429. #define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \
  430. (ARCHIVE_ENTRY_ACL_EXECUTE \
  431. | ARCHIVE_ENTRY_ACL_WRITE \
  432. | ARCHIVE_ENTRY_ACL_READ)
  433. #define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \
  434. (ARCHIVE_ENTRY_ACL_EXECUTE \
  435. | ARCHIVE_ENTRY_ACL_READ_DATA \
  436. | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \
  437. | ARCHIVE_ENTRY_ACL_WRITE_DATA \
  438. | ARCHIVE_ENTRY_ACL_ADD_FILE \
  439. | ARCHIVE_ENTRY_ACL_APPEND_DATA \
  440. | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \
  441. | ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \
  442. | ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \
  443. | ARCHIVE_ENTRY_ACL_DELETE_CHILD \
  444. | ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \
  445. | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \
  446. | ARCHIVE_ENTRY_ACL_DELETE \
  447. | ARCHIVE_ENTRY_ACL_READ_ACL \
  448. | ARCHIVE_ENTRY_ACL_WRITE_ACL \
  449. | ARCHIVE_ENTRY_ACL_WRITE_OWNER \
  450. | ARCHIVE_ENTRY_ACL_SYNCHRONIZE)
  451. /*
  452. * Inheritance values (NFS4 ACLs only); included in permset.
  453. */
  454. #define ARCHIVE_ENTRY_ACL_ENTRY_INHERITED 0x01000000
  455. #define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000
  456. #define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000
  457. #define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000
  458. #define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000
  459. #define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000
  460. #define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000
  461. #define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \
  462. (ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \
  463. | ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \
  464. | ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \
  465. | ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \
  466. | ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \
  467. | ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS \
  468. | ARCHIVE_ENTRY_ACL_ENTRY_INHERITED)
  469. /* We need to be able to specify combinations of these. */
  470. #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 0x00000100 /* POSIX.1e only */
  471. #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 0x00000200 /* POSIX.1e only */
  472. #define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 0x00000400 /* NFS4 only */
  473. #define ARCHIVE_ENTRY_ACL_TYPE_DENY 0x00000800 /* NFS4 only */
  474. #define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 0x00001000 /* NFS4 only */
  475. #define ARCHIVE_ENTRY_ACL_TYPE_ALARM 0x00002000 /* NFS4 only */
  476. #define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \
  477. | ARCHIVE_ENTRY_ACL_TYPE_DEFAULT)
  478. #define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \
  479. | ARCHIVE_ENTRY_ACL_TYPE_DENY \
  480. | ARCHIVE_ENTRY_ACL_TYPE_AUDIT \
  481. | ARCHIVE_ENTRY_ACL_TYPE_ALARM)
  482. /* Tag values mimic POSIX.1e */
  483. #define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
  484. #define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
  485. #define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
  486. #define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
  487. #define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */
  488. #define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */
  489. #define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */
  490. /*
  491. * Set the ACL by clearing it and adding entries one at a time.
  492. * Unlike the POSIX.1e ACL routines, you must specify the type
  493. * (access/default) for each entry. Internally, the ACL data is just
  494. * a soup of entries. API calls here allow you to retrieve just the
  495. * entries of interest. This design (which goes against the spirit of
  496. * POSIX.1e) is useful for handling archive formats that combine
  497. * default and access information in a single ACL list.
  498. */
  499. __LA_DECL void archive_entry_acl_clear(struct archive_entry *);
  500. __LA_DECL int archive_entry_acl_add_entry(struct archive_entry *,
  501. int /* type */, int /* permset */, int /* tag */,
  502. int /* qual */, const char * /* name */);
  503. __LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *,
  504. int /* type */, int /* permset */, int /* tag */,
  505. int /* qual */, const wchar_t * /* name */);
  506. /*
  507. * To retrieve the ACL, first "reset", then repeatedly ask for the
  508. * "next" entry. The want_type parameter allows you to request only
  509. * certain types of entries.
  510. */
  511. __LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */);
  512. __LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
  513. int * /* type */, int * /* permset */, int * /* tag */,
  514. int * /* qual */, const char ** /* name */);
  515. /*
  516. * Construct a text-format ACL. The flags argument is a bitmask that
  517. * can include any of the following:
  518. *
  519. * Flags only for archive entries with POSIX.1e ACL:
  520. * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries.
  521. * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries.
  522. * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
  523. * default ACL entry.
  524. * ARCHIVE_ENTRY_ACL_STYLE_SOLARIS - Output only one colon after "other" and
  525. * "mask" entries.
  526. *
  527. * Flags only for archive entries with NFSv4 ACL:
  528. * ARCHIVE_ENTRY_ACL_STYLE_COMPACT - Do not output the minus character for
  529. * unset permissions and flags in NFSv4 ACL permission and flag fields
  530. *
  531. * Flags for for archive entries with POSIX.1e ACL or NFSv4 ACL:
  532. * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
  533. * each ACL entry.
  534. * ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA - Separate entries with comma
  535. * instead of newline.
  536. */
  537. #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 0x00000001
  538. #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 0x00000002
  539. #define ARCHIVE_ENTRY_ACL_STYLE_SOLARIS 0x00000004
  540. #define ARCHIVE_ENTRY_ACL_STYLE_SEPARATOR_COMMA 0x00000008
  541. #define ARCHIVE_ENTRY_ACL_STYLE_COMPACT 0x00000010
  542. __LA_DECL wchar_t *archive_entry_acl_to_text_w(struct archive_entry *,
  543. la_ssize_t * /* len */, int /* flags */);
  544. __LA_DECL char *archive_entry_acl_to_text(struct archive_entry *,
  545. la_ssize_t * /* len */, int /* flags */);
  546. __LA_DECL int archive_entry_acl_from_text_w(struct archive_entry *,
  547. const wchar_t * /* wtext */, int /* type */);
  548. __LA_DECL int archive_entry_acl_from_text(struct archive_entry *,
  549. const char * /* text */, int /* type */);
  550. /* Deprecated constants */
  551. #define OLD_ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
  552. #define OLD_ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
  553. /* Deprecated functions */
  554. __LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
  555. int /* flags */) __LA_DEPRECATED;
  556. __LA_DECL const char *archive_entry_acl_text(struct archive_entry *,
  557. int /* flags */) __LA_DEPRECATED;
  558. /* Return bitmask of ACL types in an archive entry */
  559. __LA_DECL int archive_entry_acl_types(struct archive_entry *);
  560. /* Return a count of entries matching 'want_type' */
  561. __LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
  562. /* Return an opaque ACL object. */
  563. /* There's not yet anything clients can actually do with this... */
  564. struct archive_acl;
  565. __LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *);
  566. /*
  567. * extended attributes
  568. */
  569. __LA_DECL void archive_entry_xattr_clear(struct archive_entry *);
  570. __LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *,
  571. const char * /* name */, const void * /* value */,
  572. size_t /* size */);
  573. /*
  574. * To retrieve the xattr list, first "reset", then repeatedly ask for the
  575. * "next" entry.
  576. */
  577. __LA_DECL int archive_entry_xattr_count(struct archive_entry *);
  578. __LA_DECL int archive_entry_xattr_reset(struct archive_entry *);
  579. __LA_DECL int archive_entry_xattr_next(struct archive_entry *,
  580. const char ** /* name */, const void ** /* value */, size_t *);
  581. /*
  582. * sparse
  583. */
  584. __LA_DECL void archive_entry_sparse_clear(struct archive_entry *);
  585. __LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *,
  586. la_int64_t /* offset */, la_int64_t /* length */);
  587. /*
  588. * To retrieve the xattr list, first "reset", then repeatedly ask for the
  589. * "next" entry.
  590. */
  591. __LA_DECL int archive_entry_sparse_count(struct archive_entry *);
  592. __LA_DECL int archive_entry_sparse_reset(struct archive_entry *);
  593. __LA_DECL int archive_entry_sparse_next(struct archive_entry *,
  594. la_int64_t * /* offset */, la_int64_t * /* length */);
  595. /*
  596. * Utility to match up hardlinks.
  597. *
  598. * The 'struct archive_entry_linkresolver' is a cache of archive entries
  599. * for files with multiple links. Here's how to use it:
  600. * 1. Create a lookup object with archive_entry_linkresolver_new()
  601. * 2. Tell it the archive format you're using.
  602. * 3. Hand each archive_entry to archive_entry_linkify().
  603. * That function will return 0, 1, or 2 entries that should
  604. * be written.
  605. * 4. Call archive_entry_linkify(resolver, NULL) until
  606. * no more entries are returned.
  607. * 5. Call archive_entry_linkresolver_free(resolver) to free resources.
  608. *
  609. * The entries returned have their hardlink and size fields updated
  610. * appropriately. If an entry is passed in that does not refer to
  611. * a file with multiple links, it is returned unchanged. The intention
  612. * is that you should be able to simply filter all entries through
  613. * this machine.
  614. *
  615. * To make things more efficient, be sure that each entry has a valid
  616. * nlinks value. The hardlink cache uses this to track when all links
  617. * have been found. If the nlinks value is zero, it will keep every
  618. * name in the cache indefinitely, which can use a lot of memory.
  619. *
  620. * Note that archive_entry_size() is reset to zero if the file
  621. * body should not be written to the archive. Pay attention!
  622. */
  623. struct archive_entry_linkresolver;
  624. /*
  625. * There are three different strategies for marking hardlinks.
  626. * The descriptions below name them after the best-known
  627. * formats that rely on each strategy:
  628. *
  629. * "Old cpio" is the simplest, it always returns any entry unmodified.
  630. * As far as I know, only cpio formats use this. Old cpio archives
  631. * store every link with the full body; the onus is on the dearchiver
  632. * to detect and properly link the files as they are restored.
  633. * "tar" is also pretty simple; it caches a copy the first time it sees
  634. * any link. Subsequent appearances are modified to be hardlink
  635. * references to the first one without any body. Used by all tar
  636. * formats, although the newest tar formats permit the "old cpio" strategy
  637. * as well. This strategy is very simple for the dearchiver,
  638. * and reasonably straightforward for the archiver.
  639. * "new cpio" is trickier. It stores the body only with the last
  640. * occurrence. The complication is that we might not
  641. * see every link to a particular file in a single session, so
  642. * there's no easy way to know when we've seen the last occurrence.
  643. * The solution here is to queue one link until we see the next.
  644. * At the end of the session, you can enumerate any remaining
  645. * entries by calling archive_entry_linkify(NULL) and store those
  646. * bodies. If you have a file with three links l1, l2, and l3,
  647. * you'll get the following behavior if you see all three links:
  648. * linkify(l1) => NULL (the resolver stores l1 internally)
  649. * linkify(l2) => l1 (resolver stores l2, you write l1)
  650. * linkify(l3) => l2, l3 (all links seen, you can write both).
  651. * If you only see l1 and l2, you'll get this behavior:
  652. * linkify(l1) => NULL
  653. * linkify(l2) => l1
  654. * linkify(NULL) => l2 (at end, you retrieve remaining links)
  655. * As the name suggests, this strategy is used by newer cpio variants.
  656. * It's noticeably more complex for the archiver, slightly more complex
  657. * for the dearchiver than the tar strategy, but makes it straightforward
  658. * to restore a file using any link by simply continuing to scan until
  659. * you see a link that is stored with a body. In contrast, the tar
  660. * strategy requires you to rescan the archive from the beginning to
  661. * correctly extract an arbitrary link.
  662. */
  663. __LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
  664. __LA_DECL void archive_entry_linkresolver_set_strategy(
  665. struct archive_entry_linkresolver *, int /* format_code */);
  666. __LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
  667. __LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *,
  668. struct archive_entry **, struct archive_entry **);
  669. __LA_DECL struct archive_entry *archive_entry_partial_links(
  670. struct archive_entry_linkresolver *res, unsigned int *links);
  671. #ifdef __cplusplus
  672. }
  673. #endif
  674. /* This is meaningless outside of this header. */
  675. #undef __LA_DECL
  676. #endif /* !ARCHIVE_ENTRY_H_INCLUDED */