1 /*-
2  * Copyright (c) 2003-2007 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: src/lib/libarchive/archive_entry_private.h,v 1.6 2008/09/30 03:53:03 kientzle Exp $
26  */
27 
28 #ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
29 #define	ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
30 
31 #include "archive_string.h"
32 
33 /*
34  * Handle wide character (i.e., Unicode) and non-wide character
35  * strings transparently.
36  */
37 
38 struct aes {
39 	struct archive_string aes_mbs;
40 	struct archive_string aes_utf8;
41 	const wchar_t *aes_wcs;
42 	/* Bitmap of which of the above are valid.  Because we're lazy
43 	 * about malloc-ing and reusing the underlying storage, we
44 	 * can't rely on NULL pointers to indicate whether a string
45 	 * has been set. */
46 	int aes_set;
47 #define	AES_SET_MBS 1
48 #define	AES_SET_UTF8 2
49 #define	AES_SET_WCS 4
50 };
51 
52 struct ae_acl {
53 	struct ae_acl *next;
54 	int	type;			/* E.g., access or default */
55 	int	tag;			/* E.g., user/group/other/mask */
56 	int	permset;		/* r/w/x bits */
57 	int	id;			/* uid/gid for user/group */
58 	struct aes name;		/* uname/gname */
59 };
60 
61 struct ae_xattr {
62 	struct ae_xattr *next;
63 
64 	char	*name;
65 	void	*value;
66 	size_t	size;
67 };
68 
69 /*
70  * Description of an archive entry.
71  *
72  * Basically, this is a "struct stat" with a few text fields added in.
73  *
74  * TODO: Add "comment", "charset", and possibly other entries
75  * that are supported by "pax interchange" format.  However, GNU, ustar,
76  * cpio, and other variants don't support these features, so they're not an
77  * excruciatingly high priority right now.
78  *
79  * TODO: "pax interchange" format allows essentially arbitrary
80  * key/value attributes to be attached to any entry.  Supporting
81  * such extensions may make this library useful for special
82  * applications (e.g., a package manager could attach special
83  * package-management attributes to each entry).  There are tricky
84  * API issues involved, so this is not going to happen until
85  * there's a real demand for it.
86  *
87  * TODO: Design a good API for handling sparse files.
88  */
89 struct archive_entry {
90 	/*
91 	 * Note that ae_stat.st_mode & AE_IFMT  can be  0!
92 	 *
93 	 * This occurs when the actual file type of the object is not
94 	 * in the archive.  For example, 'tar' archives store
95 	 * hardlinks without marking the type of the underlying
96 	 * object.
97 	 */
98 
99 	/*
100 	 * We have a "struct aest" for holding file metadata rather than just
101 	 * a "struct stat" because on some platforms the "struct stat" has
102 	 * fields which are too narrow to hold the range of possible values;
103 	 * we don't want to lose information if we read an archive and write
104 	 * out another (e.g., in "tar -cf new.tar @old.tar").
105 	 *
106 	 * The "stat" pointer points to some form of platform-specific struct
107 	 * stat; it is declared as a void * rather than a struct stat * as
108 	 * some platforms have multiple varieties of stat structures.
109 	 */
110 	void *stat;
111 	int  stat_valid; /* Set to 0 whenever a field in aest changes. */
112 
113 	struct aest {
114 		int64_t		aest_atime;
115 		uint32_t	aest_atime_nsec;
116 		int64_t		aest_ctime;
117 		uint32_t	aest_ctime_nsec;
118 		int64_t		aest_mtime;
119 		uint32_t	aest_mtime_nsec;
120 		int64_t		aest_birthtime;
121 		uint32_t	aest_birthtime_nsec;
122 		gid_t		aest_gid;
123 		ino_t		aest_ino;
124 		mode_t		aest_mode;
125 		uint32_t	aest_nlink;
126 		uint64_t	aest_size;
127 		uid_t		aest_uid;
128 		/*
129 		 * Because converting between device codes and
130 		 * major/minor values is platform-specific and
131 		 * inherently a bit risky, we only do that conversion
132 		 * lazily.  That way, we will do a better job of
133 		 * preserving information in those cases where no
134 		 * conversion is actually required.
135 		 */
136 		int		aest_dev_is_broken_down;
137 		dev_t		aest_dev;
138 		dev_t		aest_devmajor;
139 		dev_t		aest_devminor;
140 		int		aest_rdev_is_broken_down;
141 		dev_t		aest_rdev;
142 		dev_t		aest_rdevmajor;
143 		dev_t		aest_rdevminor;
144 	} ae_stat;
145 
146 	int ae_set; /* bitmap of fields that are currently set */
147 #define	AE_SET_HARDLINK	1
148 #define	AE_SET_SYMLINK	2
149 #define	AE_SET_ATIME	4
150 #define	AE_SET_CTIME	8
151 #define	AE_SET_MTIME	16
152 #define	AE_SET_BIRTHTIME 32
153 #define	AE_SET_SIZE	64
154 
155 	/*
156 	 * Use aes here so that we get transparent mbs<->wcs conversions.
157 	 */
158 	struct aes ae_fflags_text;	/* Text fflags per fflagstostr(3) */
159 	unsigned long ae_fflags_set;		/* Bitmap fflags */
160 	unsigned long ae_fflags_clear;
161 	struct aes ae_gname;		/* Name of owning group */
162 	struct aes ae_hardlink;	/* Name of target for hardlink */
163 	struct aes ae_pathname;	/* Name of entry */
164 	struct aes ae_symlink;		/* symlink contents */
165 	struct aes ae_uname;		/* Name of owner */
166 
167 	/* Not used within libarchive; useful for some clients. */
168 	struct aes ae_sourcepath;	/* Path this entry is sourced from. */
169 
170 	/* ACL support. */
171 	struct ae_acl	*acl_head;
172 	struct ae_acl	*acl_p;
173 	int		 acl_state;	/* See acl_next for details. */
174 	wchar_t		*acl_text_w;
175 
176 	/* extattr support. */
177 	struct ae_xattr *xattr_head;
178 	struct ae_xattr *xattr_p;
179 
180 	/* Miscellaneous. */
181 	char		 strmode[12];
182 };
183 
184 
185 #endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
186