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