160b4ad09SPeter Avalos /*- 260b4ad09SPeter Avalos * Copyright (c) 2003-2007 Tim Kientzle 360b4ad09SPeter Avalos * All rights reserved. 460b4ad09SPeter Avalos * 560b4ad09SPeter Avalos * Redistribution and use in source and binary forms, with or without 660b4ad09SPeter Avalos * modification, are permitted provided that the following conditions 760b4ad09SPeter Avalos * are met: 860b4ad09SPeter Avalos * 1. Redistributions of source code must retain the above copyright 960b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer. 1060b4ad09SPeter Avalos * 2. Redistributions in binary form must reproduce the above copyright 1160b4ad09SPeter Avalos * notice, this list of conditions and the following disclaimer in the 1260b4ad09SPeter Avalos * documentation and/or other materials provided with the distribution. 1360b4ad09SPeter Avalos * 1460b4ad09SPeter Avalos * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR 1560b4ad09SPeter Avalos * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 1660b4ad09SPeter Avalos * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 1760b4ad09SPeter Avalos * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT, 1860b4ad09SPeter Avalos * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 1960b4ad09SPeter Avalos * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2060b4ad09SPeter Avalos * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2160b4ad09SPeter Avalos * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2260b4ad09SPeter Avalos * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2360b4ad09SPeter Avalos * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2460b4ad09SPeter Avalos * 258029ab02SPeter Avalos * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $ 2660b4ad09SPeter Avalos */ 2760b4ad09SPeter Avalos 28085658deSDaniel Fojt #ifndef BSDTAR_H_INCLUDED 29085658deSDaniel Fojt #define BSDTAR_H_INCLUDED 30085658deSDaniel Fojt 3160b4ad09SPeter Avalos #include "bsdtar_platform.h" 3260b4ad09SPeter Avalos #include <stdio.h> 3360b4ad09SPeter Avalos 3460b4ad09SPeter Avalos #define DEFAULT_BYTES_PER_BLOCK (20*512) 35d4d8193eSPeter Avalos #define ENV_READER_OPTIONS "TAR_READER_OPTIONS" 36d4d8193eSPeter Avalos #define ENV_WRITER_OPTIONS "TAR_WRITER_OPTIONS" 37d4d8193eSPeter Avalos #define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__," 3860b4ad09SPeter Avalos 39d4d8193eSPeter Avalos struct creation_set; 4060b4ad09SPeter Avalos /* 4160b4ad09SPeter Avalos * The internal state for the "bsdtar" program. 4260b4ad09SPeter Avalos * 4360b4ad09SPeter Avalos * Keeping all of the state in a structure like this simplifies memory 4460b4ad09SPeter Avalos * leak testing (at exit, anything left on the heap is suspect). A 4560b4ad09SPeter Avalos * pointer to this structure is passed to most bsdtar internal 4660b4ad09SPeter Avalos * functions. 4760b4ad09SPeter Avalos */ 4860b4ad09SPeter Avalos struct bsdtar { 4960b4ad09SPeter Avalos /* Options */ 5060b4ad09SPeter Avalos const char *filename; /* -f filename */ 5160b4ad09SPeter Avalos char *pending_chdir; /* -C dir */ 5260b4ad09SPeter Avalos const char *names_from_file; /* -T file */ 5360b4ad09SPeter Avalos int bytes_per_block; /* -b block_size */ 54c09f92d2SPeter Avalos int bytes_in_last_block; /* See -b handling. */ 5560b4ad09SPeter Avalos int verbose; /* -v */ 56e95abc47Szrj unsigned int flags; /* Bitfield of boolean options */ 5760b4ad09SPeter Avalos int extract_flags; /* Flags for extract operation */ 5859bf7050SPeter Avalos int readdisk_flags; /* Flags for read disk operation */ 5960b4ad09SPeter Avalos int strip_components; /* Remove this many leading dirs */ 60c09f92d2SPeter Avalos int gid; /* --gid */ 61c09f92d2SPeter Avalos const char *gname; /* --gname */ 62c09f92d2SPeter Avalos int uid; /* --uid */ 63c09f92d2SPeter Avalos const char *uname; /* --uname */ 646b384f39SPeter Avalos const char *passphrase; /* --passphrase */ 6560b4ad09SPeter Avalos char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ 6660b4ad09SPeter Avalos char symlink_mode; /* H or L, per BSD conventions */ 678029ab02SPeter Avalos const char *option_options; /* --options */ 6860b4ad09SPeter Avalos char day_first; /* show day before month in -tv output */ 69d4d8193eSPeter Avalos struct creation_set *cset; 70c09f92d2SPeter Avalos 71c09f92d2SPeter Avalos /* Option parser state */ 72c09f92d2SPeter Avalos int getopt_state; 73c09f92d2SPeter Avalos char *getopt_word; 7460b4ad09SPeter Avalos 7560b4ad09SPeter Avalos /* If >= 0, then close this when done. */ 7660b4ad09SPeter Avalos int fd; 7760b4ad09SPeter Avalos 7860b4ad09SPeter Avalos /* Miscellaneous state information */ 7960b4ad09SPeter Avalos int argc; 8060b4ad09SPeter Avalos char **argv; 81c09f92d2SPeter Avalos const char *argument; 8260b4ad09SPeter Avalos size_t gs_width; /* For 'list_item' in read.c */ 8360b4ad09SPeter Avalos size_t u_width; /* for 'list_item' in read.c */ 8460b4ad09SPeter Avalos uid_t user_uid; /* UID running this program */ 8560b4ad09SPeter Avalos int return_value; /* Value returned by main() */ 8660b4ad09SPeter Avalos char warned_lead_slash; /* Already displayed warning */ 8760b4ad09SPeter Avalos char next_line_is_dir; /* Used for -C parsing in -cT */ 8860b4ad09SPeter Avalos 8960b4ad09SPeter Avalos /* 9060b4ad09SPeter Avalos * Data for various subsystems. Full definitions are located in 9160b4ad09SPeter Avalos * the file where they are used. 9260b4ad09SPeter Avalos */ 938029ab02SPeter Avalos struct archive *diskreader; /* for write.c */ 948029ab02SPeter Avalos struct archive_entry_linkresolver *resolver; /* for write.c */ 9560b4ad09SPeter Avalos struct archive_dir *archive_dir; /* for write.c */ 9660b4ad09SPeter Avalos struct name_cache *gname_cache; /* for write.c */ 978029ab02SPeter Avalos char *buff; /* for write.c */ 98c09f92d2SPeter Avalos size_t buff_size; /* for write.c */ 9959bf7050SPeter Avalos int first_fs; /* for write.c */ 10059bf7050SPeter Avalos struct archive *matching; /* for matching.c */ 10160b4ad09SPeter Avalos struct security *security; /* for read.c */ 10260b4ad09SPeter Avalos struct name_cache *uname_cache; /* for write.c */ 10360b4ad09SPeter Avalos struct siginfo_data *siginfo; /* for siginfo.c */ 10460b4ad09SPeter Avalos struct substitution *substitution; /* for subst.c */ 1056b384f39SPeter Avalos char *ppbuff; /* for util.c */ 10660b4ad09SPeter Avalos }; 10760b4ad09SPeter Avalos 108e95abc47Szrj /* Options for flags bitfield */ 109e95abc47Szrj #define OPTFLAG_AUTO_COMPRESS (0x00000001) /* -a */ 110e95abc47Szrj #define OPTFLAG_ABSOLUTE_PATHS (0x00000002) /* -P */ 111e95abc47Szrj #define OPTFLAG_CHROOT (0x00000004) /* --chroot */ 112e95abc47Szrj #define OPTFLAG_FAST_READ (0x00000008) /* --fast-read */ 113e95abc47Szrj #define OPTFLAG_IGNORE_ZEROS (0x00000010) /* --ignore-zeros */ 114e95abc47Szrj #define OPTFLAG_INTERACTIVE (0x00000020) /* -w */ 115e95abc47Szrj #define OPTFLAG_NO_OWNER (0x00000040) /* -o */ 116e95abc47Szrj #define OPTFLAG_NO_SUBDIRS (0x00000080) /* -n */ 117e95abc47Szrj #define OPTFLAG_NULL (0x00000100) /* --null */ 118e95abc47Szrj #define OPTFLAG_NUMERIC_OWNER (0x00000200) /* --numeric-owner */ 119e95abc47Szrj #define OPTFLAG_O (0x00000400) /* -o */ 120e95abc47Szrj #define OPTFLAG_STDOUT (0x00000800) /* -O */ 121e95abc47Szrj #define OPTFLAG_TOTALS (0x00001000) /* --totals */ 122e95abc47Szrj #define OPTFLAG_UNLINK_FIRST (0x00002000) /* -U */ 123e95abc47Szrj #define OPTFLAG_WARN_LINKS (0x00004000) /* --check-links */ 124e95abc47Szrj #define OPTFLAG_NO_XATTRS (0x00008000) /* --no-xattrs */ 125e95abc47Szrj #define OPTFLAG_XATTRS (0x00010000) /* --xattrs */ 126e95abc47Szrj #define OPTFLAG_NO_ACLS (0x00020000) /* --no-acls */ 127e95abc47Szrj #define OPTFLAG_ACLS (0x00040000) /* --acls */ 128e95abc47Szrj #define OPTFLAG_NO_FFLAGS (0x00080000) /* --no-fflags */ 129e95abc47Szrj #define OPTFLAG_FFLAGS (0x00100000) /* --fflags */ 130e95abc47Szrj #define OPTFLAG_NO_MAC_METADATA (0x00200000) /* --no-mac-metadata */ 131e95abc47Szrj #define OPTFLAG_MAC_METADATA (0x00400000) /* --mac-metadata */ 132*50f8aa9cSAntonio Huete Jimenez #define OPTFLAG_NO_READ_SPARSE (0x00800000) /* --no-read-sparse */ 133*50f8aa9cSAntonio Huete Jimenez #define OPTFLAG_READ_SPARSE (0x01000000) /* --read-sparse */ 134e95abc47Szrj 1358029ab02SPeter Avalos /* Fake short equivalents for long options that otherwise lack them. */ 1368029ab02SPeter Avalos enum { 137e95abc47Szrj OPTION_ACLS = 1, 138e95abc47Szrj OPTION_B64ENCODE, 139d4d8193eSPeter Avalos OPTION_CHECK_LINKS, 1408029ab02SPeter Avalos OPTION_CHROOT, 1416b384f39SPeter Avalos OPTION_CLEAR_NOCHANGE_FFLAGS, 1428029ab02SPeter Avalos OPTION_EXCLUDE, 143085658deSDaniel Fojt OPTION_EXCLUDE_VCS, 144e95abc47Szrj OPTION_FFLAGS, 1458029ab02SPeter Avalos OPTION_FORMAT, 146c09f92d2SPeter Avalos OPTION_GID, 147c09f92d2SPeter Avalos OPTION_GNAME, 148d4d8193eSPeter Avalos OPTION_GRZIP, 1498029ab02SPeter Avalos OPTION_HELP, 150d4d8193eSPeter Avalos OPTION_HFS_COMPRESSION, 1516b384f39SPeter Avalos OPTION_IGNORE_ZEROS, 1528029ab02SPeter Avalos OPTION_INCLUDE, 1538029ab02SPeter Avalos OPTION_KEEP_NEWER_FILES, 154d4d8193eSPeter Avalos OPTION_LRZIP, 1556b384f39SPeter Avalos OPTION_LZ4, 156c09f92d2SPeter Avalos OPTION_LZIP, 1578029ab02SPeter Avalos OPTION_LZMA, 158d4d8193eSPeter Avalos OPTION_LZOP, 159e95abc47Szrj OPTION_MAC_METADATA, 1608029ab02SPeter Avalos OPTION_NEWER_CTIME, 1618029ab02SPeter Avalos OPTION_NEWER_CTIME_THAN, 1628029ab02SPeter Avalos OPTION_NEWER_MTIME, 1638029ab02SPeter Avalos OPTION_NEWER_MTIME_THAN, 1648029ab02SPeter Avalos OPTION_NODUMP, 165d4d8193eSPeter Avalos OPTION_NOPRESERVE_HFS_COMPRESSION, 166e95abc47Szrj OPTION_NO_ACLS, 167e95abc47Szrj OPTION_NO_FFLAGS, 168e95abc47Szrj OPTION_NO_MAC_METADATA, 169*50f8aa9cSAntonio Huete Jimenez OPTION_NO_READ_SPARSE, 170085658deSDaniel Fojt OPTION_NO_SAFE_WRITES, 1718029ab02SPeter Avalos OPTION_NO_SAME_OWNER, 1728029ab02SPeter Avalos OPTION_NO_SAME_PERMISSIONS, 173e95abc47Szrj OPTION_NO_XATTRS, 1748029ab02SPeter Avalos OPTION_NULL, 1758029ab02SPeter Avalos OPTION_NUMERIC_OWNER, 176d4d8193eSPeter Avalos OPTION_OLDER_CTIME, 177d4d8193eSPeter Avalos OPTION_OLDER_CTIME_THAN, 178d4d8193eSPeter Avalos OPTION_OLDER_MTIME, 179d4d8193eSPeter Avalos OPTION_OLDER_MTIME_THAN, 1808029ab02SPeter Avalos OPTION_ONE_FILE_SYSTEM, 181c09f92d2SPeter Avalos OPTION_OPTIONS, 1826b384f39SPeter Avalos OPTION_PASSPHRASE, 1838029ab02SPeter Avalos OPTION_POSIX, 184*50f8aa9cSAntonio Huete Jimenez OPTION_READ_SPARSE, 185085658deSDaniel Fojt OPTION_SAFE_WRITES, 1868029ab02SPeter Avalos OPTION_SAME_OWNER, 1878029ab02SPeter Avalos OPTION_STRIP_COMPONENTS, 1888029ab02SPeter Avalos OPTION_TOTALS, 189c09f92d2SPeter Avalos OPTION_UID, 190c09f92d2SPeter Avalos OPTION_UNAME, 1918029ab02SPeter Avalos OPTION_USE_COMPRESS_PROGRAM, 192d4d8193eSPeter Avalos OPTION_UUENCODE, 193e95abc47Szrj OPTION_VERSION, 194e95abc47Szrj OPTION_XATTRS, 195e95abc47Szrj OPTION_ZSTD, 1968029ab02SPeter Avalos }; 1978029ab02SPeter Avalos 1988029ab02SPeter Avalos int bsdtar_getopt(struct bsdtar *); 19960b4ad09SPeter Avalos void do_chdir(struct bsdtar *); 20060b4ad09SPeter Avalos int edit_pathname(struct bsdtar *, struct archive_entry *); 2019c82a63eSPeter Avalos int need_report(void); 20260b4ad09SPeter Avalos int pathcmp(const char *a, const char *b); 203e95abc47Szrj void safe_fprintf(FILE *, const char *fmt, ...) __LA_PRINTF(2, 3); 20460b4ad09SPeter Avalos void set_chdir(struct bsdtar *, const char *newdir); 2059c82a63eSPeter Avalos const char *tar_i64toa(int64_t); 20660b4ad09SPeter Avalos void tar_mode_c(struct bsdtar *bsdtar); 20760b4ad09SPeter Avalos void tar_mode_r(struct bsdtar *bsdtar); 20860b4ad09SPeter Avalos void tar_mode_t(struct bsdtar *bsdtar); 20960b4ad09SPeter Avalos void tar_mode_u(struct bsdtar *bsdtar); 21060b4ad09SPeter Avalos void tar_mode_x(struct bsdtar *bsdtar); 211e95abc47Szrj void usage(void) __LA_DEAD; 212e95abc47Szrj int yes(const char *fmt, ...) __LA_PRINTF(1, 2); 21360b4ad09SPeter Avalos 214d4d8193eSPeter Avalos #if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) 21560b4ad09SPeter Avalos void add_substitution(struct bsdtar *, const char *); 216c09f92d2SPeter Avalos int apply_substitution(struct bsdtar *, const char *, char **, int, int); 21760b4ad09SPeter Avalos void cleanup_substitution(struct bsdtar *); 21860b4ad09SPeter Avalos #endif 219d4d8193eSPeter Avalos 220d4d8193eSPeter Avalos void cset_add_filter(struct creation_set *, const char *); 221d4d8193eSPeter Avalos void cset_add_filter_program(struct creation_set *, const char *); 222d4d8193eSPeter Avalos int cset_auto_compress(struct creation_set *, const char *); 223d4d8193eSPeter Avalos void cset_free(struct creation_set *); 224d4d8193eSPeter Avalos const char * cset_get_format(struct creation_set *); 225d4d8193eSPeter Avalos struct creation_set *cset_new(void); 226d4d8193eSPeter Avalos int cset_read_support_filter_program(struct creation_set *, 227d4d8193eSPeter Avalos struct archive *); 228d4d8193eSPeter Avalos void cset_set_format(struct creation_set *, const char *); 229d4d8193eSPeter Avalos int cset_write_add_filters(struct creation_set *, 230d4d8193eSPeter Avalos struct archive *, const void **); 231d4d8193eSPeter Avalos 2326b384f39SPeter Avalos const char * passphrase_callback(struct archive *, void *); 2336b384f39SPeter Avalos void passphrase_free(char *); 2346b384f39SPeter Avalos void list_item_verbose(struct bsdtar *, FILE *, 2356b384f39SPeter Avalos struct archive_entry *); 236085658deSDaniel Fojt 237085658deSDaniel Fojt #endif 238