2 * Copyright (c) 2003-2007 Tim Kientzle
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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.
28 #ifndef ARCHIVE_ENTRY_H_INCLUDED
29 #define ARCHIVE_ENTRY_H_INCLUDED
31 #include <sys/types.h>
32 #include <stddef.h> /* for wchar_t */
42 * Description of an archive entry.
44 * Basically, a "struct stat" with a few text fields added in.
46 * TODO: Add "comment", "charset", and possibly other entries that are
47 * supported by "pax interchange" format. However, GNU, ustar, cpio,
48 * and other variants don't support these features, so they're not an
49 * excruciatingly high priority right now.
51 * TODO: "pax interchange" format allows essentially arbitrary
52 * key/value attributes to be attached to any entry. Supporting
53 * such extensions may make this library useful for special
54 * applications (e.g., a package manager could attach special
55 * package-management attributes to each entry).
60 * File-type constants. These are returned from archive_entry_filetype()
61 * and passed to archive_entry_set_filetype().
63 * These values match S_XXX defines on every platform I've checked,
64 * including Windows, AIX, Linux, Solaris, and BSD. They're
65 * (re)defined here because platforms generally don't define the ones
66 * they don't support. For example, Windows doesn't define S_IFLNK or
67 * S_IFBLK. Instead of having a mass of conditional logic and system
68 * checks to define any S_XXX values that aren't supported locally,
69 * I've just defined a new set of such constants so that
70 * libarchive-based applications can manipulate and identify archive
71 * entries properly even if the hosting platform can't store them on
74 * These values are also used directly within some portable formats,
75 * such as cpio. If you find a platform that varies from these, the
76 * correct solution is to leave these alone and translate from these
77 * portable values to platform-native values when entries are read from
80 #define AE_IFMT 0170000
81 #define AE_IFREG 0100000
82 #define AE_IFLNK 0120000
83 #define AE_IFSOCK 0140000
84 #define AE_IFCHR 0020000
85 #define AE_IFBLK 0060000
86 #define AE_IFDIR 0040000
87 #define AE_IFIFO 0010000
90 * Basic object manipulation
93 struct archive_entry *archive_entry_clear(struct archive_entry *);
94 /* The 'clone' function does a deep copy; all of the strings are copied too. */
95 struct archive_entry *archive_entry_clone(struct archive_entry *);
96 void archive_entry_free(struct archive_entry *);
97 struct archive_entry *archive_entry_new(void);
100 * Retrieve fields from an archive_entry.
103 time_t archive_entry_atime(struct archive_entry *);
104 long archive_entry_atime_nsec(struct archive_entry *);
105 time_t archive_entry_ctime(struct archive_entry *);
106 long archive_entry_ctime_nsec(struct archive_entry *);
107 dev_t archive_entry_dev(struct archive_entry *);
108 dev_t archive_entry_devmajor(struct archive_entry *);
109 dev_t archive_entry_devminor(struct archive_entry *);
110 mode_t archive_entry_filetype(struct archive_entry *);
111 void archive_entry_fflags(struct archive_entry *,
112 unsigned long * /* set */,
113 unsigned long * /* clear */);
114 const char *archive_entry_fflags_text(struct archive_entry *);
115 gid_t archive_entry_gid(struct archive_entry *);
116 const char *archive_entry_gname(struct archive_entry *);
117 const wchar_t *archive_entry_gname_w(struct archive_entry *);
118 const char *archive_entry_hardlink(struct archive_entry *);
119 const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
120 ino_t archive_entry_ino(struct archive_entry *);
121 mode_t archive_entry_mode(struct archive_entry *);
122 time_t archive_entry_mtime(struct archive_entry *);
123 long archive_entry_mtime_nsec(struct archive_entry *);
124 unsigned int archive_entry_nlink(struct archive_entry *);
125 const char *archive_entry_pathname(struct archive_entry *);
126 const wchar_t *archive_entry_pathname_w(struct archive_entry *);
127 dev_t archive_entry_rdev(struct archive_entry *);
128 dev_t archive_entry_rdevmajor(struct archive_entry *);
129 dev_t archive_entry_rdevminor(struct archive_entry *);
130 int64_t archive_entry_size(struct archive_entry *);
131 const char *archive_entry_strmode(struct archive_entry *);
132 const char *archive_entry_symlink(struct archive_entry *);
133 const wchar_t *archive_entry_symlink_w(struct archive_entry *);
134 uid_t archive_entry_uid(struct archive_entry *);
135 const char *archive_entry_uname(struct archive_entry *);
136 const wchar_t *archive_entry_uname_w(struct archive_entry *);
139 * Set fields in an archive_entry.
141 * Note that string 'set' functions do not copy the string, only the pointer.
142 * In contrast, 'copy' functions do copy the object pointed to.
145 void archive_entry_set_atime(struct archive_entry *, time_t, long);
146 void archive_entry_set_ctime(struct archive_entry *, time_t, long);
147 void archive_entry_set_dev(struct archive_entry *, dev_t);
148 void archive_entry_set_devmajor(struct archive_entry *, dev_t);
149 void archive_entry_set_devminor(struct archive_entry *, dev_t);
150 void archive_entry_set_filetype(struct archive_entry *, unsigned int);
151 void archive_entry_set_fflags(struct archive_entry *,
152 unsigned long /* set */, unsigned long /* clear */);
153 /* Returns pointer to start of first invalid token, or NULL if none. */
154 /* Note that all recognized tokens are processed, regardless. */
155 const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
157 void archive_entry_set_gid(struct archive_entry *, gid_t);
158 void archive_entry_set_gname(struct archive_entry *, const char *);
159 void archive_entry_copy_gname(struct archive_entry *, const char *);
160 void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
161 void archive_entry_set_hardlink(struct archive_entry *, const char *);
162 void archive_entry_copy_hardlink(struct archive_entry *, const char *);
163 void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
164 void archive_entry_set_ino(struct archive_entry *, unsigned long);
165 void archive_entry_set_link(struct archive_entry *, const char *);
166 void archive_entry_copy_link(struct archive_entry *, const char *);
167 void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *);
168 void archive_entry_set_mode(struct archive_entry *, mode_t);
169 void archive_entry_set_mtime(struct archive_entry *, time_t, long);
170 void archive_entry_set_nlink(struct archive_entry *, unsigned int);
171 void archive_entry_set_pathname(struct archive_entry *, const char *);
172 void archive_entry_copy_pathname(struct archive_entry *, const char *);
173 void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
174 void archive_entry_set_perm(struct archive_entry *, mode_t);
175 void archive_entry_set_rdev(struct archive_entry *, dev_t);
176 void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
177 void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
178 void archive_entry_set_size(struct archive_entry *, int64_t);
179 void archive_entry_set_symlink(struct archive_entry *, const char *);
180 void archive_entry_copy_symlink(struct archive_entry *, const char *);
181 void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
182 void archive_entry_set_uid(struct archive_entry *, uid_t);
183 void archive_entry_set_uname(struct archive_entry *, const char *);
184 void archive_entry_copy_uname(struct archive_entry *, const char *);
185 void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
188 * Routines to bulk copy fields to/from a platform-native "struct
189 * stat." Libarchive used to just store a struct stat inside of each
190 * archive_entry object, but this created issues when trying to
191 * manipulate archives on systems different than the ones they were
194 * TODO: On Linux, provide both stat32 and stat64 versions of these functions.
196 const struct stat *archive_entry_stat(struct archive_entry *);
197 void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
200 * ACL routines. This used to simply store and return text-format ACL
201 * strings, but that proved insufficient for a number of reasons:
202 * = clients need control over uname/uid and gname/gid mappings
203 * = there are many different ACL text formats
204 * = would like to be able to read/convert archives containing ACLs
205 * on platforms that lack ACL libraries
207 * This last point, in particular, forces me to implement a reasonably
208 * complete set of ACL support routines.
210 * TODO: Extend this to support NFSv4/NTFS permissions. That should
211 * allow full ACL support on Mac OS, in particular, which uses
212 * POSIX.1e-style interfaces to manipulate NFSv4/NTFS permissions.
216 * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's
217 * "permset"/"perm" abstract type nonsense. A permset is just a simple
218 * bitmap, following long-standing Unix tradition.
220 #define ARCHIVE_ENTRY_ACL_EXECUTE 1
221 #define ARCHIVE_ENTRY_ACL_WRITE 2
222 #define ARCHIVE_ENTRY_ACL_READ 4
224 /* We need to be able to specify either or both of these. */
225 #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256
226 #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512
228 /* Tag values mimic POSIX.1e */
229 #define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
230 #define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
231 #define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
232 #define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
233 #define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */
234 #define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */
237 * Set the ACL by clearing it and adding entries one at a time.
238 * Unlike the POSIX.1e ACL routines, you must specify the type
239 * (access/default) for each entry. Internally, the ACL data is just
240 * a soup of entries. API calls here allow you to retrieve just the
241 * entries of interest. This design (which goes against the spirit of
242 * POSIX.1e) is useful for handling archive formats that combine
243 * default and access information in a single ACL list.
245 void archive_entry_acl_clear(struct archive_entry *);
246 void archive_entry_acl_add_entry(struct archive_entry *,
247 int /* type */, int /* permset */, int /* tag */,
248 int /* qual */, const char * /* name */);
249 void archive_entry_acl_add_entry_w(struct archive_entry *,
250 int /* type */, int /* permset */, int /* tag */,
251 int /* qual */, const wchar_t * /* name */);
254 * To retrieve the ACL, first "reset", then repeatedly ask for the
255 * "next" entry. The want_type parameter allows you to request only
256 * access entries or only default entries.
258 int archive_entry_acl_reset(struct archive_entry *, int /* want_type */);
259 int archive_entry_acl_next(struct archive_entry *, int /* want_type */,
260 int * /* type */, int * /* permset */, int * /* tag */,
261 int * /* qual */, const char ** /* name */);
262 int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */,
263 int * /* type */, int * /* permset */, int * /* tag */,
264 int * /* qual */, const wchar_t ** /* name */);
267 * Construct a text-format ACL. The flags argument is a bitmask that
268 * can include any of the following:
270 * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries.
271 * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries.
272 * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
273 * each ACL entry. (As used by 'star'.)
274 * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
277 #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
278 #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
279 const wchar_t *archive_entry_acl_text_w(struct archive_entry *,
282 /* Return a count of entries matching 'want_type' */
283 int archive_entry_acl_count(struct archive_entry *, int /* want_type */);
286 * Private ACL parser. This is private because it handles some
287 * very weird formats that clients should not be messing with.
288 * Clients should only deal with their platform-native formats.
289 * Because of the need to support many formats cleanly, new arguments
290 * are likely to get added on a regular basis. Clients who try to use
291 * this interface are likely to be surprised when it changes.
295 * TODO: Move this declaration out of the public header and into
296 * a private header. Warnings above are silly.
298 int __archive_entry_acl_parse_w(struct archive_entry *,
299 const wchar_t *, int /* type */);
302 * extended attributes
305 void archive_entry_xattr_clear(struct archive_entry *);
306 void archive_entry_xattr_add_entry(struct archive_entry *,
307 const char * /* name */, const void * /* value */,
311 * To retrieve the xattr list, first "reset", then repeatedly ask for the
315 int archive_entry_xattr_count(struct archive_entry *);
316 int archive_entry_xattr_reset(struct archive_entry *);
317 int archive_entry_xattr_next(struct archive_entry *,
318 const char ** /* name */, const void ** /* value */, size_t *);
321 * Utility to detect hardlinks.
323 * The 'struct archive_hardlink_lookup' is a cache of entry
324 * names and dev/ino numbers. Here's how to use it:
325 * 1. Create a lookup object with archive_hardlink_lookup_new()
326 * 2. Hand each archive_entry to archive_hardlink_lookup().
327 * That function will return NULL (this is not a hardlink to
328 * a previous entry) or the pathname of the first entry
330 * 3. Use archive_hardlink_lookup_free() to release the cache.
332 * To make things more efficient, be sure that each entry has a valid
333 * nlinks value. The hardlink cache uses this to track when all links
334 * have been found. If the nlinks value is zero, it will keep every
335 * name in the cache indefinitely, which can use a lot of memory.
337 struct archive_entry_linkresolver;
339 struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
340 void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
341 const char *archive_entry_linkresolve(struct archive_entry_linkresolver *,
342 struct archive_entry *);
348 #endif /* !ARCHIVE_ENTRY_H_INCLUDED */