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