bsdtar.h revision 238856
1/*-
2 * Copyright (c) 2003-2007 Tim Kientzle
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17 * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 *
25 * $FreeBSD: head/contrib/libarchive/tar/bsdtar.h 238856 2012-07-28 06:38:44Z mm $
26 */
27
28#include "bsdtar_platform.h"
29#include <stdio.h>
30
31#define	DEFAULT_BYTES_PER_BLOCK	(20*512)
32
33/*
34 * The internal state for the "bsdtar" program.
35 *
36 * Keeping all of the state in a structure like this simplifies memory
37 * leak testing (at exit, anything left on the heap is suspect).  A
38 * pointer to this structure is passed to most bsdtar internal
39 * functions.
40 */
41struct bsdtar {
42	/* Options */
43	const char	 *filename; /* -f filename */
44	const char	 *create_format; /* -F format */
45	char		 *pending_chdir; /* -C dir */
46	const char	 *names_from_file; /* -T file */
47	int		  bytes_per_block; /* -b block_size */
48	int		  bytes_in_last_block; /* See -b handling. */
49	int		  verbose;   /* -v */
50	int		  extract_flags; /* Flags for extract operation */
51	int		  readdisk_flags; /* Flags for read disk operation */
52	int		  strip_components; /* Remove this many leading dirs */
53	int		  gid;  /* --gid */
54	const char	 *gname; /* --gname */
55	int		  uid;  /* --uid */
56	const char	 *uname; /* --uname */
57	char		  mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
58	char		  symlink_mode; /* H or L, per BSD conventions */
59	char		  create_compression; /* j, y, or z */
60	const char	 *compress_program;
61	char		  option_absolute_paths; /* -P */
62	char		  option_chroot; /* --chroot */
63	char		  option_fast_read; /* --fast-read */
64	const char	 *option_options; /* --options */
65	char		  option_interactive; /* -w */
66	char		  option_no_owner; /* -o */
67	char		  option_no_subdirs; /* -n */
68	char		  option_numeric_owner; /* --numeric-owner */
69	char		  option_null; /* --null */
70	char		  option_stdout; /* -O */
71	char		  option_totals; /* --totals */
72	char		  option_unlink_first; /* -U */
73	char		  option_warn_links; /* --check-links */
74	char		  day_first; /* show day before month in -tv output */
75
76	/* Option parser state */
77	int		  getopt_state;
78	char		 *getopt_word;
79
80	/* If >= 0, then close this when done. */
81	int		  fd;
82
83	/* Miscellaneous state information */
84	int		  argc;
85	char		**argv;
86	const char	 *argument;
87	size_t		  gs_width; /* For 'list_item' in read.c */
88	size_t		  u_width; /* for 'list_item' in read.c */
89	uid_t		  user_uid; /* UID running this program */
90	int		  return_value; /* Value returned by main() */
91	char		  warned_lead_slash; /* Already displayed warning */
92	char		  next_line_is_dir; /* Used for -C parsing in -cT */
93
94	/*
95	 * Data for various subsystems.  Full definitions are located in
96	 * the file where they are used.
97	 */
98	struct archive		*diskreader;	/* for write.c */
99	struct archive_entry_linkresolver *resolver; /* for write.c */
100	struct archive_dir	*archive_dir;	/* for write.c */
101	struct name_cache	*gname_cache;	/* for write.c */
102	char			*buff;		/* for write.c */
103	size_t			 buff_size;	/* for write.c */
104	int			 first_fs;	/* for write.c */
105	struct archive		*matching;	/* for matching.c */
106	struct security		*security;	/* for read.c */
107	struct name_cache	*uname_cache;	/* for write.c */
108	struct siginfo_data	*siginfo;	/* for siginfo.c */
109	struct substitution	*substitution;	/* for subst.c */
110};
111
112/* Fake short equivalents for long options that otherwise lack them. */
113enum {
114	OPTION_CHECK_LINKS = 1,
115	OPTION_CHROOT,
116	OPTION_DISABLE_COPYFILE,
117	OPTION_EXCLUDE,
118	OPTION_FORMAT,
119	OPTION_GID,
120	OPTION_GNAME,
121	OPTION_HELP,
122	OPTION_INCLUDE,
123	OPTION_KEEP_NEWER_FILES,
124	OPTION_LZIP,
125	OPTION_LZMA,
126	OPTION_NEWER_CTIME,
127	OPTION_NEWER_CTIME_THAN,
128	OPTION_NEWER_MTIME,
129	OPTION_NEWER_MTIME_THAN,
130	OPTION_NODUMP,
131	OPTION_NO_SAME_OWNER,
132	OPTION_NO_SAME_PERMISSIONS,
133	OPTION_NULL,
134	OPTION_NUMERIC_OWNER,
135	OPTION_ONE_FILE_SYSTEM,
136	OPTION_OPTIONS,
137	OPTION_POSIX,
138	OPTION_SAME_OWNER,
139	OPTION_STRIP_COMPONENTS,
140	OPTION_TOTALS,
141	OPTION_UID,
142	OPTION_UNAME,
143	OPTION_USE_COMPRESS_PROGRAM,
144	OPTION_VERSION
145};
146
147int	bsdtar_getopt(struct bsdtar *);
148void	do_chdir(struct bsdtar *);
149int	edit_pathname(struct bsdtar *, struct archive_entry *);
150int	need_report(void);
151int	pathcmp(const char *a, const char *b);
152void	safe_fprintf(FILE *, const char *fmt, ...);
153void	set_chdir(struct bsdtar *, const char *newdir);
154const char *tar_i64toa(int64_t);
155void	tar_mode_c(struct bsdtar *bsdtar);
156void	tar_mode_r(struct bsdtar *bsdtar);
157void	tar_mode_t(struct bsdtar *bsdtar);
158void	tar_mode_u(struct bsdtar *bsdtar);
159void	tar_mode_x(struct bsdtar *bsdtar);
160void	usage(void);
161int	yes(const char *fmt, ...);
162
163#if HAVE_REGEX_H
164void	add_substitution(struct bsdtar *, const char *);
165int	apply_substitution(struct bsdtar *, const char *, char **, int, int);
166void	cleanup_substitution(struct bsdtar *);
167#endif
168