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 *
25228763Smm * $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
35232153Smm#include "archive_acl_private.h"
36228753Smm#include "archive_string.h"
37228753Smm
38228753Smmstruct ae_xattr {
39228753Smm	struct ae_xattr *next;
40228753Smm
41228753Smm	char	*name;
42228753Smm	void	*value;
43228753Smm	size_t	size;
44228753Smm};
45228753Smm
46232153Smmstruct ae_sparse {
47232153Smm	struct ae_sparse *next;
48232153Smm
49232153Smm	int64_t	 offset;
50232153Smm	int64_t	 length;
51232153Smm};
52232153Smm
53228753Smm/*
54228753Smm * Description of an archive entry.
55228753Smm *
56228753Smm * Basically, this is a "struct stat" with a few text fields added in.
57228753Smm *
58228753Smm * TODO: Add "comment", "charset", and possibly other entries
59228753Smm * that are supported by "pax interchange" format.  However, GNU, ustar,
60228753Smm * cpio, and other variants don't support these features, so they're not an
61228753Smm * excruciatingly high priority right now.
62228753Smm *
63228753Smm * TODO: "pax interchange" format allows essentially arbitrary
64228753Smm * key/value attributes to be attached to any entry.  Supporting
65228753Smm * such extensions may make this library useful for special
66228753Smm * applications (e.g., a package manager could attach special
67228753Smm * package-management attributes to each entry).  There are tricky
68228753Smm * API issues involved, so this is not going to happen until
69228753Smm * there's a real demand for it.
70228753Smm *
71228753Smm * TODO: Design a good API for handling sparse files.
72228753Smm */
73228753Smmstruct archive_entry {
74232153Smm	struct archive *archive;
75232153Smm
76228753Smm	/*
77228753Smm	 * Note that ae_stat.st_mode & AE_IFMT  can be  0!
78228753Smm	 *
79228753Smm	 * This occurs when the actual file type of the object is not
80228753Smm	 * in the archive.  For example, 'tar' archives store
81228753Smm	 * hardlinks without marking the type of the underlying
82228753Smm	 * object.
83228753Smm	 */
84228753Smm
85228753Smm	/*
86232153Smm	 * We have a "struct aest" for holding file metadata rather than just
87232153Smm	 * a "struct stat" because on some platforms the "struct stat" has
88232153Smm	 * fields which are too narrow to hold the range of possible values;
89232153Smm	 * we don't want to lose information if we read an archive and write
90232153Smm	 * out another (e.g., in "tar -cf new.tar @old.tar").
91232153Smm	 *
92232153Smm	 * The "stat" pointer points to some form of platform-specific struct
93232153Smm	 * stat; it is declared as a void * rather than a struct stat * as
94232153Smm	 * some platforms have multiple varieties of stat structures.
95228753Smm	 */
96228753Smm	void *stat;
97228753Smm	int  stat_valid; /* Set to 0 whenever a field in aest changes. */
98228753Smm
99228753Smm	struct aest {
100228753Smm		int64_t		aest_atime;
101228753Smm		uint32_t	aest_atime_nsec;
102228753Smm		int64_t		aest_ctime;
103228753Smm		uint32_t	aest_ctime_nsec;
104228753Smm		int64_t		aest_mtime;
105228753Smm		uint32_t	aest_mtime_nsec;
106228753Smm		int64_t		aest_birthtime;
107228753Smm		uint32_t	aest_birthtime_nsec;
108232153Smm		int64_t		aest_gid;
109228753Smm		int64_t		aest_ino;
110228753Smm		uint32_t	aest_nlink;
111228753Smm		uint64_t	aest_size;
112232153Smm		int64_t		aest_uid;
113228753Smm		/*
114228753Smm		 * Because converting between device codes and
115228753Smm		 * major/minor values is platform-specific and
116228753Smm		 * inherently a bit risky, we only do that conversion
117228753Smm		 * lazily.  That way, we will do a better job of
118228753Smm		 * preserving information in those cases where no
119228753Smm		 * conversion is actually required.
120228753Smm		 */
121228753Smm		int		aest_dev_is_broken_down;
122228753Smm		dev_t		aest_dev;
123228753Smm		dev_t		aest_devmajor;
124228753Smm		dev_t		aest_devminor;
125228753Smm		int		aest_rdev_is_broken_down;
126228753Smm		dev_t		aest_rdev;
127228753Smm		dev_t		aest_rdevmajor;
128228753Smm		dev_t		aest_rdevminor;
129228753Smm	} ae_stat;
130228753Smm
131228753Smm	int ae_set; /* bitmap of fields that are currently set */
132228753Smm#define	AE_SET_HARDLINK	1
133228753Smm#define	AE_SET_SYMLINK	2
134228753Smm#define	AE_SET_ATIME	4
135228753Smm#define	AE_SET_CTIME	8
136228753Smm#define	AE_SET_MTIME	16
137228753Smm#define	AE_SET_BIRTHTIME 32
138228753Smm#define	AE_SET_SIZE	64
139232153Smm#define	AE_SET_INO	128
140232153Smm#define	AE_SET_DEV	256
141228753Smm
142228753Smm	/*
143228753Smm	 * Use aes here so that we get transparent mbs<->wcs conversions.
144228753Smm	 */
145232153Smm	struct archive_mstring ae_fflags_text;	/* Text fflags per fflagstostr(3) */
146228753Smm	unsigned long ae_fflags_set;		/* Bitmap fflags */
147228753Smm	unsigned long ae_fflags_clear;
148232153Smm	struct archive_mstring ae_gname;		/* Name of owning group */
149232153Smm	struct archive_mstring ae_hardlink;	/* Name of target for hardlink */
150232153Smm	struct archive_mstring ae_pathname;	/* Name of entry */
151232153Smm	struct archive_mstring ae_symlink;		/* symlink contents */
152232153Smm	struct archive_mstring ae_uname;		/* Name of owner */
153228753Smm
154228753Smm	/* Not used within libarchive; useful for some clients. */
155232153Smm	struct archive_mstring ae_sourcepath;	/* Path this entry is sourced from. */
156228753Smm
157232153Smm	void *mac_metadata;
158232153Smm	size_t mac_metadata_size;
159232153Smm
160228753Smm	/* ACL support. */
161232153Smm	struct archive_acl    acl;
162228753Smm
163228753Smm	/* extattr support. */
164228753Smm	struct ae_xattr *xattr_head;
165228753Smm	struct ae_xattr *xattr_p;
166228753Smm
167232153Smm	/* sparse support. */
168232153Smm	struct ae_sparse *sparse_head;
169232153Smm	struct ae_sparse *sparse_tail;
170232153Smm	struct ae_sparse *sparse_p;
171232153Smm
172228753Smm	/* Miscellaneous. */
173228753Smm	char		 strmode[12];
174228753Smm};
175228753Smm
176228753Smm#endif /* ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
177