bsdtar.h revision 358090
1299425Smm/*-
2299425Smm * Copyright (c) 2003-2007 Tim Kientzle
3299425Smm * All rights reserved.
4299425Smm *
5299425Smm * Redistribution and use in source and binary forms, with or without
6299425Smm * modification, are permitted provided that the following conditions
7299425Smm * are met:
8299425Smm * 1. Redistributions of source code must retain the above copyright
9299425Smm *    notice, this list of conditions and the following disclaimer.
10299425Smm * 2. Redistributions in binary form must reproduce the above copyright
11299425Smm *    notice, this list of conditions and the following disclaimer in the
12299425Smm *    documentation and/or other materials provided with the distribution.
13299425Smm *
14299425Smm * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY EXPRESS OR
15299425Smm * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
16299425Smm * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
17299425Smm * IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE FOR ANY DIRECT, INDIRECT,
18299425Smm * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
19299425Smm * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
20299425Smm * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
21299425Smm * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
22299425Smm * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
23299425Smm * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24299425Smm *
25299425Smm * $FreeBSD: stable/10/contrib/libarchive/tar/bsdtar.h 358090 2020-02-19 01:51:44Z mm $
26358090Smm */
27358090Smm
28358090Smm#ifndef BSDTAR_H_INCLUDED
29299425Smm#define BSDTAR_H_INCLUDED
30299425Smm
31299425Smm#include "bsdtar_platform.h"
32299425Smm#include <stdio.h>
33299425Smm
34299425Smm#define	DEFAULT_BYTES_PER_BLOCK	(20*512)
35299425Smm#define ENV_READER_OPTIONS	"TAR_READER_OPTIONS"
36299425Smm#define ENV_WRITER_OPTIONS	"TAR_WRITER_OPTIONS"
37299425Smm#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__,"
38299425Smm
39299425Smmstruct creation_set;
40299425Smm/*
41299425Smm * The internal state for the "bsdtar" program.
42299425Smm *
43299425Smm * Keeping all of the state in a structure like this simplifies memory
44299425Smm * leak testing (at exit, anything left on the heap is suspect).  A
45299425Smm * pointer to this structure is passed to most bsdtar internal
46299425Smm * functions.
47299425Smm */
48299425Smmstruct bsdtar {
49299425Smm	/* Options */
50299425Smm	const char	 *filename; /* -f filename */
51299425Smm	char		 *pending_chdir; /* -C dir */
52299425Smm	const char	 *names_from_file; /* -T file */
53299425Smm	int		  bytes_per_block; /* -b block_size */
54299425Smm	int		  bytes_in_last_block; /* See -b handling. */
55299425Smm	int		  verbose;   /* -v */
56299425Smm	unsigned int	  flags; /* Bitfield of boolean options */
57299425Smm	int		  extract_flags; /* Flags for extract operation */
58299425Smm	int		  readdisk_flags; /* Flags for read disk operation */
59299425Smm	int		  strip_components; /* Remove this many leading dirs */
60299425Smm	int		  gid;  /* --gid */
61299425Smm	const char	 *gname; /* --gname */
62299425Smm	int		  uid;  /* --uid */
63299425Smm	const char	 *uname; /* --uname */
64299425Smm	const char	 *passphrase; /* --passphrase */
65299425Smm	char		  mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
66322072Smm	char		  symlink_mode; /* H or L, per BSD conventions */
67299425Smm	const char	 *option_options; /* --options */
68299425Smm	char		  day_first; /* show day before month in -tv output */
69299425Smm	struct creation_set *cset;
70299425Smm
71299425Smm	/* Option parser state */
72299425Smm	int		  getopt_state;
73299425Smm	char		 *getopt_word;
74299425Smm
75299425Smm	/* If >= 0, then close this when done. */
76299425Smm	int		  fd;
77299425Smm
78299425Smm	/* Miscellaneous state information */
79299425Smm	int		  argc;
80299425Smm	char		**argv;
81299425Smm	const char	 *argument;
82299425Smm	size_t		  gs_width; /* For 'list_item' in read.c */
83299425Smm	size_t		  u_width; /* for 'list_item' in read.c */
84299425Smm	uid_t		  user_uid; /* UID running this program */
85358090Smm	int		  return_value; /* Value returned by main() */
86358090Smm	char		  warned_lead_slash; /* Already displayed warning */
87358090Smm	char		  next_line_is_dir; /* Used for -C parsing in -cT */
88358090Smm
89358090Smm	/*
90358090Smm	 * Data for various subsystems.  Full definitions are located in
91358090Smm	 * the file where they are used.
92358090Smm	 */
93358090Smm	struct archive		*diskreader;	/* for write.c */
94358090Smm	struct archive_entry_linkresolver *resolver; /* for write.c */
95358090Smm	struct archive_dir	*archive_dir;	/* for write.c */
96358090Smm	struct name_cache	*gname_cache;	/* for write.c */
97358090Smm	char			*buff;		/* for write.c */
98358090Smm	size_t			 buff_size;	/* for write.c */
99358090Smm	int			 first_fs;	/* for write.c */
100358090Smm	struct archive		*matching;	/* for matching.c */
101358090Smm	struct security		*security;	/* for read.c */
102299425Smm	struct name_cache	*uname_cache;	/* for write.c */
103299425Smm	struct siginfo_data	*siginfo;	/* for siginfo.c */
104299425Smm	struct substitution	*substitution;	/* for subst.c */
105299425Smm	char			*ppbuff;	/* for util.c */
106299425Smm};
107368708Smm
108299425Smm/* Options for flags bitfield */
109299425Smm#define	OPTFLAG_AUTO_COMPRESS	(0x00000001)	/* -a */
110368708Smm#define	OPTFLAG_ABSOLUTE_PATHS	(0x00000002)	/* -P */
111299425Smm#define	OPTFLAG_CHROOT		(0x00000004)	/* --chroot */
112368708Smm#define	OPTFLAG_FAST_READ	(0x00000008)	/* --fast-read */
113368708Smm#define	OPTFLAG_IGNORE_ZEROS	(0x00000010)	/* --ignore-zeros */
114368708Smm#define	OPTFLAG_INTERACTIVE	(0x00000020)	/* -w */
115368708Smm#define	OPTFLAG_NO_OWNER	(0x00000040)	/* -o */
116368708Smm#define	OPTFLAG_NO_SUBDIRS	(0x00000080)	/* -n */
117368708Smm#define	OPTFLAG_NULL		(0x00000100)	/* --null */
118368708Smm#define	OPTFLAG_NUMERIC_OWNER	(0x00000200)	/* --numeric-owner */
119299425Smm#define	OPTFLAG_O		(0x00000400)	/* -o */
120299425Smm#define	OPTFLAG_STDOUT		(0x00000800)	/* -O */
121299425Smm#define	OPTFLAG_TOTALS		(0x00001000)	/* --totals */
122299425Smm#define	OPTFLAG_UNLINK_FIRST	(0x00002000)	/* -U */
123299425Smm#define	OPTFLAG_WARN_LINKS	(0x00004000)	/* --check-links */
124299425Smm#define	OPTFLAG_NO_XATTRS	(0x00008000)	/* --no-xattrs */
125299425Smm#define	OPTFLAG_XATTRS		(0x00010000)	/* --xattrs */
126299425Smm#define	OPTFLAG_NO_ACLS		(0x00020000)	/* --no-acls */
127311042Smm#define	OPTFLAG_ACLS		(0x00040000)	/* --acls */
128299425Smm#define	OPTFLAG_NO_FFLAGS	(0x00080000)	/* --no-fflags */
129299425Smm#define	OPTFLAG_FFLAGS		(0x00100000)	/* --fflags */
130299425Smm#define	OPTFLAG_NO_MAC_METADATA	(0x00200000)	/* --no-mac-metadata */
131299425Smm#define	OPTFLAG_MAC_METADATA	(0x00400000)	/* --mac-metadata */
132311042Smm
133299425Smm/* Fake short equivalents for long options that otherwise lack them. */
134299425Smmenum {
135299425Smm	OPTION_ACLS = 1,
136299425Smm	OPTION_B64ENCODE,
137299425Smm	OPTION_CHECK_LINKS,
138299425Smm	OPTION_CHROOT,
139299425Smm	OPTION_CLEAR_NOCHANGE_FFLAGS,
140299425Smm	OPTION_EXCLUDE,
141299425Smm	OPTION_EXCLUDE_VCS,
142299425Smm	OPTION_FFLAGS,
143299425Smm	OPTION_FORMAT,
144299425Smm	OPTION_GID,
145299425Smm	OPTION_GNAME,
146299425Smm	OPTION_GRZIP,
147299425Smm	OPTION_HELP,
148299425Smm	OPTION_HFS_COMPRESSION,
149299425Smm	OPTION_IGNORE_ZEROS,
150299425Smm	OPTION_INCLUDE,
151299425Smm	OPTION_KEEP_NEWER_FILES,
152299425Smm	OPTION_LRZIP,
153299425Smm	OPTION_LZ4,
154299425Smm	OPTION_LZIP,
155299425Smm	OPTION_LZMA,
156299425Smm	OPTION_LZOP,
157299425Smm	OPTION_MAC_METADATA,
158299425Smm	OPTION_NEWER_CTIME,
159299425Smm	OPTION_NEWER_CTIME_THAN,
160299425Smm	OPTION_NEWER_MTIME,
161299425Smm	OPTION_NEWER_MTIME_THAN,
162299425Smm	OPTION_NODUMP,
163299425Smm	OPTION_NOPRESERVE_HFS_COMPRESSION,
164299425Smm	OPTION_NO_ACLS,
165299425Smm	OPTION_NO_FFLAGS,
166299425Smm	OPTION_NO_MAC_METADATA,
167299425Smm	OPTION_NO_SAFE_WRITES,
168299425Smm	OPTION_NO_SAME_OWNER,
169299425Smm	OPTION_NO_SAME_PERMISSIONS,
170299425Smm	OPTION_NO_XATTRS,
171299425Smm	OPTION_NULL,
172299425Smm	OPTION_NUMERIC_OWNER,
173299425Smm	OPTION_OLDER_CTIME,
174299425Smm	OPTION_OLDER_CTIME_THAN,
175299425Smm	OPTION_OLDER_MTIME,
176299425Smm	OPTION_OLDER_MTIME_THAN,
177299425Smm	OPTION_ONE_FILE_SYSTEM,
178299425Smm	OPTION_OPTIONS,
179299425Smm	OPTION_PASSPHRASE,
180299425Smm	OPTION_POSIX,
181299425Smm	OPTION_SAFE_WRITES,
182299425Smm	OPTION_SAME_OWNER,
183299425Smm	OPTION_STRIP_COMPONENTS,
184299425Smm	OPTION_TOTALS,
185299425Smm	OPTION_UID,
186299425Smm	OPTION_UNAME,
187299425Smm	OPTION_USE_COMPRESS_PROGRAM,
188299425Smm	OPTION_UUENCODE,
189	OPTION_VERSION,
190	OPTION_XATTRS,
191	OPTION_ZSTD,
192};
193
194int	bsdtar_getopt(struct bsdtar *);
195void	do_chdir(struct bsdtar *);
196int	edit_pathname(struct bsdtar *, struct archive_entry *);
197int	need_report(void);
198int	pathcmp(const char *a, const char *b);
199void	safe_fprintf(FILE *, const char *fmt, ...) __LA_PRINTF(2, 3);
200void	set_chdir(struct bsdtar *, const char *newdir);
201const char *tar_i64toa(int64_t);
202void	tar_mode_c(struct bsdtar *bsdtar);
203void	tar_mode_r(struct bsdtar *bsdtar);
204void	tar_mode_t(struct bsdtar *bsdtar);
205void	tar_mode_u(struct bsdtar *bsdtar);
206void	tar_mode_x(struct bsdtar *bsdtar);
207void	usage(void) __LA_DEAD;
208int	yes(const char *fmt, ...) __LA_PRINTF(1, 2);
209
210#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H)
211void	add_substitution(struct bsdtar *, const char *);
212int	apply_substitution(struct bsdtar *, const char *, char **, int, int);
213void	cleanup_substitution(struct bsdtar *);
214#endif
215
216void		cset_add_filter(struct creation_set *, const char *);
217void		cset_add_filter_program(struct creation_set *, const char *);
218int		cset_auto_compress(struct creation_set *, const char *);
219void		cset_free(struct creation_set *);
220const char *	cset_get_format(struct creation_set *);
221struct creation_set *cset_new(void);
222int		cset_read_support_filter_program(struct creation_set *,
223		    struct archive *);
224void		cset_set_format(struct creation_set *, const char *);
225int		cset_write_add_filters(struct creation_set *,
226		    struct archive *, const void **);
227
228const char * passphrase_callback(struct archive *, void *);
229void	     passphrase_free(char *);
230void	list_item_verbose(struct bsdtar *, FILE *,
231		    struct archive_entry *);
232
233#endif
234