archive_entry.h 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  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: src/lib/libarchive/archive_entry.h,v 1.31 2008/12/06 06:18:46 kientzle Exp $
  26. */
  27. #ifndef ARCHIVE_ENTRY_H_INCLUDED
  28. #define ARCHIVE_ENTRY_H_INCLUDED
  29. /*
  30. * Note: archive_entry.h is for use outside of libarchive; the
  31. * configuration headers (config.h, archive_platform.h, etc.) are
  32. * purely internal. Do NOT use HAVE_XXX configuration macros to
  33. * control the behavior of this header! If you must conditionalize,
  34. * use predefined compiler and/or platform macros.
  35. */
  36. #include <sys/types.h>
  37. #include <stddef.h> /* for wchar_t */
  38. #include <time.h>
  39. #if defined(_WIN32) && !defined(__CYGWIN__)
  40. #include <windows.h>
  41. #endif
  42. /* Get appropriate definitions of standard POSIX-style types. */
  43. /* These should match the types used in 'struct stat' */
  44. #if defined(_WIN32) && !defined(__CYGWIN__) && !defined(__BORLANDC__)
  45. #define __LA_INT64_T __int64
  46. #define __LA_UID_T short
  47. #define __LA_GID_T short
  48. #define __LA_DEV_T unsigned int
  49. #define __LA_MODE_T unsigned short
  50. #else
  51. #ifdef __BORLANDC__
  52. # include <sys/types.h>
  53. #else
  54. # include <unistd.h>
  55. #endif
  56. #if defined(__BORLANDC__)
  57. #define __LA_INT64_T __int64
  58. #else
  59. #define __LA_INT64_T int64_t
  60. #endif
  61. #define __LA_UID_T uid_t
  62. #define __LA_GID_T gid_t
  63. #define __LA_DEV_T dev_t
  64. #define __LA_MODE_T mode_t
  65. #endif
  66. /*
  67. * XXX Is this defined for all Windows compilers? If so, in what
  68. * header? It would be nice to remove the __LA_INO_T indirection and
  69. * just use plain ino_t everywhere. Likewise for the other types just
  70. * above.
  71. */
  72. #define __LA_INO_T ino_t
  73. /*
  74. * On Windows, define LIBARCHIVE_STATIC if you're building or using a
  75. * .lib. The default here assumes you're building a DLL. Only
  76. * libarchive source should ever define __LIBARCHIVE_BUILD.
  77. */
  78. #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC)
  79. # ifdef __LIBARCHIVE_BUILD
  80. # ifdef __GNUC__
  81. # define __LA_DECL __attribute__((dllexport)) extern
  82. # else
  83. # define __LA_DECL __declspec(dllexport)
  84. # endif
  85. # else
  86. # ifdef __GNUC__
  87. # define __LA_DECL __attribute__((dllimport)) extern
  88. # else
  89. # define __LA_DECL __declspec(dllimport)
  90. # endif
  91. # endif
  92. #else
  93. /* Static libraries on all platforms and shared libraries on non-Windows. */
  94. # define __LA_DECL
  95. #endif
  96. #ifdef __cplusplus
  97. extern "C" {
  98. #endif
  99. /*
  100. * Description of an archive entry.
  101. *
  102. * You can think of this as "struct stat" with some text fields added in.
  103. *
  104. * TODO: Add "comment", "charset", and possibly other entries that are
  105. * supported by "pax interchange" format. However, GNU, ustar, cpio,
  106. * and other variants don't support these features, so they're not an
  107. * excruciatingly high priority right now.
  108. *
  109. * TODO: "pax interchange" format allows essentially arbitrary
  110. * key/value attributes to be attached to any entry. Supporting
  111. * such extensions may make this library useful for special
  112. * applications (e.g., a package manager could attach special
  113. * package-management attributes to each entry).
  114. */
  115. struct archive_entry;
  116. /*
  117. * File-type constants. These are returned from archive_entry_filetype()
  118. * and passed to archive_entry_set_filetype().
  119. *
  120. * These values match S_XXX defines on every platform I've checked,
  121. * including Windows, AIX, Linux, Solaris, and BSD. They're
  122. * (re)defined here because platforms generally don't define the ones
  123. * they don't support. For example, Windows doesn't define S_IFLNK or
  124. * S_IFBLK. Instead of having a mass of conditional logic and system
  125. * checks to define any S_XXX values that aren't supported locally,
  126. * I've just defined a new set of such constants so that
  127. * libarchive-based applications can manipulate and identify archive
  128. * entries properly even if the hosting platform can't store them on
  129. * disk.
  130. *
  131. * These values are also used directly within some portable formats,
  132. * such as cpio. If you find a platform that varies from these, the
  133. * correct solution is to leave these alone and translate from these
  134. * portable values to platform-native values when entries are read from
  135. * or written to disk.
  136. */
  137. #define AE_IFMT 0170000
  138. #define AE_IFREG 0100000
  139. #define AE_IFLNK 0120000
  140. #define AE_IFSOCK 0140000
  141. #define AE_IFCHR 0020000
  142. #define AE_IFBLK 0060000
  143. #define AE_IFDIR 0040000
  144. #define AE_IFIFO 0010000
  145. /*
  146. * Basic object manipulation
  147. */
  148. __LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *);
  149. /* The 'clone' function does a deep copy; all of the strings are copied too. */
  150. __LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *);
  151. __LA_DECL void archive_entry_free(struct archive_entry *);
  152. __LA_DECL struct archive_entry *archive_entry_new(void);
  153. /*
  154. * Retrieve fields from an archive_entry.
  155. *
  156. * There are a number of implicit conversions among these fields. For
  157. * example, if a regular string field is set and you read the _w wide
  158. * character field, the entry will implicitly convert narrow-to-wide
  159. * using the current locale. Similarly, dev values are automatically
  160. * updated when you write devmajor or devminor and vice versa.
  161. *
  162. * In addition, fields can be "set" or "unset." Unset string fields
  163. * return NULL, non-string fields have _is_set() functions to test
  164. * whether they've been set. You can "unset" a string field by
  165. * assigning NULL; non-string fields have _unset() functions to
  166. * unset them.
  167. *
  168. * Note: There is one ambiguity in the above; string fields will
  169. * also return NULL when implicit character set conversions fail.
  170. * This is usually what you want.
  171. */
  172. __LA_DECL time_t archive_entry_atime(struct archive_entry *);
  173. __LA_DECL long archive_entry_atime_nsec(struct archive_entry *);
  174. __LA_DECL int archive_entry_atime_is_set(struct archive_entry *);
  175. __LA_DECL time_t archive_entry_birthtime(struct archive_entry *);
  176. __LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *);
  177. __LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *);
  178. __LA_DECL time_t archive_entry_ctime(struct archive_entry *);
  179. __LA_DECL long archive_entry_ctime_nsec(struct archive_entry *);
  180. __LA_DECL int archive_entry_ctime_is_set(struct archive_entry *);
  181. __LA_DECL dev_t archive_entry_dev(struct archive_entry *);
  182. __LA_DECL dev_t archive_entry_devmajor(struct archive_entry *);
  183. __LA_DECL dev_t archive_entry_devminor(struct archive_entry *);
  184. __LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *);
  185. __LA_DECL void archive_entry_fflags(struct archive_entry *,
  186. unsigned long * /* set */,
  187. unsigned long * /* clear */);
  188. __LA_DECL const char *archive_entry_fflags_text(struct archive_entry *);
  189. __LA_DECL __LA_GID_T archive_entry_gid(struct archive_entry *);
  190. __LA_DECL const char *archive_entry_gname(struct archive_entry *);
  191. __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *);
  192. __LA_DECL const char *archive_entry_hardlink(struct archive_entry *);
  193. __LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
  194. __LA_DECL __LA_INO_T archive_entry_ino(struct archive_entry *);
  195. __LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *);
  196. __LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *);
  197. __LA_DECL time_t archive_entry_mtime(struct archive_entry *);
  198. __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *);
  199. __LA_DECL int archive_entry_mtime_is_set(struct archive_entry *);
  200. __LA_DECL unsigned int archive_entry_nlink(struct archive_entry *);
  201. __LA_DECL const char *archive_entry_pathname(struct archive_entry *);
  202. __LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *);
  203. __LA_DECL dev_t archive_entry_rdev(struct archive_entry *);
  204. __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *);
  205. __LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *);
  206. __LA_DECL const char *archive_entry_sourcepath(struct archive_entry *);
  207. __LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *);
  208. __LA_DECL int archive_entry_size_is_set(struct archive_entry *);
  209. __LA_DECL const char *archive_entry_strmode(struct archive_entry *);
  210. __LA_DECL const char *archive_entry_symlink(struct archive_entry *);
  211. __LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *);
  212. __LA_DECL __LA_UID_T archive_entry_uid(struct archive_entry *);
  213. __LA_DECL const char *archive_entry_uname(struct archive_entry *);
  214. __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *);
  215. /*
  216. * Set fields in an archive_entry.
  217. *
  218. * Note that string 'set' functions do not copy the string, only the pointer.
  219. * In contrast, 'copy' functions do copy the object pointed to.
  220. *
  221. * Note: As of libarchive 2.4, 'set' functions do copy the string and
  222. * are therefore exact synonyms for the 'copy' versions. The 'copy'
  223. * names will be retired in libarchive 3.0.
  224. */
  225. __LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long);
  226. __LA_DECL void archive_entry_unset_atime(struct archive_entry *);
  227. #if defined(_WIN32) && !defined(__CYGWIN__)
  228. __LA_DECL void archive_entry_copy_bhfi(struct archive_entry *,
  229. BY_HANDLE_FILE_INFORMATION *);
  230. #endif
  231. __LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long);
  232. __LA_DECL void archive_entry_unset_birthtime(struct archive_entry *);
  233. __LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long);
  234. __LA_DECL void archive_entry_unset_ctime(struct archive_entry *);
  235. __LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t);
  236. __LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t);
  237. __LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t);
  238. __LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int);
  239. __LA_DECL void archive_entry_set_fflags(struct archive_entry *,
  240. unsigned long /* set */, unsigned long /* clear */);
  241. /* Returns pointer to start of first invalid token, or NULL if none. */
  242. /* Note that all recognized tokens are processed, regardless. */
  243. __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *,
  244. const char *);
  245. __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
  246. const wchar_t *);
  247. __LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_GID_T);
  248. __LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *);
  249. __LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *);
  250. __LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
  251. __LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *);
  252. __LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *);
  253. __LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *);
  254. __LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
  255. #if ARCHIVE_VERSION_NUMBER >= 3000000
  256. /* Starting with libarchive 3.0, this will be synonym for ino64. */
  257. __LA_DECL void archive_entry_set_ino(struct archive_entry *, int64_t);
  258. #else
  259. __LA_DECL void archive_entry_set_ino(struct archive_entry *, unsigned long);
  260. #endif
  261. __LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T);
  262. __LA_DECL void archive_entry_set_link(struct archive_entry *, const char *);
  263. __LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *);
  264. __LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
  265. __LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *);
  266. __LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T);
  267. __LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long);
  268. __LA_DECL void archive_entry_unset_mtime(struct archive_entry *);
  269. __LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int);
  270. __LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *);
  271. __LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *);
  272. __LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
  273. __LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *);
  274. __LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T);
  275. __LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t);
  276. __LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
  277. __LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
  278. __LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T);
  279. __LA_DECL void archive_entry_unset_size(struct archive_entry *);
  280. __LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *);
  281. __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *);
  282. __LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *);
  283. __LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
  284. __LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_UID_T);
  285. __LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *);
  286. __LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *);
  287. __LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
  288. __LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *);
  289. /*
  290. * Routines to bulk copy fields to/from a platform-native "struct
  291. * stat." Libarchive used to just store a struct stat inside of each
  292. * archive_entry object, but this created issues when trying to
  293. * manipulate archives on systems different than the ones they were
  294. * created on.
  295. *
  296. * TODO: On Linux, provide both stat32 and stat64 versions of these functions.
  297. */
  298. __LA_DECL const struct stat *archive_entry_stat(struct archive_entry *);
  299. __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
  300. /*
  301. * ACL routines. This used to simply store and return text-format ACL
  302. * strings, but that proved insufficient for a number of reasons:
  303. * = clients need control over uname/uid and gname/gid mappings
  304. * = there are many different ACL text formats
  305. * = would like to be able to read/convert archives containing ACLs
  306. * on platforms that lack ACL libraries
  307. *
  308. * This last point, in particular, forces me to implement a reasonably
  309. * complete set of ACL support routines.
  310. *
  311. * TODO: Extend this to support NFSv4/NTFS permissions. That should
  312. * allow full ACL support on Mac OS, in particular, which uses
  313. * POSIX.1e-style interfaces to manipulate NFSv4/NTFS permissions.
  314. */
  315. /*
  316. * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's
  317. * "permset"/"perm" abstract type nonsense. A permset is just a simple
  318. * bitmap, following long-standing Unix tradition.
  319. */
  320. #define ARCHIVE_ENTRY_ACL_EXECUTE 1
  321. #define ARCHIVE_ENTRY_ACL_WRITE 2
  322. #define ARCHIVE_ENTRY_ACL_READ 4
  323. /* We need to be able to specify either or both of these. */
  324. #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256
  325. #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512
  326. /* Tag values mimic POSIX.1e */
  327. #define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
  328. #define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
  329. #define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
  330. #define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
  331. #define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */
  332. #define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */
  333. /*
  334. * Set the ACL by clearing it and adding entries one at a time.
  335. * Unlike the POSIX.1e ACL routines, you must specify the type
  336. * (access/default) for each entry. Internally, the ACL data is just
  337. * a soup of entries. API calls here allow you to retrieve just the
  338. * entries of interest. This design (which goes against the spirit of
  339. * POSIX.1e) is useful for handling archive formats that combine
  340. * default and access information in a single ACL list.
  341. */
  342. __LA_DECL void archive_entry_acl_clear(struct archive_entry *);
  343. __LA_DECL void archive_entry_acl_add_entry(struct archive_entry *,
  344. int /* type */, int /* permset */, int /* tag */,
  345. int /* qual */, const char * /* name */);
  346. __LA_DECL void archive_entry_acl_add_entry_w(struct archive_entry *,
  347. int /* type */, int /* permset */, int /* tag */,
  348. int /* qual */, const wchar_t * /* name */);
  349. /*
  350. * To retrieve the ACL, first "reset", then repeatedly ask for the
  351. * "next" entry. The want_type parameter allows you to request only
  352. * access entries or only default entries.
  353. */
  354. __LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */);
  355. __LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
  356. int * /* type */, int * /* permset */, int * /* tag */,
  357. int * /* qual */, const char ** /* name */);
  358. __LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */,
  359. int * /* type */, int * /* permset */, int * /* tag */,
  360. int * /* qual */, const wchar_t ** /* name */);
  361. /*
  362. * Construct a text-format ACL. The flags argument is a bitmask that
  363. * can include any of the following:
  364. *
  365. * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries.
  366. * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries.
  367. * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
  368. * each ACL entry. (As used by 'star'.)
  369. * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
  370. * default ACL entry.
  371. */
  372. #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
  373. #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
  374. __LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
  375. int /* flags */);
  376. /* Return a count of entries matching 'want_type' */
  377. __LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
  378. /*
  379. * Private ACL parser. This is private because it handles some
  380. * very weird formats that clients should not be messing with.
  381. * Clients should only deal with their platform-native formats.
  382. * Because of the need to support many formats cleanly, new arguments
  383. * are likely to get added on a regular basis. Clients who try to use
  384. * this interface are likely to be surprised when it changes.
  385. *
  386. * You were warned!
  387. *
  388. * TODO: Move this declaration out of the public header and into
  389. * a private header. Warnings above are silly.
  390. */
  391. __LA_DECL int __archive_entry_acl_parse_w(struct archive_entry *,
  392. const wchar_t *, int /* type */);
  393. /*
  394. * extended attributes
  395. */
  396. __LA_DECL void archive_entry_xattr_clear(struct archive_entry *);
  397. __LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *,
  398. const char * /* name */, const void * /* value */,
  399. size_t /* size */);
  400. /*
  401. * To retrieve the xattr list, first "reset", then repeatedly ask for the
  402. * "next" entry.
  403. */
  404. __LA_DECL int archive_entry_xattr_count(struct archive_entry *);
  405. __LA_DECL int archive_entry_xattr_reset(struct archive_entry *);
  406. __LA_DECL int archive_entry_xattr_next(struct archive_entry *,
  407. const char ** /* name */, const void ** /* value */, size_t *);
  408. /*
  409. * Utility to match up hardlinks.
  410. *
  411. * The 'struct archive_entry_linkresolver' is a cache of archive entries
  412. * for files with multiple links. Here's how to use it:
  413. * 1. Create a lookup object with archive_entry_linkresolver_new()
  414. * 2. Tell it the archive format you're using.
  415. * 3. Hand each archive_entry to archive_entry_linkify().
  416. * That function will return 0, 1, or 2 entries that should
  417. * be written.
  418. * 4. Call archive_entry_linkify(resolver, NULL) until
  419. * no more entries are returned.
  420. * 5. Call archive_entry_link_resolver_free(resolver) to free resources.
  421. *
  422. * The entries returned have their hardlink and size fields updated
  423. * appropriately. If an entry is passed in that does not refer to
  424. * a file with multiple links, it is returned unchanged. The intention
  425. * is that you should be able to simply filter all entries through
  426. * this machine.
  427. *
  428. * To make things more efficient, be sure that each entry has a valid
  429. * nlinks value. The hardlink cache uses this to track when all links
  430. * have been found. If the nlinks value is zero, it will keep every
  431. * name in the cache indefinitely, which can use a lot of memory.
  432. *
  433. * Note that archive_entry_size() is reset to zero if the file
  434. * body should not be written to the archive. Pay attention!
  435. */
  436. struct archive_entry_linkresolver;
  437. /*
  438. * There are three different strategies for marking hardlinks.
  439. * The descriptions below name them after the best-known
  440. * formats that rely on each strategy:
  441. *
  442. * "Old cpio" is the simplest, it always returns any entry unmodified.
  443. * As far as I know, only cpio formats use this. Old cpio archives
  444. * store every link with the full body; the onus is on the dearchiver
  445. * to detect and properly link the files as they are restored.
  446. * "tar" is also pretty simple; it caches a copy the first time it sees
  447. * any link. Subsequent appearances are modified to be hardlink
  448. * references to the first one without any body. Used by all tar
  449. * formats, although the newest tar formats permit the "old cpio" strategy
  450. * as well. This strategy is very simple for the dearchiver,
  451. * and reasonably straightforward for the archiver.
  452. * "new cpio" is trickier. It stores the body only with the last
  453. * occurrence. The complication is that we might not
  454. * see every link to a particular file in a single session, so
  455. * there's no easy way to know when we've seen the last occurrence.
  456. * The solution here is to queue one link until we see the next.
  457. * At the end of the session, you can enumerate any remaining
  458. * entries by calling archive_entry_linkify(NULL) and store those
  459. * bodies. If you have a file with three links l1, l2, and l3,
  460. * you'll get the following behavior if you see all three links:
  461. * linkify(l1) => NULL (the resolver stores l1 internally)
  462. * linkify(l2) => l1 (resolver stores l2, you write l1)
  463. * linkify(l3) => l2, l3 (all links seen, you can write both).
  464. * If you only see l1 and l2, you'll get this behavior:
  465. * linkify(l1) => NULL
  466. * linkify(l2) => l1
  467. * linkify(NULL) => l2 (at end, you retrieve remaining links)
  468. * As the name suggests, this strategy is used by newer cpio variants.
  469. * It's noticably more complex for the archiver, slightly more complex
  470. * for the dearchiver than the tar strategy, but makes it straightforward
  471. * to restore a file using any link by simply continuing to scan until
  472. * you see a link that is stored with a body. In contrast, the tar
  473. * strategy requires you to rescan the archive from the beginning to
  474. * correctly extract an arbitrary link.
  475. */
  476. __LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
  477. __LA_DECL void archive_entry_linkresolver_set_strategy(
  478. struct archive_entry_linkresolver *, int /* format_code */);
  479. __LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
  480. __LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *,
  481. struct archive_entry **, struct archive_entry **);
  482. #ifdef __cplusplus
  483. }
  484. #endif
  485. /* This is meaningless outside of this header. */
  486. #undef __LA_DECL
  487. #endif /* !ARCHIVE_ENTRY_H_INCLUDED */