Merge from vendor branch GCC:
[dragonfly.git] / contrib / 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.12 2004/08/08 07:39:19 kientzle Exp $
27  */
28
29 #ifndef ARCHIVE_ENTRY_H_INCLUDED
30 #define ARCHIVE_ENTRY_H_INCLUDED
31
32 #include <unistd.h>
33 #include <wchar.h>
34
35 /*
36  * Description of an archive entry.
37  *
38  * Basically, a "struct stat" with a few text fields added in.
39  *
40  * TODO: Add "comment", "charset", and possibly other entries that are
41  * supported by "pax interchange" format.  However, GNU, ustar, cpio,
42  * and other variants don't support these features, so they're not an
43  * excruciatingly high priority right now.
44  *
45  * TODO: "pax interchange" format allows essentially arbitrary
46  * key/value attributes to be attached to any entry.  Supporting
47  * such extensions may make this library useful for special
48  * applications (e.g., a package manager could attach special
49  * package-management attributes to each entry).
50  */
51 struct archive_entry;
52
53 /*
54  * Basic object manipulation
55  */
56
57 struct archive_entry    *archive_entry_clear(struct archive_entry *);
58 /* The 'clone' function does a deep copy; all of the strings are copied too. */
59 struct archive_entry    *archive_entry_clone(struct archive_entry *);
60 void                     archive_entry_free(struct archive_entry *);
61 struct archive_entry    *archive_entry_new(void);
62
63 /*
64  * Retrieve fields from an archive_entry.
65  */
66
67 time_t                   archive_entry_atime(struct archive_entry *);
68 long                     archive_entry_atime_nsec(struct archive_entry *);
69 dev_t                    archive_entry_dev(struct archive_entry *);
70 void                     archive_entry_fflags(struct archive_entry *,
71                              unsigned long *set, unsigned long *clear);
72 const char              *archive_entry_fflags_text(struct archive_entry *);
73 gid_t                    archive_entry_gid(struct archive_entry *);
74 const char              *archive_entry_gname(struct archive_entry *);
75 const char              *archive_entry_hardlink(struct archive_entry *);
76 ino_t                    archive_entry_ino(struct archive_entry *);
77 mode_t                   archive_entry_mode(struct archive_entry *);
78 time_t                   archive_entry_mtime(struct archive_entry *);
79 long                     archive_entry_mtime_nsec(struct archive_entry *);
80 const char              *archive_entry_pathname(struct archive_entry *);
81 const wchar_t           *archive_entry_pathname_w(struct archive_entry *);
82 dev_t                    archive_entry_rdev(struct archive_entry *);
83 dev_t                    archive_entry_rdevmajor(struct archive_entry *);
84 dev_t                    archive_entry_rdevminor(struct archive_entry *);
85 int64_t                  archive_entry_size(struct archive_entry *);
86 const struct stat       *archive_entry_stat(struct archive_entry *);
87 const char              *archive_entry_symlink(struct archive_entry *);
88 uid_t                    archive_entry_uid(struct archive_entry *);
89 const char              *archive_entry_uname(struct archive_entry *);
90
91 /*
92  * Set fields in an archive_entry.
93  *
94  * Note that string 'set' functions do not copy the string, only the pointer.
95  * In contrast, 'copy' functions do copy the object pointed to.
96  */
97
98 void    archive_entry_copy_stat(struct archive_entry *, const struct stat *);
99 void    archive_entry_set_fflags(struct archive_entry *,
100             unsigned long set, unsigned long clear);
101 /* Returns pointer to start of first invalid token, or NULL if none. */
102 /* Note that all recognized tokens are processed, regardless. */
103 const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *,
104             const wchar_t *);
105 void    archive_entry_set_gid(struct archive_entry *, gid_t);
106 void    archive_entry_set_gname(struct archive_entry *, const char *);
107 void    archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *);
108 void    archive_entry_set_hardlink(struct archive_entry *, const char *);
109 void    archive_entry_copy_hardlink(struct archive_entry *, const char *);
110 void    archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *);
111 void    archive_entry_set_link(struct archive_entry *, const char *);
112 void    archive_entry_set_mode(struct archive_entry *, mode_t);
113 void    archive_entry_set_mtime(struct archive_entry *, time_t, long);
114 void    archive_entry_set_pathname(struct archive_entry *, const char *);
115 void    archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *);
116 void    archive_entry_set_rdevmajor(struct archive_entry *, dev_t);
117 void    archive_entry_set_rdevminor(struct archive_entry *, dev_t);
118 void    archive_entry_set_size(struct archive_entry *, int64_t);
119 void    archive_entry_set_symlink(struct archive_entry *, const char *);
120 void    archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *);
121 void    archive_entry_set_uid(struct archive_entry *, uid_t);
122 void    archive_entry_set_uname(struct archive_entry *, const char *);
123 void    archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *);
124
125 /*
126  * ACL routines.  This used to simply store and return text-format ACL
127  * strings, but that proved insufficient for a number of reasons:
128  *   = clients need control over uname/uid and gname/gid mappings
129  *   = there are many different ACL text formats
130  *   = would like to be able to read/convert archives containing ACLs
131  *     on platforms that lack ACL libraries
132  */
133
134 /*
135  * Permission bits mimic POSIX.1e.  Note that I've not followed POSIX.1e's
136  * "permset"/"perm" abstract type nonsense.  A permset is just a simple
137  * bitmap, following long-standing Unix tradition.
138  */
139 #define ARCHIVE_ENTRY_ACL_EXECUTE       1
140 #define ARCHIVE_ENTRY_ACL_WRITE         2
141 #define ARCHIVE_ENTRY_ACL_READ          4
142
143 /* We need to be able to specify either or both of these. */
144 #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS   256
145 #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT  512
146
147 /* Tag values mimic POSIX.1e */
148 #define ARCHIVE_ENTRY_ACL_USER          10001   /* Specified user. */
149 #define ARCHIVE_ENTRY_ACL_USER_OBJ      10002   /* User who owns the file. */
150 #define ARCHIVE_ENTRY_ACL_GROUP         10003   /* Specified group. */
151 #define ARCHIVE_ENTRY_ACL_GROUP_OBJ     10004   /* Group who owns the file. */
152 #define ARCHIVE_ENTRY_ACL_MASK          10005   /* Modify group access. */
153 #define ARCHIVE_ENTRY_ACL_OTHER         10006   /* Public. */
154
155 /*
156  * Set the ACL by clearing it and adding entries one at a time.
157  * Unlike the POSIX.1e ACL routines, you must specify the type
158  * (access/default) for each entry.  Internally, the ACL data is just
159  * a soup of entries.  API calls here allow you to retrieve just the
160  * entries of interest.  This design (which goes against the spirit of
161  * POSIX.1e) is useful for handling archive formats that combine
162  * default and access information in a single ACL list.
163  */
164 void     archive_entry_acl_clear(struct archive_entry *);
165 void     archive_entry_acl_add_entry(struct archive_entry *,
166              int type, int permset, int tag, int qual, const char *name);
167 void     archive_entry_acl_add_entry_w(struct archive_entry *,
168              int type, int permset, int tag, int qual, const wchar_t *name);
169
170 /*
171  * To retrieve the ACL, first "reset", then repeatedly ask for the
172  * "next" entry.  The want_type parameter allows you to request only
173  * access entries or only default entries.
174  */
175 int      archive_entry_acl_reset(struct archive_entry *, int want_type);
176 int      archive_entry_acl_next(struct archive_entry *, int want_type,
177              int *type, int *permset, int *tag, int *qual, const char **name);
178 int      archive_entry_acl_next_w(struct archive_entry *, int want_type,
179              int *type, int *permset, int *tag, int *qual,
180              const wchar_t **name);
181
182 /*
183  * Construct a text-format ACL.  The flags argument is a bitmask that
184  * can include any of the following:
185  *
186  * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include access entries.
187  * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include default entries.
188  * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in
189  *    each ACL entry.  (As used by 'star'.)
190  * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each
191  *    default ACL entry.
192  */
193 #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID        1024
194 #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT    2048
195 const wchar_t   *archive_entry_acl_text_w(struct archive_entry *, int flags);
196
197 /* Return a count of entries matching 'want_type' */
198 int      archive_entry_acl_count(struct archive_entry *, int want_type);
199
200 /*
201  * Private ACL parser.  This is private because it handles some
202  * very weird formats that clients should not be messing with.
203  * Clients should only deal with their platform-native formats.
204  * Because of the need to support many formats cleanly, new arguments
205  * are likely to get added on a regular basis.  Clients who try to use
206  * this interface are likely to be surprised when it changes.
207  *
208  * You were warned!
209  */
210 int              __archive_entry_acl_parse_w(struct archive_entry *,
211                      const wchar_t *, int type);
212
213 #endif /* !ARCHIVE_ENTRY_H_INCLUDED */