Home | History | Annotate | Line # | Download | only in libarchive
      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 
     26 #ifndef ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
     27 #define ARCHIVE_ENTRY_PRIVATE_H_INCLUDED
     28 
     29 #ifndef __LIBARCHIVE_BUILD
     30 #error This header is only to be used internally to libarchive.
     31 #endif
     32 
     33 #include "archive_acl_private.h"
     34 #include "archive_string.h"
     35 
     36 struct ae_xattr {
     37 	struct ae_xattr *next;
     38 
     39 	char	*name;
     40 	void	*value;
     41 	size_t	size;
     42 };
     43 
     44 struct ae_sparse {
     45 	struct ae_sparse *next;
     46 
     47 	int64_t	 offset;
     48 	int64_t	 length;
     49 };
     50 
     51 struct ae_digest {
     52 	unsigned char md5[16];
     53 	unsigned char rmd160[20];
     54 	unsigned char sha1[20];
     55 	unsigned char sha256[32];
     56 	unsigned char sha384[48];
     57 	unsigned char sha512[64];
     58 };
     59 
     60 /*
     61  * Description of an archive entry.
     62  *
     63  * Basically, this is a "struct stat" with a few text fields added in.
     64  *
     65  * TODO: Add "comment", "charset", and possibly other entries
     66  * that are supported by "pax interchange" format.  However, GNU, ustar,
     67  * cpio, and other variants don't support these features, so they're not an
     68  * excruciatingly high priority right now.
     69  *
     70  * TODO: "pax interchange" format allows essentially arbitrary
     71  * key/value attributes to be attached to any entry.  Supporting
     72  * such extensions may make this library useful for special
     73  * applications (e.g., a package manager could attach special
     74  * package-management attributes to each entry).  There are tricky
     75  * API issues involved, so this is not going to happen until
     76  * there's a real demand for it.
     77  *
     78  * TODO: Design a good API for handling sparse files.
     79  */
     80 struct archive_entry {
     81 	struct archive *archive;
     82 
     83 	/*
     84 	 * Note that ae_stat.st_mode & AE_IFMT  can be  0!
     85 	 *
     86 	 * This occurs when the actual file type of the object is not
     87 	 * in the archive.  For example, 'tar' archives store
     88 	 * hardlinks without marking the type of the underlying
     89 	 * object.
     90 	 */
     91 
     92 	/*
     93 	 * We have a "struct aest" for holding file metadata rather than just
     94 	 * a "struct stat" because on some platforms the "struct stat" has
     95 	 * fields which are too narrow to hold the range of possible values;
     96 	 * we don't want to lose information if we read an archive and write
     97 	 * out another (e.g., in "tar -cf new.tar @old.tar").
     98 	 *
     99 	 * The "stat" pointer points to some form of platform-specific struct
    100 	 * stat; it is declared as a void * rather than a struct stat * as
    101 	 * some platforms have multiple varieties of stat structures.
    102 	 */
    103 	void *stat;
    104 	int  stat_valid; /* Set to 0 whenever a field in aest changes. */
    105 
    106 	struct aest {
    107 		int64_t		aest_atime;
    108 		uint32_t	aest_atime_nsec;
    109 		int64_t		aest_ctime;
    110 		uint32_t	aest_ctime_nsec;
    111 		int64_t		aest_mtime;
    112 		uint32_t	aest_mtime_nsec;
    113 		int64_t		aest_birthtime;
    114 		uint32_t	aest_birthtime_nsec;
    115 		int64_t		aest_gid;
    116 		int64_t		aest_ino;
    117 		uint32_t	aest_nlink;
    118 		uint64_t	aest_size;
    119 		int64_t		aest_uid;
    120 		/*
    121 		 * Because converting between device codes and
    122 		 * major/minor values is platform-specific and
    123 		 * inherently a bit risky, we only do that conversion
    124 		 * lazily.  That way, we will do a better job of
    125 		 * preserving information in those cases where no
    126 		 * conversion is actually required.
    127 		 */
    128 		int		aest_dev_is_broken_down;
    129 		dev_t		aest_dev;
    130 		dev_t		aest_devmajor;
    131 		dev_t		aest_devminor;
    132 		int		aest_rdev_is_broken_down;
    133 		dev_t		aest_rdev;
    134 		dev_t		aest_rdevmajor;
    135 		dev_t		aest_rdevminor;
    136 	} ae_stat;
    137 
    138 	int ae_set; /* bitmap of fields that are currently set */
    139 #define	AE_SET_HARDLINK	1
    140 #define	AE_SET_SYMLINK	2
    141 #define	AE_SET_ATIME	4
    142 #define	AE_SET_CTIME	8
    143 #define	AE_SET_MTIME	16
    144 #define	AE_SET_BIRTHTIME 32
    145 #define	AE_SET_SIZE	64
    146 #define	AE_SET_INO	128
    147 #define	AE_SET_DEV	256
    148 #define	AE_SET_PERM	512
    149 #define	AE_SET_FILETYPE	1024
    150 #define	AE_SET_UID	2048
    151 #define	AE_SET_GID	4096
    152 #define	AE_SET_RDEV	8192
    153 
    154 	/*
    155 	 * Use aes here so that we get transparent mbs<->wcs conversions.
    156 	 */
    157 	struct archive_mstring ae_fflags_text;	/* Text fflags per fflagstostr(3) */
    158 	unsigned long ae_fflags_set;		/* Bitmap fflags */
    159 	unsigned long ae_fflags_clear;
    160 	struct archive_mstring ae_gname;		/* Name of owning group */
    161 	struct archive_mstring ae_linkname;	/* Name of target for hardlink or symlink */
    162 	struct archive_mstring ae_pathname;	/* Name of entry */
    163 	struct archive_mstring ae_uname;		/* Name of owner */
    164 
    165 	/* Not used within libarchive; useful for some clients. */
    166 	struct archive_mstring ae_sourcepath;	/* Path this entry is sourced from. */
    167 
    168 #define AE_ENCRYPTION_NONE 0
    169 #define AE_ENCRYPTION_DATA 1
    170 #define AE_ENCRYPTION_METADATA 2
    171 	char encryption;
    172 
    173 	void *mac_metadata;
    174 	size_t mac_metadata_size;
    175 
    176 	/* Digest support. */
    177 #define AE_MSET_DIGEST_MD5	 1
    178 #define AE_MSET_DIGEST_RMD160	 2
    179 #define AE_MSET_DIGEST_SHA1	 4
    180 #define AE_MSET_DIGEST_SHA256	 8
    181 #define AE_MSET_DIGEST_SHA384	16
    182 #define AE_MSET_DIGEST_SHA512	32
    183 	uint_least32_t mset_digest;
    184 	struct ae_digest digest;
    185 
    186 	/* ACL support. */
    187 	struct archive_acl    acl;
    188 
    189 	/* extattr support. */
    190 	struct ae_xattr *xattr_head;
    191 	struct ae_xattr *xattr_p;
    192 
    193 	/* sparse support. */
    194 	struct ae_sparse *sparse_head;
    195 	struct ae_sparse *sparse_tail;
    196 	struct ae_sparse *sparse_p;
    197 
    198 	/* Miscellaneous. */
    199 	char		 strmode[12];
    200 
    201 	/* Symlink type support */
    202 	int ae_symlink_type;
    203 };
    204 
    205 #endif /* !ARCHIVE_ENTRY_PRIVATE_H_INCLUDED */
    206