Remove old prototypes of consinit() (which was removed along with pcvt(4))
[dragonfly.git] / contrib / libarchive-2 / libarchive / archive_entry.h
blob33c5649a9f17653a2ecf2378078d82a5d1f6caa9
1 /*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
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.
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.
25 * $FreeBSD: src/lib/libarchive/archive_entry.h,v 1.23 2007/07/15 19:10:34 kientzle Exp $
28 #ifndef ARCHIVE_ENTRY_H_INCLUDED
29 #define ARCHIVE_ENTRY_H_INCLUDED
31 #include <sys/types.h>
32 #include <stddef.h> /* for wchar_t */
33 #include <time.h>
34 #include <unistd.h>
36 #ifdef __cplusplus
37 extern "C" {
38 #endif
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).
57 struct archive_entry;
60 * File-type constants. These are returned from archive_entry_filetype().
62 #define AE_IFMT 0170000
63 #define AE_IFREG 0100000
64 #define AE_IFLNK 0120000
65 #define AE_IFSOCK 0140000
66 #define AE_IFCHR 0020000
67 #define AE_IFBLK 0060000
68 #define AE_IFDIR 0040000
69 #define AE_IFIFO 0010000
72 * Basic object manipulation
75 struct archive_entry *archive_entry_clear(struct archive_entry *);
76 /* The 'clone' function does a deep copy; all of the strings are copied too. */
77 struct archive_entry *archive_entry_clone(struct archive_entry *);
78 void archive_entry_free(struct archive_entry *);
79 struct archive_entry *archive_entry_new(void);
82 * Retrieve fields from an archive_entry.
85 time_t archive_entry_atime(struct archive_entry *);
86 long archive_entry_atime_nsec(struct archive_entry *);
87 time_t archive_entry_ctime(struct archive_entry *);
88 long archive_entry_ctime_nsec(struct archive_entry *);
89 dev_t archive_entry_dev(struct archive_entry *);
90 dev_t archive_entry_devmajor(struct archive_entry *);
91 dev_t archive_entry_devminor(struct archive_entry *);
92 mode_t archive_entry_filetype(struct archive_entry *);
93 void archive_entry_fflags(struct archive_entry *,
94 unsigned long *set, unsigned long *clear);
95 const char *archive_entry_fflags_text(struct archive_entry *);
96 gid_t archive_entry_gid(struct archive_entry *);
97 const char *archive_entry_gname(struct archive_entry *);
98 const wchar_t *archive_entry_gname_w(struct archive_entry *);
99 const char *archive_entry_hardlink(struct archive_entry *);
100 const wchar_t *archive_entry_hardlink_w(struct archive_entry *);
101 ino_t archive_entry_ino(struct archive_entry *);
102 mode_t archive_entry_mode(struct archive_entry *);
103 time_t archive_entry_mtime(struct archive_entry *);
104 long archive_entry_mtime_nsec(struct archive_entry *);
105 unsigned int archive_entry_nlink(struct archive_entry *);
106 const char *archive_entry_pathname(struct archive_entry *);
107 const wchar_t *archive_entry_pathname_w(struct archive_entry *);
108 dev_t archive_entry_rdev(struct archive_entry *);
109 dev_t archive_entry_rdevmajor(struct archive_entry *);
110 dev_t archive_entry_rdevminor(struct archive_entry *);
111 int64_t archive_entry_size(struct archive_entry *);
112 const char *archive_entry_strmode(struct archive_entry *);
113 const char *archive_entry_symlink(struct archive_entry *);
114 const wchar_t *archive_entry_symlink_w(struct archive_entry *);
115 uid_t archive_entry_uid(struct archive_entry *);
116 const char *archive_entry_uname(struct archive_entry *);
117 const wchar_t *archive_entry_uname_w(struct archive_entry *);
120 * Set fields in an archive_entry.
122 * Note that string 'set' functions do not copy the string, only the pointer.
123 * In contrast, 'copy' functions do copy the object pointed to.
126 void archive_entry_set_atime(struct archive_entry *, time_t, long);
127 void archive_entry_set_ctime(struct archive_entry *, time_t, long);
128 void archive_entry_set_dev(struct archive_entry *, dev_t);
129 void archive_entry_set_devmajor(struct archive_entry *, dev_t);
130 void archive_entry_set_devminor(struct archive_entry *, dev_t);
131 void archive_entry_set_filetype(struct archive_entry *, unsigned int);
132 void archive_entry_set_fflags(struct archive_entry *,
133 unsigned long set, unsigned long clear);
134 /* Returns pointer to start of first invalid token, or NULL if none. */
135 /* Note that all recognized tokens are processed, regardless. */
136 const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
137 const wchar_t *);
138 void archive_entry_set_gid(struct archive_entry *, gid_t);
139 void archive_entry_set_gname(struct archive_entry *, const char *);
140 void archive_entry_copy_gname(struct archive_entry *, const char *);
141 void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
142 void archive_entry_set_hardlink(struct archive_entry *, const char *);
143 void archive_entry_copy_hardlink(struct archive_entry *, const char *);
144 void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
145 void archive_entry_set_ino(struct archive_entry *, unsigned long);
146 void archive_entry_set_link(struct archive_entry *, const char *);
147 void archive_entry_set_mode(struct archive_entry *, mode_t);
148 void archive_entry_set_mtime(struct archive_entry *, time_t, long);
149 void archive_entry_set_nlink(struct archive_entry *, unsigned int);
150 void archive_entry_set_pathname(struct archive_entry *, const char *);
151 void archive_entry_copy_pathname(struct archive_entry *, const char *);
152 void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
153 void archive_entry_set_perm(struct archive_entry *, mode_t);
154 void archive_entry_set_rdev(struct archive_entry *, dev_t);
155 void archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
156 void archive_entry_set_rdevminor(struct archive_entry *, dev_t);
157 void archive_entry_set_size(struct archive_entry *, int64_t);
158 void archive_entry_set_symlink(struct archive_entry *, const char *);
159 void archive_entry_copy_symlink(struct archive_entry *, const char *);
160 void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
161 void archive_entry_set_uid(struct archive_entry *, uid_t);
162 void archive_entry_set_uname(struct archive_entry *, const char *);
163 void archive_entry_copy_uname(struct archive_entry *, const char *);
164 void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
167 * Routines to bulk copy fields to/from a platform-native "struct
168 * stat." Libarchive used to just store a struct stat inside of each
169 * archive_entry object, but this created issues when trying to
170 * manipulate archives on systems different than the ones they were
171 * created on.
173 * TODO: On Linux, provide both stat32 and stat64 versions of these functions.
175 const struct stat *archive_entry_stat(struct archive_entry *);
176 void archive_entry_copy_stat(struct archive_entry *, const struct stat *);
179 * ACL routines. This used to simply store and return text-format ACL
180 * strings, but that proved insufficient for a number of reasons:
181 * = clients need control over uname/uid and gname/gid mappings
182 * = there are many different ACL text formats
183 * = would like to be able to read/convert archives containing ACLs
184 * on platforms that lack ACL libraries
188 * Permission bits mimic POSIX.1e. Note that I've not followed POSIX.1e's
189 * "permset"/"perm" abstract type nonsense. A permset is just a simple
190 * bitmap, following long-standing Unix tradition.
192 #define ARCHIVE_ENTRY_ACL_EXECUTE 1
193 #define ARCHIVE_ENTRY_ACL_WRITE 2
194 #define ARCHIVE_ENTRY_ACL_READ 4
196 /* We need to be able to specify either or both of these. */
197 #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256
198 #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512
200 /* Tag values mimic POSIX.1e */
201 #define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */
202 #define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */
203 #define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */
204 #define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */
205 #define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access. */
206 #define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public. */
209 * Set the ACL by clearing it and adding entries one at a time.
210 * Unlike the POSIX.1e ACL routines, you must specify the type
211 * (access/default) for each entry. Internally, the ACL data is just
212 * a soup of entries. API calls here allow you to retrieve just the
213 * entries of interest. This design (which goes against the spirit of
214 * POSIX.1e) is useful for handling archive formats that combine
215 * default and access information in a single ACL list.
217 void archive_entry_acl_clear(struct archive_entry *);
218 void archive_entry_acl_add_entry(struct archive_entry *,
219 int type, int permset, int tag, int qual, const char *name);
220 void archive_entry_acl_add_entry_w(struct archive_entry *,
221 int type, int permset, int tag, int qual, const wchar_t *name);
224 * To retrieve the ACL, first "reset", then repeatedly ask for the
225 * "next" entry. The want_type parameter allows you to request only
226 * access entries or only default entries.
228 int archive_entry_acl_reset(struct archive_entry *, int want_type);
229 int archive_entry_acl_next(struct archive_entry *, int want_type,
230 int *type, int *permset, int *tag, int *qual, const char **name);
231 int archive_entry_acl_next_w(struct archive_entry *, int want_type,
232 int *type, int *permset, int *tag, int *qual,
233 const wchar_t **name);
236 * Construct a text-format ACL. The flags argument is a bitmask that
237 * can include any of the following:
239 * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries.
240 * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries.
241 * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
242 * each ACL entry. (As used by 'star'.)
243 * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
244 * default ACL entry.
246 #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024
247 #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048
248 const wchar_t *archive_entry_acl_text_w(struct archive_entry *, int flags);
250 /* Return a count of entries matching 'want_type' */
251 int archive_entry_acl_count(struct archive_entry *, int want_type);
254 * Private ACL parser. This is private because it handles some
255 * very weird formats that clients should not be messing with.
256 * Clients should only deal with their platform-native formats.
257 * Because of the need to support many formats cleanly, new arguments
258 * are likely to get added on a regular basis. Clients who try to use
259 * this interface are likely to be surprised when it changes.
261 * You were warned!
263 int __archive_entry_acl_parse_w(struct archive_entry *,
264 const wchar_t *, int type);
267 * extended attributes
270 void archive_entry_xattr_clear(struct archive_entry *);
271 void archive_entry_xattr_add_entry(struct archive_entry *,
272 const char *name, const void *value, size_t size);
275 * To retrieve the xattr list, first "reset", then repeatedly ask for the
276 * "next" entry.
279 int archive_entry_xattr_count(struct archive_entry *);
280 int archive_entry_xattr_reset(struct archive_entry *);
281 int archive_entry_xattr_next(struct archive_entry *,
282 const char **name, const void **value, size_t *);
285 * Utility to detect hardlinks.
287 * The 'struct archive_hardlink_lookup' is a cache of entry
288 * names and dev/ino numbers. Here's how to use it:
289 * 1. Create a lookup object with archive_hardlink_lookup_new()
290 * 2. Hand each archive_entry to archive_hardlink_lookup().
291 * That function will return NULL (this is not a hardlink to
292 * a previous entry) or the pathname of the first entry
293 * that matched this.
294 * 3. Use archive_hardlink_lookup_free() to release the cache.
296 * To make things more efficient, be sure that each entry has a valid
297 * nlinks value. The hardlink cache uses this to track when all links
298 * have been found. If the nlinks value is zero, it will keep every
299 * name in the cache indefinitely, which can use a lot of memory.
301 struct archive_entry_linkresolver;
303 struct archive_entry_linkresolver *archive_entry_linkresolver_new(void);
304 void archive_entry_linkresolver_free(struct archive_entry_linkresolver *);
305 const char *archive_entry_linkresolve(struct archive_entry_linkresolver *,
306 struct archive_entry *);
308 #ifdef __cplusplus
310 #endif
312 #endif /* !ARCHIVE_ENTRY_H_INCLUDED */