1 /*- 2 * Copyright (c) 2003-2008 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.h 201096 2009-12-28 02:41:27Z kientzle $ 26 */ 27 28 #ifndef ARCHIVE_ENTRY_H_INCLUDED 29 #define ARCHIVE_ENTRY_H_INCLUDED 30 31 /* Note: Compiler will complain if this does not match archive.h! */ 32 #define ARCHIVE_VERSION_NUMBER 3000003 33 34 /* 35 * Note: archive_entry.h is for use outside of libarchive; the 36 * configuration headers (config.h, archive_platform.h, etc.) are 37 * purely internal. Do NOT use HAVE_XXX configuration macros to 38 * control the behavior of this header! If you must conditionalize, 39 * use predefined compiler and/or platform macros. 40 */ 41 42 #include <sys/types.h> 43 #include <stddef.h> /* for wchar_t */ 44 #include <time.h> 45 46 #if defined(_WIN32) && !defined(__CYGWIN__) 47 #include <windows.h> 48 #endif 49 50 /* Get appropriate definitions of standard POSIX-style types. */ 51 /* These should match the types used in 'struct stat' */ 52 #if defined(_WIN32) && !defined(__CYGWIN__) 53 #define __LA_INT64_T __int64 54 # if defined(__BORLANDC__) 55 # define __LA_UID_T uid_t /* Remove in libarchive 3.2 */ 56 # define __LA_GID_T gid_t /* Remove in libarchive 3.2 */ 57 # define __LA_DEV_T dev_t 58 # define __LA_MODE_T mode_t 59 # else 60 # define __LA_UID_T short /* Remove in libarchive 3.2 */ 61 # define __LA_GID_T short /* Remove in libarchive 3.2 */ 62 # define __LA_DEV_T unsigned int 63 # define __LA_MODE_T unsigned short 64 # endif 65 #else 66 #include <unistd.h> 67 # if defined(_SCO_DS) 68 # define __LA_INT64_T long long 69 # else 70 # define __LA_INT64_T int64_t 71 # endif 72 # define __LA_UID_T uid_t /* Remove in libarchive 3.2 */ 73 # define __LA_GID_T gid_t /* Remove in libarchive 3.2 */ 74 # define __LA_DEV_T dev_t 75 # define __LA_MODE_T mode_t 76 #endif 77 78 /* 79 * Remove this for libarchive 3.2, since ino_t is no longer used. 80 */ 81 #define __LA_INO_T ino_t 82 83 84 /* 85 * On Windows, define LIBARCHIVE_STATIC if you're building or using a 86 * .lib. The default here assumes you're building a DLL. Only 87 * libarchive source should ever define __LIBARCHIVE_BUILD. 88 */ 89 #if ((defined __WIN32__) || (defined _WIN32) || defined(__CYGWIN__)) && (!defined LIBARCHIVE_STATIC) 90 # ifdef __LIBARCHIVE_BUILD 91 # ifdef __GNUC__ 92 # define __LA_DECL __attribute__((dllexport)) extern 93 # else 94 # define __LA_DECL __declspec(dllexport) 95 # endif 96 # else 97 # ifdef __GNUC__ 98 # define __LA_DECL 99 # else 100 # define __LA_DECL __declspec(dllimport) 101 # endif 102 # endif 103 #else 104 /* Static libraries on all platforms and shared libraries on non-Windows. */ 105 # define __LA_DECL 106 #endif 107 108 #ifdef __cplusplus 109 extern "C" { 110 #endif 111 112 /* 113 * Description of an archive entry. 114 * 115 * You can think of this as "struct stat" with some text fields added in. 116 * 117 * TODO: Add "comment", "charset", and possibly other entries that are 118 * supported by "pax interchange" format. However, GNU, ustar, cpio, 119 * and other variants don't support these features, so they're not an 120 * excruciatingly high priority right now. 121 * 122 * TODO: "pax interchange" format allows essentially arbitrary 123 * key/value attributes to be attached to any entry. Supporting 124 * such extensions may make this library useful for special 125 * applications (e.g., a package manager could attach special 126 * package-management attributes to each entry). 127 */ 128 struct archive; 129 struct archive_entry; 130 131 /* 132 * File-type constants. These are returned from archive_entry_filetype() 133 * and passed to archive_entry_set_filetype(). 134 * 135 * These values match S_XXX defines on every platform I've checked, 136 * including Windows, AIX, Linux, Solaris, and BSD. They're 137 * (re)defined here because platforms generally don't define the ones 138 * they don't support. For example, Windows doesn't define S_IFLNK or 139 * S_IFBLK. Instead of having a mass of conditional logic and system 140 * checks to define any S_XXX values that aren't supported locally, 141 * I've just defined a new set of such constants so that 142 * libarchive-based applications can manipulate and identify archive 143 * entries properly even if the hosting platform can't store them on 144 * disk. 145 * 146 * These values are also used directly within some portable formats, 147 * such as cpio. If you find a platform that varies from these, the 148 * correct solution is to leave these alone and translate from these 149 * portable values to platform-native values when entries are read from 150 * or written to disk. 151 */ 152 #define AE_IFMT 0170000 153 #define AE_IFREG 0100000 154 #define AE_IFLNK 0120000 155 #define AE_IFSOCK 0140000 156 #define AE_IFCHR 0020000 157 #define AE_IFBLK 0060000 158 #define AE_IFDIR 0040000 159 #define AE_IFIFO 0010000 160 161 /* 162 * Basic object manipulation 163 */ 164 165 __LA_DECL struct archive_entry *archive_entry_clear(struct archive_entry *); 166 /* The 'clone' function does a deep copy; all of the strings are copied too. */ 167 __LA_DECL struct archive_entry *archive_entry_clone(struct archive_entry *); 168 __LA_DECL void archive_entry_free(struct archive_entry *); 169 __LA_DECL struct archive_entry *archive_entry_new(void); 170 171 /* 172 * This form of archive_entry_new2() will pull character-set 173 * conversion information from the specified archive handle. The 174 * older archive_entry_new(void) form is equivalent to calling 175 * archive_entry_new2(NULL) and will result in the use of an internal 176 * default character-set conversion. 177 */ 178 __LA_DECL struct archive_entry *archive_entry_new2(struct archive *); 179 180 /* 181 * Retrieve fields from an archive_entry. 182 * 183 * There are a number of implicit conversions among these fields. For 184 * example, if a regular string field is set and you read the _w wide 185 * character field, the entry will implicitly convert narrow-to-wide 186 * using the current locale. Similarly, dev values are automatically 187 * updated when you write devmajor or devminor and vice versa. 188 * 189 * In addition, fields can be "set" or "unset." Unset string fields 190 * return NULL, non-string fields have _is_set() functions to test 191 * whether they've been set. You can "unset" a string field by 192 * assigning NULL; non-string fields have _unset() functions to 193 * unset them. 194 * 195 * Note: There is one ambiguity in the above; string fields will 196 * also return NULL when implicit character set conversions fail. 197 * This is usually what you want. 198 */ 199 __LA_DECL time_t archive_entry_atime(struct archive_entry *); 200 __LA_DECL long archive_entry_atime_nsec(struct archive_entry *); 201 __LA_DECL int archive_entry_atime_is_set(struct archive_entry *); 202 __LA_DECL time_t archive_entry_birthtime(struct archive_entry *); 203 __LA_DECL long archive_entry_birthtime_nsec(struct archive_entry *); 204 __LA_DECL int archive_entry_birthtime_is_set(struct archive_entry *); 205 __LA_DECL time_t archive_entry_ctime(struct archive_entry *); 206 __LA_DECL long archive_entry_ctime_nsec(struct archive_entry *); 207 __LA_DECL int archive_entry_ctime_is_set(struct archive_entry *); 208 __LA_DECL dev_t archive_entry_dev(struct archive_entry *); 209 __LA_DECL int archive_entry_dev_is_set(struct archive_entry *); 210 __LA_DECL dev_t archive_entry_devmajor(struct archive_entry *); 211 __LA_DECL dev_t archive_entry_devminor(struct archive_entry *); 212 __LA_DECL __LA_MODE_T archive_entry_filetype(struct archive_entry *); 213 __LA_DECL void archive_entry_fflags(struct archive_entry *, 214 unsigned long * /* set */, 215 unsigned long * /* clear */); 216 __LA_DECL const char *archive_entry_fflags_text(struct archive_entry *); 217 __LA_DECL __LA_INT64_T archive_entry_gid(struct archive_entry *); 218 __LA_DECL const char *archive_entry_gname(struct archive_entry *); 219 __LA_DECL const wchar_t *archive_entry_gname_w(struct archive_entry *); 220 __LA_DECL const char *archive_entry_hardlink(struct archive_entry *); 221 __LA_DECL const wchar_t *archive_entry_hardlink_w(struct archive_entry *); 222 __LA_DECL __LA_INT64_T archive_entry_ino(struct archive_entry *); 223 __LA_DECL __LA_INT64_T archive_entry_ino64(struct archive_entry *); 224 __LA_DECL int archive_entry_ino_is_set(struct archive_entry *); 225 __LA_DECL __LA_MODE_T archive_entry_mode(struct archive_entry *); 226 __LA_DECL time_t archive_entry_mtime(struct archive_entry *); 227 __LA_DECL long archive_entry_mtime_nsec(struct archive_entry *); 228 __LA_DECL int archive_entry_mtime_is_set(struct archive_entry *); 229 __LA_DECL unsigned int archive_entry_nlink(struct archive_entry *); 230 __LA_DECL const char *archive_entry_pathname(struct archive_entry *); 231 __LA_DECL const wchar_t *archive_entry_pathname_w(struct archive_entry *); 232 __LA_DECL __LA_MODE_T archive_entry_perm(struct archive_entry *); 233 __LA_DECL dev_t archive_entry_rdev(struct archive_entry *); 234 __LA_DECL dev_t archive_entry_rdevmajor(struct archive_entry *); 235 __LA_DECL dev_t archive_entry_rdevminor(struct archive_entry *); 236 __LA_DECL const char *archive_entry_sourcepath(struct archive_entry *); 237 __LA_DECL const wchar_t *archive_entry_sourcepath_w(struct archive_entry *); 238 __LA_DECL __LA_INT64_T archive_entry_size(struct archive_entry *); 239 __LA_DECL int archive_entry_size_is_set(struct archive_entry *); 240 __LA_DECL const char *archive_entry_strmode(struct archive_entry *); 241 __LA_DECL const char *archive_entry_symlink(struct archive_entry *); 242 __LA_DECL const wchar_t *archive_entry_symlink_w(struct archive_entry *); 243 __LA_DECL __LA_INT64_T archive_entry_uid(struct archive_entry *); 244 __LA_DECL const char *archive_entry_uname(struct archive_entry *); 245 __LA_DECL const wchar_t *archive_entry_uname_w(struct archive_entry *); 246 247 /* 248 * Set fields in an archive_entry. 249 * 250 * Note: Before libarchive 2.4, there were 'set' and 'copy' versions 251 * of the string setters. 'copy' copied the actual string, 'set' just 252 * stored the pointer. In libarchive 2.4 and later, strings are 253 * always copied. 254 */ 255 256 __LA_DECL void archive_entry_set_atime(struct archive_entry *, time_t, long); 257 __LA_DECL void archive_entry_unset_atime(struct archive_entry *); 258 #if defined(_WIN32) && !defined(__CYGWIN__) 259 __LA_DECL void archive_entry_copy_bhfi(struct archive_entry *, BY_HANDLE_FILE_INFORMATION *); 260 #endif 261 __LA_DECL void archive_entry_set_birthtime(struct archive_entry *, time_t, long); 262 __LA_DECL void archive_entry_unset_birthtime(struct archive_entry *); 263 __LA_DECL void archive_entry_set_ctime(struct archive_entry *, time_t, long); 264 __LA_DECL void archive_entry_unset_ctime(struct archive_entry *); 265 __LA_DECL void archive_entry_set_dev(struct archive_entry *, dev_t); 266 __LA_DECL void archive_entry_set_devmajor(struct archive_entry *, dev_t); 267 __LA_DECL void archive_entry_set_devminor(struct archive_entry *, dev_t); 268 __LA_DECL void archive_entry_set_filetype(struct archive_entry *, unsigned int); 269 __LA_DECL void archive_entry_set_fflags(struct archive_entry *, 270 unsigned long /* set */, unsigned long /* clear */); 271 /* Returns pointer to start of first invalid token, or NULL if none. */ 272 /* Note that all recognized tokens are processed, regardless. */ 273 __LA_DECL const char *archive_entry_copy_fflags_text(struct archive_entry *, 274 const char *); 275 __LA_DECL const wchar_t *archive_entry_copy_fflags_text_w(struct archive_entry *, 276 const wchar_t *); 277 __LA_DECL void archive_entry_set_gid(struct archive_entry *, __LA_INT64_T); 278 __LA_DECL void archive_entry_set_gname(struct archive_entry *, const char *); 279 __LA_DECL void archive_entry_copy_gname(struct archive_entry *, const char *); 280 __LA_DECL void archive_entry_copy_gname_w(struct archive_entry *, const wchar_t *); 281 __LA_DECL int archive_entry_update_gname_utf8(struct archive_entry *, const char *); 282 __LA_DECL void archive_entry_set_hardlink(struct archive_entry *, const char *); 283 __LA_DECL void archive_entry_copy_hardlink(struct archive_entry *, const char *); 284 __LA_DECL void archive_entry_copy_hardlink_w(struct archive_entry *, const wchar_t *); 285 __LA_DECL int archive_entry_update_hardlink_utf8(struct archive_entry *, const char *); 286 __LA_DECL void archive_entry_set_ino(struct archive_entry *, __LA_INT64_T); 287 __LA_DECL void archive_entry_set_ino64(struct archive_entry *, __LA_INT64_T); 288 __LA_DECL void archive_entry_set_link(struct archive_entry *, const char *); 289 __LA_DECL void archive_entry_copy_link(struct archive_entry *, const char *); 290 __LA_DECL void archive_entry_copy_link_w(struct archive_entry *, const wchar_t *); 291 __LA_DECL int archive_entry_update_link_utf8(struct archive_entry *, const char *); 292 __LA_DECL void archive_entry_set_mode(struct archive_entry *, __LA_MODE_T); 293 __LA_DECL void archive_entry_set_mtime(struct archive_entry *, time_t, long); 294 __LA_DECL void archive_entry_unset_mtime(struct archive_entry *); 295 __LA_DECL void archive_entry_set_nlink(struct archive_entry *, unsigned int); 296 __LA_DECL void archive_entry_set_pathname(struct archive_entry *, const char *); 297 __LA_DECL void archive_entry_copy_pathname(struct archive_entry *, const char *); 298 __LA_DECL void archive_entry_copy_pathname_w(struct archive_entry *, const wchar_t *); 299 __LA_DECL int archive_entry_update_pathname_utf8(struct archive_entry *, const char *); 300 __LA_DECL void archive_entry_set_perm(struct archive_entry *, __LA_MODE_T); 301 __LA_DECL void archive_entry_set_rdev(struct archive_entry *, dev_t); 302 __LA_DECL void archive_entry_set_rdevmajor(struct archive_entry *, dev_t); 303 __LA_DECL void archive_entry_set_rdevminor(struct archive_entry *, dev_t); 304 __LA_DECL void archive_entry_set_size(struct archive_entry *, __LA_INT64_T); 305 __LA_DECL void archive_entry_unset_size(struct archive_entry *); 306 __LA_DECL void archive_entry_copy_sourcepath(struct archive_entry *, const char *); 307 __LA_DECL void archive_entry_copy_sourcepath_w(struct archive_entry *, const wchar_t *); 308 __LA_DECL void archive_entry_set_symlink(struct archive_entry *, const char *); 309 __LA_DECL void archive_entry_copy_symlink(struct archive_entry *, const char *); 310 __LA_DECL void archive_entry_copy_symlink_w(struct archive_entry *, const wchar_t *); 311 __LA_DECL int archive_entry_update_symlink_utf8(struct archive_entry *, const char *); 312 __LA_DECL void archive_entry_set_uid(struct archive_entry *, __LA_INT64_T); 313 __LA_DECL void archive_entry_set_uname(struct archive_entry *, const char *); 314 __LA_DECL void archive_entry_copy_uname(struct archive_entry *, const char *); 315 __LA_DECL void archive_entry_copy_uname_w(struct archive_entry *, const wchar_t *); 316 __LA_DECL int archive_entry_update_uname_utf8(struct archive_entry *, const char *); 317 /* 318 * Routines to bulk copy fields to/from a platform-native "struct 319 * stat." Libarchive used to just store a struct stat inside of each 320 * archive_entry object, but this created issues when trying to 321 * manipulate archives on systems different than the ones they were 322 * created on. 323 * 324 * TODO: On Linux, provide both stat32 and stat64 versions of these functions. 325 */ 326 __LA_DECL const struct stat *archive_entry_stat(struct archive_entry *); 327 __LA_DECL void archive_entry_copy_stat(struct archive_entry *, const struct stat *); 328 329 /* 330 * Storage for Mac OS-specific AppleDouble metadata information. 331 * Apple-format tar files store a separate binary blob containing 332 * encoded metadata with ACL, extended attributes, etc. 333 * This provides a place to store that blob. 334 */ 335 336 __LA_DECL const void * archive_entry_mac_metadata(struct archive_entry *, size_t *); 337 __LA_DECL void archive_entry_copy_mac_metadata(struct archive_entry *, const void *, size_t); 338 339 /* 340 * ACL routines. This used to simply store and return text-format ACL 341 * strings, but that proved insufficient for a number of reasons: 342 * = clients need control over uname/uid and gname/gid mappings 343 * = there are many different ACL text formats 344 * = would like to be able to read/convert archives containing ACLs 345 * on platforms that lack ACL libraries 346 * 347 * This last point, in particular, forces me to implement a reasonably 348 * complete set of ACL support routines. 349 */ 350 351 /* 352 * Permission bits. 353 */ 354 #define ARCHIVE_ENTRY_ACL_EXECUTE 0x00000001 355 #define ARCHIVE_ENTRY_ACL_WRITE 0x00000002 356 #define ARCHIVE_ENTRY_ACL_READ 0x00000004 357 #define ARCHIVE_ENTRY_ACL_READ_DATA 0x00000008 358 #define ARCHIVE_ENTRY_ACL_LIST_DIRECTORY 0x00000008 359 #define ARCHIVE_ENTRY_ACL_WRITE_DATA 0x00000010 360 #define ARCHIVE_ENTRY_ACL_ADD_FILE 0x00000010 361 #define ARCHIVE_ENTRY_ACL_APPEND_DATA 0x00000020 362 #define ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY 0x00000020 363 #define ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS 0x00000040 364 #define ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS 0x00000080 365 #define ARCHIVE_ENTRY_ACL_DELETE_CHILD 0x00000100 366 #define ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES 0x00000200 367 #define ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES 0x00000400 368 #define ARCHIVE_ENTRY_ACL_DELETE 0x00000800 369 #define ARCHIVE_ENTRY_ACL_READ_ACL 0x00001000 370 #define ARCHIVE_ENTRY_ACL_WRITE_ACL 0x00002000 371 #define ARCHIVE_ENTRY_ACL_WRITE_OWNER 0x00004000 372 #define ARCHIVE_ENTRY_ACL_SYNCHRONIZE 0x00008000 373 374 #define ARCHIVE_ENTRY_ACL_PERMS_POSIX1E \ 375 (ARCHIVE_ENTRY_ACL_EXECUTE \ 376 | ARCHIVE_ENTRY_ACL_WRITE \ 377 | ARCHIVE_ENTRY_ACL_READ) 378 379 #define ARCHIVE_ENTRY_ACL_PERMS_NFS4 \ 380 (ARCHIVE_ENTRY_ACL_EXECUTE \ 381 | ARCHIVE_ENTRY_ACL_READ_DATA \ 382 | ARCHIVE_ENTRY_ACL_LIST_DIRECTORY \ 383 | ARCHIVE_ENTRY_ACL_WRITE_DATA \ 384 | ARCHIVE_ENTRY_ACL_ADD_FILE \ 385 | ARCHIVE_ENTRY_ACL_APPEND_DATA \ 386 | ARCHIVE_ENTRY_ACL_ADD_SUBDIRECTORY \ 387 | ARCHIVE_ENTRY_ACL_READ_NAMED_ATTRS \ 388 | ARCHIVE_ENTRY_ACL_WRITE_NAMED_ATTRS \ 389 | ARCHIVE_ENTRY_ACL_DELETE_CHILD \ 390 | ARCHIVE_ENTRY_ACL_READ_ATTRIBUTES \ 391 | ARCHIVE_ENTRY_ACL_WRITE_ATTRIBUTES \ 392 | ARCHIVE_ENTRY_ACL_DELETE \ 393 | ARCHIVE_ENTRY_ACL_READ_ACL \ 394 | ARCHIVE_ENTRY_ACL_WRITE_ACL \ 395 | ARCHIVE_ENTRY_ACL_WRITE_OWNER \ 396 | ARCHIVE_ENTRY_ACL_SYNCHRONIZE) 397 398 /* 399 * Inheritance values (NFS4 ACLs only); included in permset. 400 */ 401 #define ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT 0x02000000 402 #define ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT 0x04000000 403 #define ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT 0x08000000 404 #define ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY 0x10000000 405 #define ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS 0x20000000 406 #define ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS 0x40000000 407 408 #define ARCHIVE_ENTRY_ACL_INHERITANCE_NFS4 \ 409 (ARCHIVE_ENTRY_ACL_ENTRY_FILE_INHERIT \ 410 | ARCHIVE_ENTRY_ACL_ENTRY_DIRECTORY_INHERIT \ 411 | ARCHIVE_ENTRY_ACL_ENTRY_NO_PROPAGATE_INHERIT \ 412 | ARCHIVE_ENTRY_ACL_ENTRY_INHERIT_ONLY \ 413 | ARCHIVE_ENTRY_ACL_ENTRY_SUCCESSFUL_ACCESS \ 414 | ARCHIVE_ENTRY_ACL_ENTRY_FAILED_ACCESS) 415 416 /* We need to be able to specify combinations of these. */ 417 #define ARCHIVE_ENTRY_ACL_TYPE_ACCESS 256 /* POSIX.1e only */ 418 #define ARCHIVE_ENTRY_ACL_TYPE_DEFAULT 512 /* POSIX.1e only */ 419 #define ARCHIVE_ENTRY_ACL_TYPE_ALLOW 1024 /* NFS4 only */ 420 #define ARCHIVE_ENTRY_ACL_TYPE_DENY 2048 /* NFS4 only */ 421 #define ARCHIVE_ENTRY_ACL_TYPE_AUDIT 4096 /* NFS4 only */ 422 #define ARCHIVE_ENTRY_ACL_TYPE_ALARM 8192 /* NFS4 only */ 423 #define ARCHIVE_ENTRY_ACL_TYPE_POSIX1E (ARCHIVE_ENTRY_ACL_TYPE_ACCESS \ 424 | ARCHIVE_ENTRY_ACL_TYPE_DEFAULT) 425 #define ARCHIVE_ENTRY_ACL_TYPE_NFS4 (ARCHIVE_ENTRY_ACL_TYPE_ALLOW \ 426 | ARCHIVE_ENTRY_ACL_TYPE_DENY \ 427 | ARCHIVE_ENTRY_ACL_TYPE_AUDIT \ 428 | ARCHIVE_ENTRY_ACL_TYPE_ALARM) 429 430 /* Tag values mimic POSIX.1e */ 431 #define ARCHIVE_ENTRY_ACL_USER 10001 /* Specified user. */ 432 #define ARCHIVE_ENTRY_ACL_USER_OBJ 10002 /* User who owns the file. */ 433 #define ARCHIVE_ENTRY_ACL_GROUP 10003 /* Specified group. */ 434 #define ARCHIVE_ENTRY_ACL_GROUP_OBJ 10004 /* Group who owns the file. */ 435 #define ARCHIVE_ENTRY_ACL_MASK 10005 /* Modify group access (POSIX.1e only) */ 436 #define ARCHIVE_ENTRY_ACL_OTHER 10006 /* Public (POSIX.1e only) */ 437 #define ARCHIVE_ENTRY_ACL_EVERYONE 10107 /* Everyone (NFS4 only) */ 438 439 /* 440 * Set the ACL by clearing it and adding entries one at a time. 441 * Unlike the POSIX.1e ACL routines, you must specify the type 442 * (access/default) for each entry. Internally, the ACL data is just 443 * a soup of entries. API calls here allow you to retrieve just the 444 * entries of interest. This design (which goes against the spirit of 445 * POSIX.1e) is useful for handling archive formats that combine 446 * default and access information in a single ACL list. 447 */ 448 __LA_DECL void archive_entry_acl_clear(struct archive_entry *); 449 __LA_DECL int archive_entry_acl_add_entry(struct archive_entry *, 450 int /* type */, int /* permset */, int /* tag */, 451 int /* qual */, const char * /* name */); 452 __LA_DECL int archive_entry_acl_add_entry_w(struct archive_entry *, 453 int /* type */, int /* permset */, int /* tag */, 454 int /* qual */, const wchar_t * /* name */); 455 456 /* 457 * To retrieve the ACL, first "reset", then repeatedly ask for the 458 * "next" entry. The want_type parameter allows you to request only 459 * certain types of entries. 460 */ 461 __LA_DECL int archive_entry_acl_reset(struct archive_entry *, int /* want_type */); 462 __LA_DECL int archive_entry_acl_next(struct archive_entry *, int /* want_type */, 463 int * /* type */, int * /* permset */, int * /* tag */, 464 int * /* qual */, const char ** /* name */); 465 __LA_DECL int archive_entry_acl_next_w(struct archive_entry *, int /* want_type */, 466 int * /* type */, int * /* permset */, int * /* tag */, 467 int * /* qual */, const wchar_t ** /* name */); 468 469 /* 470 * Construct a text-format ACL. The flags argument is a bitmask that 471 * can include any of the following: 472 * 473 * ARCHIVE_ENTRY_ACL_TYPE_ACCESS - Include POSIX.1e "access" entries. 474 * ARCHIVE_ENTRY_ACL_TYPE_DEFAULT - Include POSIX.1e "default" entries. 475 * ARCHIVE_ENTRY_ACL_TYPE_NFS4 - Include NFS4 entries. 476 * ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID - Include extra numeric ID field in 477 * each ACL entry. ('star' introduced this for POSIX.1e, this flag 478 * also applies to NFS4.) 479 * ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT - Include "default:" before each 480 * default ACL entry, as used in old Solaris ACLs. 481 */ 482 #define ARCHIVE_ENTRY_ACL_STYLE_EXTRA_ID 1024 483 #define ARCHIVE_ENTRY_ACL_STYLE_MARK_DEFAULT 2048 484 __LA_DECL const wchar_t *archive_entry_acl_text_w(struct archive_entry *, 485 int /* flags */); 486 __LA_DECL const char *archive_entry_acl_text(struct archive_entry *, 487 int /* flags */); 488 489 /* Return a count of entries matching 'want_type' */ 490 __LA_DECL int archive_entry_acl_count(struct archive_entry *, int /* want_type */); 491 492 /* Return an opaque ACL object. */ 493 /* There's not yet anything clients can actually do with this... */ 494 struct archive_acl; 495 __LA_DECL struct archive_acl *archive_entry_acl(struct archive_entry *); 496 497 /* 498 * extended attributes 499 */ 500 501 __LA_DECL void archive_entry_xattr_clear(struct archive_entry *); 502 __LA_DECL void archive_entry_xattr_add_entry(struct archive_entry *, 503 const char * /* name */, const void * /* value */, 504 size_t /* size */); 505 506 /* 507 * To retrieve the xattr list, first "reset", then repeatedly ask for the 508 * "next" entry. 509 */ 510 511 __LA_DECL int archive_entry_xattr_count(struct archive_entry *); 512 __LA_DECL int archive_entry_xattr_reset(struct archive_entry *); 513 __LA_DECL int archive_entry_xattr_next(struct archive_entry *, 514 const char ** /* name */, const void ** /* value */, size_t *); 515 516 /* 517 * sparse 518 */ 519 520 __LA_DECL void archive_entry_sparse_clear(struct archive_entry *); 521 __LA_DECL void archive_entry_sparse_add_entry(struct archive_entry *, 522 __LA_INT64_T /* offset */, __LA_INT64_T /* length */); 523 524 /* 525 * To retrieve the xattr list, first "reset", then repeatedly ask for the 526 * "next" entry. 527 */ 528 529 __LA_DECL int archive_entry_sparse_count(struct archive_entry *); 530 __LA_DECL int archive_entry_sparse_reset(struct archive_entry *); 531 __LA_DECL int archive_entry_sparse_next(struct archive_entry *, 532 __LA_INT64_T * /* offset */, __LA_INT64_T * /* length */); 533 534 /* 535 * Utility to match up hardlinks. 536 * 537 * The 'struct archive_entry_linkresolver' is a cache of archive entries 538 * for files with multiple links. Here's how to use it: 539 * 1. Create a lookup object with archive_entry_linkresolver_new() 540 * 2. Tell it the archive format you're using. 541 * 3. Hand each archive_entry to archive_entry_linkify(). 542 * That function will return 0, 1, or 2 entries that should 543 * be written. 544 * 4. Call archive_entry_linkify(resolver, NULL) until 545 * no more entries are returned. 546 * 5. Call archive_entry_linkresolver_free(resolver) to free resources. 547 * 548 * The entries returned have their hardlink and size fields updated 549 * appropriately. If an entry is passed in that does not refer to 550 * a file with multiple links, it is returned unchanged. The intention 551 * is that you should be able to simply filter all entries through 552 * this machine. 553 * 554 * To make things more efficient, be sure that each entry has a valid 555 * nlinks value. The hardlink cache uses this to track when all links 556 * have been found. If the nlinks value is zero, it will keep every 557 * name in the cache indefinitely, which can use a lot of memory. 558 * 559 * Note that archive_entry_size() is reset to zero if the file 560 * body should not be written to the archive. Pay attention! 561 */ 562 struct archive_entry_linkresolver; 563 564 /* 565 * There are three different strategies for marking hardlinks. 566 * The descriptions below name them after the best-known 567 * formats that rely on each strategy: 568 * 569 * "Old cpio" is the simplest, it always returns any entry unmodified. 570 * As far as I know, only cpio formats use this. Old cpio archives 571 * store every link with the full body; the onus is on the dearchiver 572 * to detect and properly link the files as they are restored. 573 * "tar" is also pretty simple; it caches a copy the first time it sees 574 * any link. Subsequent appearances are modified to be hardlink 575 * references to the first one without any body. Used by all tar 576 * formats, although the newest tar formats permit the "old cpio" strategy 577 * as well. This strategy is very simple for the dearchiver, 578 * and reasonably straightforward for the archiver. 579 * "new cpio" is trickier. It stores the body only with the last 580 * occurrence. The complication is that we might not 581 * see every link to a particular file in a single session, so 582 * there's no easy way to know when we've seen the last occurrence. 583 * The solution here is to queue one link until we see the next. 584 * At the end of the session, you can enumerate any remaining 585 * entries by calling archive_entry_linkify(NULL) and store those 586 * bodies. If you have a file with three links l1, l2, and l3, 587 * you'll get the following behavior if you see all three links: 588 * linkify(l1) => NULL (the resolver stores l1 internally) 589 * linkify(l2) => l1 (resolver stores l2, you write l1) 590 * linkify(l3) => l2, l3 (all links seen, you can write both). 591 * If you only see l1 and l2, you'll get this behavior: 592 * linkify(l1) => NULL 593 * linkify(l2) => l1 594 * linkify(NULL) => l2 (at end, you retrieve remaining links) 595 * As the name suggests, this strategy is used by newer cpio variants. 596 * It's noticeably more complex for the archiver, slightly more complex 597 * for the dearchiver than the tar strategy, but makes it straightforward 598 * to restore a file using any link by simply continuing to scan until 599 * you see a link that is stored with a body. In contrast, the tar 600 * strategy requires you to rescan the archive from the beginning to 601 * correctly extract an arbitrary link. 602 */ 603 604 __LA_DECL struct archive_entry_linkresolver *archive_entry_linkresolver_new(void); 605 __LA_DECL void archive_entry_linkresolver_set_strategy( 606 struct archive_entry_linkresolver *, int /* format_code */); 607 __LA_DECL void archive_entry_linkresolver_free(struct archive_entry_linkresolver *); 608 __LA_DECL void archive_entry_linkify(struct archive_entry_linkresolver *, 609 struct archive_entry **, struct archive_entry **); 610 __LA_DECL struct archive_entry *archive_entry_partial_links( 611 struct archive_entry_linkresolver *res, unsigned int *links); 612 613 #ifdef __cplusplus 614 } 615 #endif 616 617 /* This is meaningless outside of this header. */ 618 #undef __LA_DECL 619 620 #endif /* !ARCHIVE_ENTRY_H_INCLUDED */ 621