2004-04-05 21:32:18 +00:00
|
|
|
/*-
|
|
|
|
* Copyright (c) 2003-2004 Tim Kientzle
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer
|
|
|
|
* in this position and unchanged.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name(s) of the author(s) may not be used to endorse or promote
|
|
|
|
* products derived from this software without specific prior written
|
|
|
|
* permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
|
|
|
|
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
|
|
|
|
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
|
|
|
* IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
|
|
|
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
|
|
|
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
* $FreeBSD$
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <archive.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
2004-06-07 03:19:57 +00:00
|
|
|
#define DEFAULT_BYTES_PER_BLOCK (20*512)
|
|
|
|
|
2004-04-05 21:32:18 +00:00
|
|
|
/*
|
2004-04-15 22:37:54 +00:00
|
|
|
* The internal state for the "bsdtar" program.
|
|
|
|
*
|
|
|
|
* Keeping all of the state in a structure like this simplifies memory
|
|
|
|
* leak testing (at exit, anything left on the heap is suspect). A
|
|
|
|
* pointer to this structure is passed to most bsdtar internal
|
|
|
|
* functions.
|
2004-04-05 21:32:18 +00:00
|
|
|
*/
|
|
|
|
struct bsdtar {
|
|
|
|
/* Options */
|
|
|
|
const char *filename; /* -f filename */
|
|
|
|
const char *create_format; /* -F format */
|
|
|
|
const char *start_dir; /* -C dir */
|
2004-04-08 06:12:01 +00:00
|
|
|
const char *names_from_file; /* -T file */
|
2004-04-05 21:32:18 +00:00
|
|
|
int bytes_per_block; /* -b block_size */
|
|
|
|
int verbose; /* -v */
|
|
|
|
int extract_flags; /* Flags for extract operation */
|
|
|
|
char symlink_mode; /* H or L, per BSD conventions */
|
|
|
|
char create_compression; /* j, y, or z */
|
|
|
|
char option_absolute_paths; /* -P */
|
|
|
|
char option_dont_traverse_mounts; /* -X */
|
|
|
|
char option_fast_read; /* --fast-read */
|
|
|
|
char option_honor_nodump; /* --nodump */
|
|
|
|
char option_interactive; /* -w */
|
|
|
|
char option_no_subdirs; /* -d */
|
|
|
|
char option_stdout; /* -p */
|
2004-05-17 03:33:06 +00:00
|
|
|
char option_unlink_first; /* -U */
|
2004-04-05 21:32:18 +00:00
|
|
|
char option_warn_links; /* -l */
|
|
|
|
|
|
|
|
/* If >= 0, then close this when done. */
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
/* Miscellaneous state information */
|
2004-05-17 05:44:53 +00:00
|
|
|
const char *progname;
|
2004-04-05 21:32:18 +00:00
|
|
|
int argc;
|
|
|
|
char **argv;
|
2004-04-15 22:37:54 +00:00
|
|
|
size_t gs_width; /* For 'list_item' in read.c */
|
|
|
|
size_t u_width; /* for 'list_item' in read.c */
|
|
|
|
char *user_uname; /* User running this program */
|
|
|
|
uid_t user_uid; /* UID running this program */
|
2004-05-27 04:30:59 +00:00
|
|
|
int return_value; /* Value returned by main() */
|
|
|
|
char warned_lead_slash; /* Already displayed warning */
|
2004-04-05 21:32:18 +00:00
|
|
|
|
2004-04-15 22:37:54 +00:00
|
|
|
/*
|
|
|
|
* Data for various subsystems. Full definitions are located in
|
|
|
|
* the file where they are used.
|
|
|
|
*/
|
|
|
|
struct archive_dir *archive_dir; /* for write.c */
|
2004-05-17 05:02:39 +00:00
|
|
|
struct name_cache *gname_cache; /* for write.c */
|
2004-04-15 22:37:54 +00:00
|
|
|
struct links_cache *links_cache; /* for write.c */
|
|
|
|
struct matching *matching; /* for matching.c */
|
2004-05-02 00:43:02 +00:00
|
|
|
struct security *security; /* for read.c */
|
2004-05-17 05:02:39 +00:00
|
|
|
struct name_cache *uname_cache; /* for write.c */
|
2004-04-05 21:32:18 +00:00
|
|
|
};
|
|
|
|
|
2004-05-17 05:44:53 +00:00
|
|
|
void bsdtar_errc(struct bsdtar *, int _eval, int _code,
|
|
|
|
const char *fmt, ...);
|
2004-05-03 21:05:59 +00:00
|
|
|
void bsdtar_strmode(struct archive_entry *entry, char *bp);
|
2004-05-17 05:44:53 +00:00
|
|
|
void bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
|
2004-04-05 21:32:18 +00:00
|
|
|
void cleanup_exclusions(struct bsdtar *);
|
|
|
|
void exclude(struct bsdtar *, const char *pattern);
|
2004-06-15 05:55:41 +00:00
|
|
|
void exclude_from_file(struct bsdtar *, const char *pathname);
|
2004-04-05 21:32:18 +00:00
|
|
|
int excluded(struct bsdtar *, const char *pathname);
|
|
|
|
void include(struct bsdtar *, const char *pattern);
|
|
|
|
void safe_fprintf(FILE *, const char *fmt, ...);
|
|
|
|
void tar_mode_c(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_r(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_t(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_u(struct bsdtar *bsdtar);
|
|
|
|
void tar_mode_x(struct bsdtar *bsdtar);
|
|
|
|
int unmatched_inclusions(struct bsdtar *bsdtar);
|
2004-05-17 05:44:53 +00:00
|
|
|
void usage(struct bsdtar *);
|
2004-04-05 21:32:18 +00:00
|
|
|
int yes(const char *fmt, ...);
|
|
|
|
|