xref: /dragonfly/contrib/libarchive/tar/bsdtar.h (revision 9f3fc534)
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: src/usr.bin/tar/bsdtar.h,v 1.33 2008/05/26 17:10:10 kientzle Exp $
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  */
41 struct 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 	time_t		  newer_ctime_sec; /* --newer/--newer-than */
48 	long		  newer_ctime_nsec; /* --newer/--newer-than */
49 	time_t		  newer_mtime_sec; /* --newer-mtime */
50 	long		  newer_mtime_nsec; /* --newer-mtime-than */
51 	int		  bytes_per_block; /* -b block_size */
52 	int		  verbose;   /* -v */
53 	int		  extract_flags; /* Flags for extract operation */
54 	int		  strip_components; /* Remove this many leading dirs */
55 	char		  mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
56 	char		  symlink_mode; /* H or L, per BSD conventions */
57 	char		  create_compression; /* j, y, or z */
58 	const char	 *compress_program;
59 	char		  option_absolute_paths; /* -P */
60 	char		  option_chroot; /* --chroot */
61 	char		  option_dont_traverse_mounts; /* --one-file-system */
62 	char		  option_fast_read; /* --fast-read */
63 	char		  option_honor_nodump; /* --nodump */
64 	char		  option_interactive; /* -w */
65 	char		  option_no_owner; /* -o */
66 	char		  option_no_subdirs; /* -n */
67 	char		  option_null; /* --null */
68 	char		  option_numeric_owner; /* --numeric-owner */
69 	char		  option_stdout; /* -O */
70 	char		  option_totals; /* --totals */
71 	char		  option_unlink_first; /* -U */
72 	char		  option_warn_links; /* --check-links */
73 	char		  day_first; /* show day before month in -tv output */
74 
75 	/* If >= 0, then close this when done. */
76 	int		  fd;
77 
78 	/* Miscellaneous state information */
79 	struct archive	 *archive;
80 	const char	 *progname;
81 	int		  argc;
82 	char		**argv;
83 	size_t		  gs_width; /* For 'list_item' in read.c */
84 	size_t		  u_width; /* for 'list_item' in read.c */
85 	uid_t		  user_uid; /* UID running this program */
86 	int		  return_value; /* Value returned by main() */
87 	char		  warned_lead_slash; /* Already displayed warning */
88 	char		  next_line_is_dir; /* Used for -C parsing in -cT */
89 
90 	/*
91 	 * Data for various subsystems.  Full definitions are located in
92 	 * the file where they are used.
93 	 */
94 	struct archive_entry_linkresolver *resolver;
95 	struct archive_dir	*archive_dir;	/* for write.c */
96 	struct name_cache	*gname_cache;	/* for write.c */
97 	struct matching		*matching;	/* for matching.c */
98 	struct security		*security;	/* for read.c */
99 	struct name_cache	*uname_cache;	/* for write.c */
100 	struct siginfo_data	*siginfo;	/* for siginfo.c */
101 	struct substitution	*substitution;	/* for subst.c */
102 };
103 
104 void	bsdtar_errc(struct bsdtar *, int _eval, int _code,
105 	    const char *fmt, ...);
106 void	bsdtar_warnc(struct bsdtar *, int _code, const char *fmt, ...);
107 void	cleanup_exclusions(struct bsdtar *);
108 void	do_chdir(struct bsdtar *);
109 int	edit_pathname(struct bsdtar *, struct archive_entry *);
110 int	exclude(struct bsdtar *, const char *pattern);
111 int	exclude_from_file(struct bsdtar *, const char *pathname);
112 int	excluded(struct bsdtar *, const char *pathname);
113 int	include(struct bsdtar *, const char *pattern);
114 int	include_from_file(struct bsdtar *, const char *pathname);
115 int	pathcmp(const char *a, const char *b);
116 int	process_lines(struct bsdtar *bsdtar, const char *pathname,
117 	    int (*process)(struct bsdtar *, const char *));
118 void	safe_fprintf(FILE *, const char *fmt, ...);
119 void	set_chdir(struct bsdtar *, const char *newdir);
120 void	siginfo_init(struct bsdtar *);
121 void	siginfo_setinfo(struct bsdtar *, const char * oper,
122 	    const char * path, int64_t size);
123 void	siginfo_printinfo(struct bsdtar *, off_t progress);
124 void	siginfo_done(struct bsdtar *);
125 void	tar_mode_c(struct bsdtar *bsdtar);
126 void	tar_mode_r(struct bsdtar *bsdtar);
127 void	tar_mode_t(struct bsdtar *bsdtar);
128 void	tar_mode_u(struct bsdtar *bsdtar);
129 void	tar_mode_x(struct bsdtar *bsdtar);
130 int	unmatched_inclusions(struct bsdtar *bsdtar);
131 int	unmatched_inclusions_warn(struct bsdtar *bsdtar, const char *msg);
132 void	usage(struct bsdtar *);
133 int	yes(const char *fmt, ...);
134 
135 #if HAVE_REGEX_H
136 void	add_substitution(struct bsdtar *, const char *);
137 int	apply_substitution(struct bsdtar *, const char *, char **, int);
138 void	cleanup_substitution(struct bsdtar *);
139 #endif
140