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 2860b4ad09SPeter Avalos #include "bsdtar_platform.h" 2960b4ad09SPeter Avalos #include <stdio.h> 3060b4ad09SPeter Avalos 31*9c82a63eSPeter Avalos #include "matching.h" 32*9c82a63eSPeter Avalos 3360b4ad09SPeter Avalos #define DEFAULT_BYTES_PER_BLOCK (20*512) 3460b4ad09SPeter Avalos 3560b4ad09SPeter Avalos /* 3660b4ad09SPeter Avalos * The internal state for the "bsdtar" program. 3760b4ad09SPeter Avalos * 3860b4ad09SPeter Avalos * Keeping all of the state in a structure like this simplifies memory 3960b4ad09SPeter Avalos * leak testing (at exit, anything left on the heap is suspect). A 4060b4ad09SPeter Avalos * pointer to this structure is passed to most bsdtar internal 4160b4ad09SPeter Avalos * functions. 4260b4ad09SPeter Avalos */ 4360b4ad09SPeter Avalos struct bsdtar { 4460b4ad09SPeter Avalos /* Options */ 4560b4ad09SPeter Avalos const char *filename; /* -f filename */ 4660b4ad09SPeter Avalos const char *create_format; /* -F format */ 4760b4ad09SPeter Avalos char *pending_chdir; /* -C dir */ 4860b4ad09SPeter Avalos const char *names_from_file; /* -T file */ 4960b4ad09SPeter Avalos time_t newer_ctime_sec; /* --newer/--newer-than */ 5060b4ad09SPeter Avalos long newer_ctime_nsec; /* --newer/--newer-than */ 5160b4ad09SPeter Avalos time_t newer_mtime_sec; /* --newer-mtime */ 5260b4ad09SPeter Avalos long newer_mtime_nsec; /* --newer-mtime-than */ 5360b4ad09SPeter Avalos int bytes_per_block; /* -b block_size */ 5460b4ad09SPeter Avalos int verbose; /* -v */ 5560b4ad09SPeter Avalos int extract_flags; /* Flags for extract operation */ 5660b4ad09SPeter Avalos int strip_components; /* Remove this many leading dirs */ 5760b4ad09SPeter Avalos char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ 5860b4ad09SPeter Avalos char symlink_mode; /* H or L, per BSD conventions */ 5960b4ad09SPeter Avalos char create_compression; /* j, y, or z */ 6060b4ad09SPeter Avalos const char *compress_program; 6160b4ad09SPeter Avalos char option_absolute_paths; /* -P */ 6260b4ad09SPeter Avalos char option_chroot; /* --chroot */ 6360b4ad09SPeter Avalos char option_dont_traverse_mounts; /* --one-file-system */ 6460b4ad09SPeter Avalos char option_fast_read; /* --fast-read */ 658029ab02SPeter Avalos const char *option_options; /* --options */ 6660b4ad09SPeter Avalos char option_honor_nodump; /* --nodump */ 6760b4ad09SPeter Avalos char option_interactive; /* -w */ 6860b4ad09SPeter Avalos char option_no_owner; /* -o */ 6960b4ad09SPeter Avalos char option_no_subdirs; /* -n */ 7060b4ad09SPeter Avalos char option_null; /* --null */ 7160b4ad09SPeter Avalos char option_numeric_owner; /* --numeric-owner */ 7260b4ad09SPeter Avalos char option_stdout; /* -O */ 7360b4ad09SPeter Avalos char option_totals; /* --totals */ 7460b4ad09SPeter Avalos char option_unlink_first; /* -U */ 7560b4ad09SPeter Avalos char option_warn_links; /* --check-links */ 7660b4ad09SPeter Avalos char day_first; /* show day before month in -tv output */ 7760b4ad09SPeter Avalos 7860b4ad09SPeter Avalos /* If >= 0, then close this when done. */ 7960b4ad09SPeter Avalos int fd; 8060b4ad09SPeter Avalos 8160b4ad09SPeter Avalos /* Miscellaneous state information */ 8260b4ad09SPeter Avalos int argc; 8360b4ad09SPeter Avalos char **argv; 848029ab02SPeter Avalos const char *optarg; 8560b4ad09SPeter Avalos size_t gs_width; /* For 'list_item' in read.c */ 8660b4ad09SPeter Avalos size_t u_width; /* for 'list_item' in read.c */ 8760b4ad09SPeter Avalos uid_t user_uid; /* UID running this program */ 8860b4ad09SPeter Avalos int return_value; /* Value returned by main() */ 8960b4ad09SPeter Avalos char warned_lead_slash; /* Already displayed warning */ 9060b4ad09SPeter Avalos char next_line_is_dir; /* Used for -C parsing in -cT */ 9160b4ad09SPeter Avalos 9260b4ad09SPeter Avalos /* 9360b4ad09SPeter Avalos * Data for various subsystems. Full definitions are located in 9460b4ad09SPeter Avalos * the file where they are used. 9560b4ad09SPeter Avalos */ 968029ab02SPeter Avalos struct archive *diskreader; /* for write.c */ 978029ab02SPeter Avalos struct archive_entry_linkresolver *resolver; /* for write.c */ 9860b4ad09SPeter Avalos struct archive_dir *archive_dir; /* for write.c */ 9960b4ad09SPeter Avalos struct name_cache *gname_cache; /* for write.c */ 1008029ab02SPeter Avalos char *buff; /* for write.c */ 101*9c82a63eSPeter Avalos struct lafe_matching *matching; /* for matching.c */ 10260b4ad09SPeter Avalos struct security *security; /* for read.c */ 10360b4ad09SPeter Avalos struct name_cache *uname_cache; /* for write.c */ 10460b4ad09SPeter Avalos struct siginfo_data *siginfo; /* for siginfo.c */ 10560b4ad09SPeter Avalos struct substitution *substitution; /* for subst.c */ 10660b4ad09SPeter Avalos }; 10760b4ad09SPeter Avalos 1088029ab02SPeter Avalos /* Fake short equivalents for long options that otherwise lack them. */ 1098029ab02SPeter Avalos enum { 1108029ab02SPeter Avalos OPTION_CHECK_LINKS = 1, 1118029ab02SPeter Avalos OPTION_CHROOT, 1128029ab02SPeter Avalos OPTION_EXCLUDE, 1138029ab02SPeter Avalos OPTION_FORMAT, 1148029ab02SPeter Avalos OPTION_OPTIONS, 1158029ab02SPeter Avalos OPTION_HELP, 1168029ab02SPeter Avalos OPTION_INCLUDE, 1178029ab02SPeter Avalos OPTION_KEEP_NEWER_FILES, 1188029ab02SPeter Avalos OPTION_LZMA, 1198029ab02SPeter Avalos OPTION_NEWER_CTIME, 1208029ab02SPeter Avalos OPTION_NEWER_CTIME_THAN, 1218029ab02SPeter Avalos OPTION_NEWER_MTIME, 1228029ab02SPeter Avalos OPTION_NEWER_MTIME_THAN, 1238029ab02SPeter Avalos OPTION_NODUMP, 1248029ab02SPeter Avalos OPTION_NO_SAME_OWNER, 1258029ab02SPeter Avalos OPTION_NO_SAME_PERMISSIONS, 1268029ab02SPeter Avalos OPTION_NULL, 1278029ab02SPeter Avalos OPTION_NUMERIC_OWNER, 1288029ab02SPeter Avalos OPTION_ONE_FILE_SYSTEM, 1298029ab02SPeter Avalos OPTION_POSIX, 1308029ab02SPeter Avalos OPTION_SAME_OWNER, 1318029ab02SPeter Avalos OPTION_STRIP_COMPONENTS, 1328029ab02SPeter Avalos OPTION_TOTALS, 1338029ab02SPeter Avalos OPTION_USE_COMPRESS_PROGRAM, 1348029ab02SPeter Avalos OPTION_VERSION 1358029ab02SPeter Avalos }; 1368029ab02SPeter Avalos 1378029ab02SPeter Avalos 1388029ab02SPeter Avalos int bsdtar_getopt(struct bsdtar *); 13960b4ad09SPeter Avalos void do_chdir(struct bsdtar *); 14060b4ad09SPeter Avalos int edit_pathname(struct bsdtar *, struct archive_entry *); 141*9c82a63eSPeter Avalos int need_report(void); 14260b4ad09SPeter Avalos int pathcmp(const char *a, const char *b); 14360b4ad09SPeter Avalos void safe_fprintf(FILE *, const char *fmt, ...); 14460b4ad09SPeter Avalos void set_chdir(struct bsdtar *, const char *newdir); 145*9c82a63eSPeter Avalos const char *tar_i64toa(int64_t); 14660b4ad09SPeter Avalos void tar_mode_c(struct bsdtar *bsdtar); 14760b4ad09SPeter Avalos void tar_mode_r(struct bsdtar *bsdtar); 14860b4ad09SPeter Avalos void tar_mode_t(struct bsdtar *bsdtar); 14960b4ad09SPeter Avalos void tar_mode_u(struct bsdtar *bsdtar); 15060b4ad09SPeter Avalos void tar_mode_x(struct bsdtar *bsdtar); 151*9c82a63eSPeter Avalos void usage(void); 15260b4ad09SPeter Avalos int yes(const char *fmt, ...); 15360b4ad09SPeter Avalos 15460b4ad09SPeter Avalos #if HAVE_REGEX_H 15560b4ad09SPeter Avalos void add_substitution(struct bsdtar *, const char *); 15660b4ad09SPeter Avalos int apply_substitution(struct bsdtar *, const char *, char **, int); 15760b4ad09SPeter Avalos void cleanup_substitution(struct bsdtar *); 15860b4ad09SPeter Avalos #endif 159