Blame tar/bsdtar.h

Packit Service 1d0348
/*-
Packit Service 1d0348
 * Copyright (c) 2003-2007 Tim Kientzle
Packit Service 1d0348
 * All rights reserved.
Packit Service 1d0348
 *
Packit Service 1d0348
 * Redistribution and use in source and binary forms, with or without
Packit Service 1d0348
 * modification, are permitted provided that the following conditions
Packit Service 1d0348
 * are met:
Packit Service 1d0348
 * 1. Redistributions of source code must retain the above copyright
Packit Service 1d0348
 *    notice, this list of conditions and the following disclaimer.
Packit Service 1d0348
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service 1d0348
 *    notice, this list of conditions and the following disclaimer in the
Packit Service 1d0348
 *    documentation and/or other materials provided with the distribution.
Packit Service 1d0348
 *
Packit Service 1d0348
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
Packit Service 1d0348
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
Packit Service 1d0348
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
Packit Service 1d0348
 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
Packit Service 1d0348
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
Packit Service 1d0348
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 1d0348
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 1d0348
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 1d0348
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
Packit Service 1d0348
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Packit Service 1d0348
 *
Packit Service 1d0348
 * $FreeBSD: src/usr.bin/tar/bsdtar.h,v 1.37 2008/12/06 07:37:14 kientzle Exp $
Packit Service 1d0348
 */
Packit Service 1d0348
Packit Service 1d0348
#include "bsdtar_platform.h"
Packit Service 1d0348
#include <stdio.h>
Packit Service 1d0348
Packit Service 1d0348
#define	DEFAULT_BYTES_PER_BLOCK	(20*512)
Packit Service 1d0348
#define ENV_READER_OPTIONS	"TAR_READER_OPTIONS"
Packit Service 1d0348
#define ENV_WRITER_OPTIONS	"TAR_WRITER_OPTIONS"
Packit Service 1d0348
#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__,"
Packit Service 1d0348
Packit Service 1d0348
struct creation_set;
Packit Service 1d0348
/*
Packit Service 1d0348
 * The internal state for the "bsdtar" program.
Packit Service 1d0348
 *
Packit Service 1d0348
 * Keeping all of the state in a structure like this simplifies memory
Packit Service 1d0348
 * leak testing (at exit, anything left on the heap is suspect).  A
Packit Service 1d0348
 * pointer to this structure is passed to most bsdtar internal
Packit Service 1d0348
 * functions.
Packit Service 1d0348
 */
