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