archive_entry.h 28 KB

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