Import of libarchive and bsdtar 1.3.1
[dragonfly.git] / contrib / libarchive-1.3.1 / libarchive / archive_entry.h
1 /*-
2  * Copyright (c) 2003-2004 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  *    in this position and unchanged.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  *
26  * $FreeBSD: src/lib/libarchive/archive_entry.h,v 1.19 2006/03/21 16:55:46 kientzle Exp $
27  */
28
29 #ifndef ARCHIVE_ENTRY_H_INCLUDED
30 #define ARCHIVE_ENTRY_H_INCLUDED
31
32 #include <stddef.h>  /* for wchar_t */
33 #include <unistd.h>
34
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38
39
40 /*
41  * Description of an archive entry.
42  *
43  * Basically, a "struct stat" with a few text fields added in.
44  *
45  * TODO: Add "comment", "charset", and possibly other entries that are
46  * supported by "pax interchange" format.  However, GNU, ustar, cpio,
47  * and other variants don't support these features, so they're not an
48  * excruciatingly high priority right now.
49  *
50  * TODO: "pax interchange" format allows essentially arbitrary
51  * key/value attributes to be attached to any entry.  Supporting
52  * such extensions may make this library useful for special
53  * applications (e.g., a package manager could attach special
54  * package-management attributes to each entry).
55  */
56 struct archive_entry;
57
58 /*
59  * Basic object manipulation
60  */
61
62 struct archive_entry    *archive_entry_clear(struct archive_entry *);
63 /* The 'clone' function does a deep copy; all of the strings are copied too. */
64 struct archive_entry    *archive_entry_clone(struct archive_entry *);
65 void                     archive_entry_free(struct archive_entry *);
66 struct archive_entry    *archive_entry_new(void);
67
68 /*
69  * Retrieve fields from an archive_entry.
70  */
71
72 time_t                   archive_entry_atime(struct archive_entry *);
73 long                     archive_entry_atime_nsec(struct archive_entry *);
74 time_t                   archive_entry_ctime(struct archive_entry *);
75 long                     archive_entry_ctime_nsec(struct archive_entry *);
76 dev_t                    archive_entry_dev(struct archive_entry *);
77 void                     archive_entry_fflags(struct archive_entry *,
78                              unsigned long *set, unsigned long *clear);
79 const char              *archive_entry_fflags_text(struct archive_entry *);
80 gid_t                    archive_entry_gid(struct archive_entry *);
81 const char              *archive_entry_gname(struct archive_entry *);
82 const wchar_t           *archive_entry_gname_w(struct archive_entry *);
83 const char              *archive_entry_hardlink(struct archive_entry *);
84 const wchar_t           *archive_entry_hardlink_w(struct archive_entry *);
85 ino_t                    archive_entry_ino(struct archive_entry *);
86 mode_t                   archive_entry_mode(struct archive_entry *);
87 time_t                   archive_entry_mtime(struct archive_entry *);
88 long                     archive_entry_mtime_nsec(struct archive_entry *);
89 const char              *archive_entry_pathname(struct archive_entry *);
90 const wchar_t           *archive_entry_pathname_w(struct archive_entry *);
91 dev_t                    archive_entry_rdev(struct archive_entry *);
92 dev_t                    archive_entry_rdevmajor(struct archive_entry *);
93 dev_t                    archive_entry_rdevminor(struct archive_entry *);
94 int64_t                  archive_entry_size(struct archive_entry *);
95 const struct stat       *archive_entry_stat(struct archive_entry *);
96 const char              *archive_entry_symlink(struct archive_entry *);
97 const wchar_t           *archive_entry_symlink_w(struct archive_entry *);
98 uid_t                    archive_entry_uid(struct archive_entry *);
99 const char              *archive_entry_uname(struct archive_entry *);
100 const wchar_t           *archive_entry_uname_w(struct archive_entry *);
101
102 /*
103  * Set fields in an archive_entry.
104  *
105  * Note that string 'set' functions do not copy the string, only the pointer.
106  * In contrast, 'copy' functions do copy the object pointed to.
107  */
108
109 void    archive_entry_copy_stat(struct archive_entry *, const struct stat *);
110 void    archive_entry_set_atime(struct archive_entry *, time_t, long);
111 void    archive_entry_set_ctime(struct archive_entry *, time_t, long);
112 void    archive_entry_set_fflags(struct archive_entry *,
113             unsigned long set, unsigned long clear);
114 /* Returns pointer to start of first invalid token, or NULL if none. */
115 /* Note that all recognized tokens are processed, regardless. */
116 const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
117             const wchar_t *);
118 void    archive_entry_set_gid(struct archive_entry *, gid_t);
119 void    archive_entry_set_gname(struct archive_entry *, const char *);
120 void    archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
121 void    archive_entry_set_hardlink(struct archive_entry *, const char *);
122 void    archive_entry_copy_hardlink(struct archive_entry *, const char *);
123 void    archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
124 void    archive_entry_set_link(struct archive_entry *, const char *);
125 void    archive_entry_set_mode(struct archive_entry *, mode_t);
126 void    archive_entry_set_mtime(struct archive_entry *, time_t, long);
127 void    archive_entry_set_pathname(struct archive_entry *, const char *);
128 void    archive_entry_copy_pathname(struct archive_entry *, const char *);
129 void    archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
130 void    archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
131 void    archive_entry_set_rdevminor(struct archive_entry *, dev_t);
132 void    archive_entry_set_size(struct archive_entry *, int64_t);
133 void    archive_entry_set_symlink(struct archive_entry *, const char *);
134 void    archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
135 void    archive_entry_set_uid(struct archive_entry *, uid_t);
136 void    archive_entry_set_uname(struct archive_entry *, const char *);
137 void    archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
138
139 /*
140  * ACL routines.  This used to simply store and return text-format ACL
141  * strings, but that proved insufficient for a number of reasons:
142  *   = clients need control over uname/uid and gname/gid mappings
143  *   = there are many different ACL text formats
144  *   = would like to be able to read/convert archives containing ACLs
145  *     on platforms that lack ACL libraries
146  */
147
148 /*
149  * Permission bits mimic POSIX.1e.  Note that I've not followed POSIX.1e's
150  * "permset"/"perm" abstract type nonsense.  A permset is just a simple
151  * bitmap, following long-standing Unix tradition.
152  */
153 #define ARCHIVE_ENTRY_ACL_EXECUTE       1
154 #define ARCHIVE_ENTRY_ACL_WRITE         2
155 #define ARCHIVE_ENTRY_ACL_READ          4
156
157 /* We need to be able to specify either or both of these. */
158 #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS   256
159 #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT  512
160
161 /* Tag values mimic POSIX.1e */
162 #define ARCHIVE_ENTRY_ACL_USER          10001   /* Specified user. */
163 #define ARCHIVE_ENTRY_ACL_USER_OBJ      10002   /* User who owns the file. */
164 #define ARCHIVE_ENTRY_ACL_GROUP         10003   /* Specified group. */
165 #define ARCHIVE_ENTRY_ACL_GROUP_OBJ     10004   /* Group who owns the file. */
166 #define ARCHIVE_ENTRY_ACL_MASK          10005   /* Modify group access. */
167 #define ARCHIVE_ENTRY_ACL_OTHER         10006   /* Public. */
168
169 /*
170  * Set the ACL by clearing it and adding entries one at a time.
171  * Unlike the POSIX.1e ACL routines, you must specify the type
172  * (access/default) for each entry.  Internally, the ACL data is just
173  * a soup of entries.  API calls here allow you to retrieve just the
174  * entries of interest.  This design (which goes against the spirit of
175  * POSIX.1e) is useful for handling archive formats that combine
176  * default and access information in a single ACL list.
177  */
178 void     archive_entry_acl_clear(struct archive_entry *);
179 void     archive_entry_acl_add_entry(struct archive_entry *,
180              int type, int permset, int tag, int qual, const char *name);
181 void     archive_entry_acl_add_entry_w(struct archive_entry *,
182              int type, int permset, int tag, int qual, const wchar_t *name);
183
184 /*
185  * To retrieve the ACL, first "reset", then repeatedly ask for the
186  * "next" entry.  The want_type parameter allows you to request only
187  * access entries or only default entries.
188  */
189 int      archive_entry_acl_reset(struct archive_entry *, int want_type);
190 int      archive_entry_acl_next(struct archive_entry *, int want_type,
191              int *type, int *permset, int *tag, int *qual, const char **name);
192 int      archive_entry_acl_next_w(struct archive_entry *, int want_type,
193              int *type, int *permset, int *tag, int *qual,
194              const wchar_t **name);
195
196 /*
197  * Construct a text-format ACL.  The flags argument is a bitmask that
198  * can include any of the following:
199  *
200  * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries.
201  * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries.
202  * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
203  *    each ACL entry.  (As used by 'star'.)
204  * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
205  *    default ACL entry.
206  */
207 #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID        1024
208 #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT    2048
209 const wchar_t   *archive_entry_acl_text_w(struct archive_entry *, int flags);
210
211 /* Return a count of entries matching 'want_type' */
212 int      archive_entry_acl_count(struct archive_entry *, int want_type);
213
214 /*
215  * Private ACL parser.  This is private because it handles some
216  * very weird formats that clients should not be messing with.
217  * Clients should only deal with their platform-native formats.
218  * Because of the need to support many formats cleanly, new arguments
219  * are likely to get added on a regular basis.  Clients who try to use
220  * this interface are likely to be surprised when it changes.
221  *
222  * You were warned!
223  */
224 int              __archive_entry_acl_parse_w(struct archive_entry *,
225                      const wchar_t *, int type);
226
227
228 #ifdef __cplusplus
229 }
230 #endif
231
232 /*
233  * extended attributes
234  */
235
236 void     archive_entry_xattr_clear(struct archive_entry *);
237 void     archive_entry_xattr_add_entry(struct archive_entry *,
238              const char *name, const void *value, size_t size);
239
240 /*
241  * To retrieve the xattr list, first "reset", then repeatedly ask for the
242  * "next" entry.
243  */
244
245 int     archive_entry_xattr_count(struct archive_entry *);
246 int     archive_entry_xattr_reset(struct archive_entry *);
247 int     archive_entry_xattr_next(struct archive_entry *,
248              const char **name, const void **value, size_t *);
249
250
251 #endif /* !ARCHIVE_ENTRY_H_INCLUDED */