Packit Service 1d0348
struct bsdtar {
Packit Service 1d0348
	/* Options */
Packit Service 1d0348
	const char	 *filename; /* -f filename */
Packit Service 1d0348
	char		 *pending_chdir; /* -C dir */
Packit Service 1d0348
	const char	 *names_from_file; /* -T file */
Packit Service 1d0348
	int		  bytes_per_block; /* -b block_size */
Packit Service 1d0348
	int		  bytes_in_last_block; /* See -b handling. */
Packit Service 1d0348
	int		  verbose;   /* -v */
Packit Service 1d0348
	unsigned int	  flags; /* Bitfield of boolean options */
Packit Service 1d0348
	int		  extract_flags; /* Flags for extract operation */
Packit Service 1d0348
	int		  readdisk_flags; /* Flags for read disk operation */
Packit Service 1d0348
	int		  strip_components; /* Remove this many leading dirs */
Packit Service 1d0348
	int		  gid;  /* --gid */
Packit Service 1d0348
	const char	 *gname; /* --gname */
Packit Service 1d0348
	int		  uid;  /* --uid */
Packit Service 1d0348
	const char	 *uname; /* --uname */
Packit Service 1d0348
	const char	 *passphrase; /* --passphrase */
Packit Service 1d0348
	char		  mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
Packit Service 1d0348
	char		  symlink_mode; /* H or L, per BSD conventions */
Packit Service 1d0348
	const char	 *option_options; /* --options */
Packit Service 1d0348
	char		  day_first; /* show day before month in -tv output */
Packit Service 1d0348
	struct creation_set *cset;
Packit Service 1d0348
Packit Service 1d0348
	/* Option parser state */
Packit Service 1d0348
	int		  getopt_state;
Packit Service 1d0348
	char		 *getopt_word;
Packit Service 1d0348
Packit Service 1d0348
	/* If >= 0, then close this when done. */
Packit Service 1d0348
	int		  fd;
Packit Service 1d0348
Packit Service 1d0348
	/* Miscellaneous state information */
Packit Service 1d0348
	int		  argc;
Packit Service 1d0348
	char		**argv;
Packit Service 1d0348
	const char	 *argument;
Packit Service 1d0348
	size_t		  gs_width; /* For 'list_item' in read.c */
Packit Service 1d0348
	size_t		  u_width; /* for 'list_item' in read.c */
Packit Service 1d0348
	uid_t		  user_uid; /* UID running this program */
Packit Service 1d0348
	int		  return_value; /* Value returned by main() */
Packit Service 1d0348
	char		  warned_lead_slash; /* Already displayed warning */
Packit Service 1d0348
	char		  next_line_is_dir; /* Used for -C parsing in -cT */
Packit Service 1d0348
Packit Service 1d0348
	/*
Packit Service 1d0348
	 * Data for various subsystems.  Full definitions are located in
Packit Service 1d0348
	 * the file where they are used.
Packit Service 1d0348
	 */
Packit Service 1d0348
	struct archive		*diskreader;	/* for write.c */
Packit Service 1d0348
	struct archive_entry_linkresolver *resolver; /* for write.c */
Packit Service 1d0348
	struct archive_dir	*archive_dir;	/* for write.c */
Packit Service 1d0348
	struct name_cache	*gname_cache;	/* for write.c */
Packit Service 1d0348
	char			*buff;		/* for write.c */
Packit Service 1d0348
	size_t			 buff_size;	/* for write.c */
Packit Service 1d0348
	int			 first_fs;	/* for write.c */
Packit Service 1d0348
	struct archive		*matching;	/* for matching.c */
Packit Service 1d0348
	struct security		*security;	/* for read.c */
Packit Service 1d0348
	struct name_cache	*uname_cache;	/* for write.c */
Packit Service 1d0348
	struct siginfo_data	*siginfo;	/* for siginfo.c */
Packit Service 1d0348
	struct substitution	*substitution;	/* for subst.c */
Packit Service 1d0348
	char			*ppbuff;	/* for util.c */
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
/* Options for flags bitfield */
Packit Service 1d0348
#define	OPTFLAG_AUTO_COMPRESS	(0x00000001)	/* -a */
Packit Service 1d0348
#define	OPTFLAG_ABSOLUTE_PATHS	(0x00000002)	/* -P */
Packit Service 1d0348
#define	OPTFLAG_CHROOT		(0x00000004)	/* --chroot */
Packit Service 1d0348
#define	OPTFLAG_FAST_READ	(0x00000008)	/* --fast-read */
Packit Service 1d0348
#define	OPTFLAG_IGNORE_ZEROS	(0x00000010)	/* --ignore-zeros */
Packit Service 1d0348
#define	OPTFLAG_INTERACTIVE	(0x00000020)	/* -w */
Packit Service 1d0348
#define	OPTFLAG_NO_OWNER	(0x00000040)	/* -o */
Packit Service 1d0348
#define	OPTFLAG_NO_SUBDIRS	(0x00000080)	/* -n */
Packit Service 1d0348
#define	OPTFLAG_NULL		(0x00000100)	/* --null */
Packit Service 1d0348
#define	OPTFLAG_NUMERIC_OWNER	(0x00000200)	/* --numeric-owner */
Packit Service 1d0348
#define	OPTFLAG_O		(0x00000400)	/* -o */
Packit Service 1d0348
#define	OPTFLAG_STDOUT		(0x00000800)	/* -O */
Packit Service 1d0348
#define	OPTFLAG_TOTALS		(0x00001000)	/* --totals */
Packit Service 1d0348
#define	OPTFLAG_UNLINK_FIRST	(0x00002000)	/* -U */
Packit Service 1d0348
#define	OPTFLAG_WARN_LINKS	(0x00004000)	/* --check-links */
Packit Service 1d0348
#define	OPTFLAG_NO_XATTRS	(0x00008000)	/* --no-xattrs */
Packit Service 1d0348
#define	OPTFLAG_XATTRS		(0x00010000)	/* --xattrs */
Packit Service 1d0348
#define	OPTFLAG_NO_ACLS		(0x00020000)	/* --no-acls */
Packit Service 1d0348
#define	OPTFLAG_ACLS		(0x00040000)	/* --acls */
Packit Service 1d0348
#define	OPTFLAG_NO_FFLAGS	(0x00080000)	/* --no-fflags */
Packit Service 1d0348
#define	OPTFLAG_FFLAGS		(0x00100000)	/* --fflags */
Packit Service 1d0348
#define	OPTFLAG_NO_MAC_METADATA	(0x00200000)	/* --no-mac-metadata */
Packit Service 1d0348
#define	OPTFLAG_MAC_METADATA	(0x00400000)	/* --mac-metadata */
Packit Service 1d0348
Packit Service 1d0348
/* Fake short equivalents for long options that otherwise lack them. */
Packit Service 1d0348
enum {
Packit Service 1d0348
	OPTION_ACLS = 1,
Packit Service 1d0348
	OPTION_B64ENCODE,
Packit Service 1d0348
	OPTION_CHECK_LINKS,
Packit Service 1d0348
	OPTION_CHROOT,
Packit Service 1d0348
	OPTION_CLEAR_NOCHANGE_FFLAGS,
Packit Service 1d0348
	OPTION_EXCLUDE,
Packit Service 1d0348
	OPTION_FFLAGS,
Packit Service 1d0348
	OPTION_FORMAT,
Packit Service 1d0348
	OPTION_GID,
Packit Service 1d0348
	OPTION_GNAME,
Packit Service 1d0348
	OPTION_GRZIP,
Packit Service 1d0348
	OPTION_HELP,
Packit Service 1d0348
	OPTION_HFS_COMPRESSION,
Packit Service 1d0348
	OPTION_IGNORE_ZEROS,
Packit Service 1d0348
	OPTION_INCLUDE,
Packit Service 1d0348
	OPTION_KEEP_NEWER_FILES,
Packit Service 1d0348
	OPTION_LRZIP,
Packit Service 1d0348
	OPTION_LZ4,
Packit Service 1d0348
	OPTION_LZIP,
Packit Service 1d0348
	OPTION_LZMA,
Packit Service 1d0348
	OPTION_LZOP,
Packit Service 1d0348
	OPTION_MAC_METADATA,
Packit Service 1d0348
	OPTION_NEWER_CTIME,
Packit Service 1d0348
	OPTION_NEWER_CTIME_THAN,
Packit Service 1d0348
	OPTION_NEWER_MTIME,
Packit Service 1d0348
	OPTION_NEWER_MTIME_THAN,
Packit Service 1d0348
	OPTION_NODUMP,
Packit Service 1d0348
	OPTION_NOPRESERVE_HFS_COMPRESSION,
Packit Service 1d0348
	OPTION_NO_ACLS,
Packit Service 1d0348
	OPTION_NO_FFLAGS,
Packit Service 1d0348
	OPTION_NO_MAC_METADATA,
Packit Service 1d0348
	OPTION_NO_SAME_OWNER,
Packit Service 1d0348
	OPTION_NO_SAME_PERMISSIONS,
Packit Service 1d0348
	OPTION_NO_XATTRS,
Packit Service 1d0348
	OPTION_NULL,
Packit Service 1d0348
	OPTION_NUMERIC_OWNER,
Packit Service 1d0348
	OPTION_OLDER_CTIME,
Packit Service 1d0348
	OPTION_OLDER_CTIME_THAN,
Packit Service 1d0348
	OPTION_OLDER_MTIME,
Packit Service 1d0348
	OPTION_OLDER_MTIME_THAN,
Packit Service 1d0348
	OPTION_ONE_FILE_SYSTEM,
Packit Service 1d0348
	OPTION_OPTIONS,
Packit Service 1d0348
	OPTION_PASSPHRASE,
Packit Service 1d0348
	OPTION_POSIX,
Packit Service 1d0348
	OPTION_SAME_OWNER,
Packit Service 1d0348
	OPTION_STRIP_COMPONENTS,
Packit Service 1d0348
	OPTION_TOTALS,
Packit Service 1d0348
	OPTION_UID,
Packit Service 1d0348
	OPTION_UNAME,
Packit Service 1d0348
	OPTION_USE_COMPRESS_PROGRAM,
Packit Service 1d0348
	OPTION_UUENCODE,
Packit Service 1d0348
	OPTION_VERSION,
Packit Service 1d0348
	OPTION_XATTRS,
Packit Service 1d0348
	OPTION_ZSTD,
Packit Service 1d0348
};
Packit Service 1d0348
Packit Service 1d0348
int	bsdtar_getopt(struct bsdtar *);
Packit Service 1d0348
void	do_chdir(struct bsdtar *);
Packit Service 1d0348
int	edit_pathname(struct bsdtar *, struct archive_entry *);
Packit Service 1d0348
int	need_report(void);
Packit Service 1d0348
int	pathcmp(const char *a, const char *b);
Packit Service 1d0348
void	safe_fprintf(FILE *, const char *fmt, ...) __LA_PRINTF(2, 3);
Packit Service 1d0348
void	set_chdir(struct bsdtar *, const char *newdir);
Packit Service 1d0348
const char *tar_i64toa(int64_t);
Packit Service 1d0348
void	tar_mode_c(struct bsdtar *bsdtar);
Packit Service 1d0348
void	tar_mode_r(struct bsdtar *bsdtar);
Packit Service 1d0348
void	tar_mode_t(struct bsdtar *bsdtar);
Packit Service 1d0348
void	tar_mode_u(struct bsdtar *bsdtar);
Packit Service 1d0348
void	tar_mode_x(struct bsdtar *bsdtar);
Packit Service 1d0348
void	usage(void) __LA_DEAD;
Packit Service 1d0348
int	yes(const char *fmt, ...) __LA_PRINTF(1, 2);
Packit Service 1d0348
Packit Service 1d0348
#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
Packit Service 1d0348
void	add_substitution(struct bsdtar *, const char *);
Packit Service 1d0348
int	apply_substitution(struct bsdtar *, const char *, char **, int, int);
Packit Service 1d0348
void	cleanup_substitution(struct bsdtar *);
Packit Service 1d0348
#endif
Packit Service 1d0348
Packit Service 1d0348
void		cset_add_filter(struct creation_set *, const char *);
Packit Service 1d0348
void		cset_add_filter_program(struct creation_set *, const char *);
Packit Service 1d0348
int		cset_auto_compress(struct creation_set *, const char *);
Packit Service 1d0348
void		cset_free(struct creation_set *);
Packit Service 1d0348
const char *	cset_get_format(struct creation_set *);
Packit Service 1d0348
struct creation_set *cset_new(void);
Packit Service 1d0348
int		cset_read_support_filter_program(struct creation_set *,
Packit Service 1d0348
		    struct archive *);
Packit Service 1d0348
void		cset_set_format(struct creation_set *, const char *);
Packit Service 1d0348
int		cset_write_add_filters(struct creation_set *,
Packit Service 1d0348
		    struct archive *, const void **);
Packit Service 1d0348
Packit Service 1d0348
const char * passphrase_callback(struct archive *, void *);
Packit Service 1d0348
void	     passphrase_free(char *);
Packit Service 1d0348
void	list_item_verbose(struct bsdtar *, FILE *,
Packit Service 1d0348
		    struct archive_entry *);