1228753Smm/*-
2228753Smm * Copyright (c) 2003-2007 Tim Kientzle
3228753Smm * All rights reserved.
4228753Smm *
5228753Smm * Redistribution and use in source and binary forms, with or without
6228753Smm * modification, are permitted provided that the following conditions
7228753Smm * are met:
8228753Smm * 1. Redistributions of source code must retain the above copyright
9228753Smm *    notice, this list of conditions and the following disclaimer.
10228753Smm * 2. Redistributions in binary form must reproduce the above copyright
11228753Smm *    notice, this list of conditions and the following disclaimer in the
12228753Smm *    documentation and/or other materials provided with the distribution.
13228753Smm *
14228753Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15228753Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16228753Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17228753Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18228753Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19228753Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20228753Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21228753Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22228753Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23228753Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24228753Smm *
25229592Smm * $FreeBSD$
26228753Smm */
27228753Smm
28228753Smm#ifndef __LIBARCHIVE_BUILD
29228753Smm#error This header is only to be used internally to libarchive.
30228753Smm#endif
31228753Smm
32228753Smm#ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
33228753Smm#define	ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
34228753Smm
35228753Smm#include "archive_string.h"
36228753Smm
37228753Smm/*
38228753Smm * Handle wide character (i.e., Unicode) and non-wide character
39228753Smm * strings transparently.
40228753Smm */
41228753Smm
42228753Smmstruct aes {
43228753Smm	struct archive_string aes_mbs;
44228753Smm	struct archive_string aes_utf8;
45228753Smm	const wchar_t *aes_wcs;
46228753Smm	/* Bitmap of which of the above are valid.  Because we're lazy
47228753Smm	 * about malloc-ing and reusing the underlying storage, we
48228753Smm	 * can't rely on NULL pointers to indicate whether a string
49228753Smm	 * has been set. */
50228753Smm	int aes_set;
51228753Smm#define	AES_SET_MBS 1
52228753Smm#define	AES_SET_UTF8 2
53228753Smm#define	AES_SET_WCS 4
54228753Smm};
55228753Smm
56228753Smmstruct ae_acl {
57228753Smm	struct ae_acl *next;
58228753Smm	int	type;			/* E.g., access or default */
59228753Smm	int	tag;			/* E.g., user/group/other/mask */
60228753Smm	int	permset;		/* r/w/x bits */
61228753Smm	int	id;			/* uid/gid for user/group */
62228753Smm	struct aes name;		/* uname/gname */
63228753Smm};
64228753Smm
65228753Smmstruct ae_xattr {
66228753Smm	struct ae_xattr *next;
67228753Smm
68228753Smm	char	*name;
69228753Smm	void	*value;
70228753Smm	size_t	size;
71228753Smm};
72228753Smm
73228753Smm/*
74228753Smm * Description of an archive entry.
75228753Smm *
76228753Smm * Basically, this is a "struct stat" with a few text fields added in.
77228753Smm *
78228753Smm * TODO: Add "comment", "charset", and possibly other entries
79228753Smm * that are supported by "pax interchange" format.  However, GNU, ustar,
80228753Smm * cpio, and other variants don't support these features, so they're not an
81228753Smm * excruciatingly high priority right now.
82228753Smm *
83228753Smm * TODO: "pax interchange" format allows essentially arbitrary
84228753Smm * key/value attributes to be attached to any entry.  Supporting
85228753Smm * such extensions may make this library useful for special
86228753Smm * applications (e.g., a package manager could attach special
87228753Smm * package-management attributes to each entry).  There are tricky
88228753Smm * API issues involved, so this is not going to happen until
89228753Smm * there's a real demand for it.
90228753Smm *
91228753Smm * TODO: Design a good API for handling sparse files.
92228753Smm */
93228753Smmstruct archive_entry {
94228753Smm	/*
95228753Smm	 * Note that ae_stat.st_mode & AE_IFMT  can be  0!
96228753Smm	 *
97228753Smm	 * This occurs when the actual file type of the object is not
98228753Smm	 * in the archive.  For example, 'tar' archives store
99228753Smm	 * hardlinks without marking the type of the underlying
100228753Smm	 * object.
101228753Smm	 */
102228753Smm
103228753Smm	/*
104228753Smm	 * Read archive_entry_copy_stat.c for an explanation of why I
105228753Smm	 * don't just use "struct stat" instead of "struct aest" here
106228753Smm	 * and why I have this odd pointer to a separately-allocated
107228753Smm	 * struct stat.
108228753Smm	 */
109228753Smm	void *stat;
110228753Smm	int  stat_valid; /* Set to 0 whenever a field in aest changes. */
111228753Smm
112228753Smm	struct aest {
113228753Smm		int64_t		aest_atime;
114228753Smm		uint32_t	aest_atime_nsec;
115228753Smm		int64_t		aest_ctime;
116228753Smm		uint32_t	aest_ctime_nsec;
117228753Smm		int64_t		aest_mtime;
118228753Smm		uint32_t	aest_mtime_nsec;
119228753Smm		int64_t		aest_birthtime;
120228753Smm		uint32_t	aest_birthtime_nsec;
121228753Smm		gid_t		aest_gid;
122228753Smm		int64_t		aest_ino;
123228753Smm		mode_t		aest_mode;
124228753Smm		uint32_t	aest_nlink;
125228753Smm		uint64_t	aest_size;
126228753Smm		uid_t		aest_uid;
127228753Smm		/*
128228753Smm		 * Because converting between device codes and
129228753Smm		 * major/minor values is platform-specific and
130228753Smm		 * inherently a bit risky, we only do that conversion
131228753Smm		 * lazily.  That way, we will do a better job of
132228753Smm		 * preserving information in those cases where no
133228753Smm		 * conversion is actually required.
134228753Smm		 */
135228753Smm		int		aest_dev_is_broken_down;
136228753Smm		dev_t		aest_dev;
137228753Smm		dev_t		aest_devmajor;
138228753Smm		dev_t		aest_devminor;
139228753Smm		int		aest_rdev_is_broken_down;
140228753Smm		dev_t		aest_rdev;
141228753Smm		dev_t		aest_rdevmajor;
142228753Smm		dev_t		aest_rdevminor;
143228753Smm	} ae_stat;
144228753Smm
145228753Smm	int ae_set; /* bitmap of fields that are currently set */
146228753Smm#define	AE_SET_HARDLINK	1
147228753Smm#define	AE_SET_SYMLINK	2
148228753Smm#define	AE_SET_ATIME	4
149228753Smm#define	AE_SET_CTIME	8
150228753Smm#define	AE_SET_MTIME	16
151228753Smm#define	AE_SET_BIRTHTIME 32
152228753Smm#define	AE_SET_SIZE	64
153228753Smm
154228753Smm	/*
155228753Smm	 * Use aes here so that we get transparent mbs<->wcs conversions.
156228753Smm	 */
157228753Smm	struct aes ae_fflags_text;	/* Text fflags per fflagstostr(3) */
158228753Smm	unsigned long ae_fflags_set;		/* Bitmap fflags */
159228753Smm	unsigned long ae_fflags_clear;
160228753Smm	struct aes ae_gname;		/* Name of owning group */
161228753Smm	struct aes ae_hardlink;	/* Name of target for hardlink */
162228753Smm	struct aes ae_pathname;	/* Name of entry */
163228753Smm	struct aes ae_symlink;		/* symlink contents */
164228753Smm	struct aes ae_uname;		/* Name of owner */
165228753Smm
166228753Smm	/* Not used within libarchive; useful for some clients. */
167228753Smm	struct aes ae_sourcepath;	/* Path this entry is sourced from. */
168228753Smm
169228753Smm	/* ACL support. */
170228753Smm	struct ae_acl	*acl_head;
171228753Smm	struct ae_acl	*acl_p;
172228753Smm	int		 acl_state;	/* See acl_next for details. */
173228753Smm	wchar_t		*acl_text_w;
174228753Smm
175228753Smm	/* extattr support. */
176228753Smm	struct ae_xattr *xattr_head;
177228753Smm	struct ae_xattr *xattr_p;
178228753Smm
179228753Smm	/* Miscellaneous. */
180228753Smm	char		 strmode[12];
181228753Smm};
182228753Smm
183228753Smm
184228753Smm#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
185