bsdtar.h revision 238856
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: head/contrib/libarchive/tar/bsdtar.h 238856 2012-07-28 06:38:44Z mm $ 26228753Smm */ 27228753Smm 28228753Smm#include "bsdtar_platform.h" 29228753Smm#include <stdio.h> 30228753Smm 31228753Smm#define DEFAULT_BYTES_PER_BLOCK (20*512) 32228753Smm 33228753Smm/* 34228753Smm * The internal state for the "bsdtar" program. 35228753Smm * 36228753Smm * Keeping all of the state in a structure like this simplifies memory 37228753Smm * leak testing (at exit, anything left on the heap is suspect). A 38228753Smm * pointer to this structure is passed to most bsdtar internal 39228753Smm * functions. 40228753Smm */ 41228753Smmstruct bsdtar { 42228753Smm /* Options */ 43228753Smm const char *filename; /* -f filename */ 44228753Smm const char *create_format; /* -F format */ 45228753Smm char *pending_chdir; /* -C dir */ 46228753Smm const char *names_from_file; /* -T file */ 47228753Smm int bytes_per_block; /* -b block_size */ 48232153Smm int bytes_in_last_block; /* See -b handling. */ 49228753Smm int verbose; /* -v */ 50228753Smm int extract_flags; /* Flags for extract operation */ 51238856Smm int readdisk_flags; /* Flags for read disk operation */ 52228753Smm int strip_components; /* Remove this many leading dirs */ 53228753Smm int gid; /* --gid */ 54228753Smm const char *gname; /* --gname */ 55228753Smm int uid; /* --uid */ 56228753Smm const char *uname; /* --uname */ 57228753Smm char mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */ 58228753Smm char symlink_mode; /* H or L, per BSD conventions */ 59228753Smm char create_compression; /* j, y, or z */ 60228753Smm const char *compress_program; 61228753Smm char option_absolute_paths; /* -P */ 62228753Smm char option_chroot; /* --chroot */ 63228753Smm char option_fast_read; /* --fast-read */ 64228753Smm const char *option_options; /* --options */ 65228753Smm char option_interactive; /* -w */ 66228753Smm char option_no_owner; /* -o */ 67228753Smm char option_no_subdirs; /* -n */ 68232153Smm char option_numeric_owner; /* --numeric-owner */ 69228753Smm char option_null; /* --null */ 70228753Smm char option_stdout; /* -O */ 71228753Smm char option_totals; /* --totals */ 72228753Smm char option_unlink_first; /* -U */ 73228753Smm char option_warn_links; /* --check-links */ 74228753Smm char day_first; /* show day before month in -tv output */ 75228753Smm 76232153Smm /* Option parser state */ 77232153Smm int getopt_state; 78232153Smm char *getopt_word; 79232153Smm 80228753Smm /* If >= 0, then close this when done. */ 81228753Smm int fd; 82228753Smm 83228753Smm /* Miscellaneous state information */ 84228753Smm int argc; 85228753Smm char **argv; 86232153Smm const char *argument; 87228753Smm size_t gs_width; /* For 'list_item' in read.c */ 88228753Smm size_t u_width; /* for 'list_item' in read.c */ 89228753Smm uid_t user_uid; /* UID running this program */ 90228753Smm int return_value; /* Value returned by main() */ 91228753Smm char warned_lead_slash; /* Already displayed warning */ 92228753Smm char next_line_is_dir; /* Used for -C parsing in -cT */ 93228753Smm 94228753Smm /* 95228753Smm * Data for various subsystems. Full definitions are located in 96228753Smm * the file where they are used. 97228753Smm */ 98228753Smm struct archive *diskreader; /* for write.c */ 99228753Smm struct archive_entry_linkresolver *resolver; /* for write.c */ 100228753Smm struct archive_dir *archive_dir; /* for write.c */ 101228753Smm struct name_cache *gname_cache; /* for write.c */ 102228753Smm char *buff; /* for write.c */ 103232153Smm size_t buff_size; /* for write.c */ 104238856Smm int first_fs; /* for write.c */ 105238856Smm struct archive *matching; /* for matching.c */ 106228753Smm struct security *security; /* for read.c */ 107228753Smm struct name_cache *uname_cache; /* for write.c */ 108228753Smm struct siginfo_data *siginfo; /* for siginfo.c */ 109228753Smm struct substitution *substitution; /* for subst.c */ 110228753Smm}; 111228753Smm 112228753Smm/* Fake short equivalents for long options that otherwise lack them. */ 113228753Smmenum { 114228753Smm OPTION_CHECK_LINKS = 1, 115228753Smm OPTION_CHROOT, 116232153Smm OPTION_DISABLE_COPYFILE, 117228753Smm OPTION_EXCLUDE, 118228753Smm OPTION_FORMAT, 119228753Smm OPTION_GID, 120228753Smm OPTION_GNAME, 121228753Smm OPTION_HELP, 122228753Smm OPTION_INCLUDE, 123228753Smm OPTION_KEEP_NEWER_FILES, 124232153Smm OPTION_LZIP, 125228753Smm OPTION_LZMA, 126228753Smm OPTION_NEWER_CTIME, 127228753Smm OPTION_NEWER_CTIME_THAN, 128228753Smm OPTION_NEWER_MTIME, 129228753Smm OPTION_NEWER_MTIME_THAN, 130228753Smm OPTION_NODUMP, 131228753Smm OPTION_NO_SAME_OWNER, 132228753Smm OPTION_NO_SAME_PERMISSIONS, 133228753Smm OPTION_NULL, 134228753Smm OPTION_NUMERIC_OWNER, 135228753Smm OPTION_ONE_FILE_SYSTEM, 136228753Smm OPTION_OPTIONS, 137228753Smm OPTION_POSIX, 138228753Smm OPTION_SAME_OWNER, 139228753Smm OPTION_STRIP_COMPONENTS, 140228753Smm OPTION_TOTALS, 141228753Smm OPTION_UID, 142228753Smm OPTION_UNAME, 143228753Smm OPTION_USE_COMPRESS_PROGRAM, 144228753Smm OPTION_VERSION 145228753Smm}; 146228753Smm 147228753Smmint bsdtar_getopt(struct bsdtar *); 148228753Smmvoid do_chdir(struct bsdtar *); 149228753Smmint edit_pathname(struct bsdtar *, struct archive_entry *); 150228753Smmint need_report(void); 151228753Smmint pathcmp(const char *a, const char *b); 152228753Smmvoid safe_fprintf(FILE *, const char *fmt, ...); 153228753Smmvoid set_chdir(struct bsdtar *, const char *newdir); 154228753Smmconst char *tar_i64toa(int64_t); 155228753Smmvoid tar_mode_c(struct bsdtar *bsdtar); 156228753Smmvoid tar_mode_r(struct bsdtar *bsdtar); 157228753Smmvoid tar_mode_t(struct bsdtar *bsdtar); 158228753Smmvoid tar_mode_u(struct bsdtar *bsdtar); 159228753Smmvoid tar_mode_x(struct bsdtar *bsdtar); 160228753Smmvoid usage(void); 161228753Smmint yes(const char *fmt, ...); 162228753Smm 163228753Smm#if HAVE_REGEX_H 164228753Smmvoid add_substitution(struct bsdtar *, const char *); 165232153Smmint apply_substitution(struct bsdtar *, const char *, char **, int, int); 166228753Smmvoid cleanup_substitution(struct bsdtar *); 167228753Smm#endif 168