Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/freebsd-src
Path: blob/main/contrib/libarchive/tar/bsdtar.h
39483 views
1
/*-
2
* SPDX-License-Identifier: BSD-2-Clause
3
*
4
* Copyright (c) 2003-2007 Tim Kientzle
5
* All rights reserved.
6
*/
7
8
#ifndef BSDTAR_H_INCLUDED
9
#define BSDTAR_H_INCLUDED
10
11
#include "bsdtar_platform.h"
12
#include <stdio.h>
13
14
#define DEFAULT_BYTES_PER_BLOCK (20*512)
15
#define ENV_READER_OPTIONS "TAR_READER_OPTIONS"
16
#define ENV_WRITER_OPTIONS "TAR_WRITER_OPTIONS"
17
#define IGNORE_WRONG_MODULE_NAME "__ignore_wrong_module_name__,"
18
19
struct creation_set;
20
/*
21
* The internal state for the "bsdtar" program.
22
*
23
* Keeping all of the state in a structure like this simplifies memory
24
* leak testing (at exit, anything left on the heap is suspect). A
25
* pointer to this structure is passed to most bsdtar internal
26
* functions.
27
*/
28
struct bsdtar {
29
/* Options */
30
const char *filename; /* -f filename */
31
char *pending_chdir; /* -C dir */
32
const char *names_from_file; /* -T file */
33
int bytes_per_block; /* -b block_size */
34
int bytes_in_last_block; /* See -b handling. */
35
int verbose; /* -v */
36
unsigned int flags; /* Bitfield of boolean options */
37
int extract_flags; /* Flags for extract operation */
38
int readdisk_flags; /* Flags for read disk operation */
39
int strip_components; /* Remove this many leading dirs */
40
int gid; /* --gid */
41
const char *gname; /* --gname */
42
int uid; /* --uid */
43
const char *uname; /* --uname */
44
const char *passphrase; /* --passphrase */
45
int mode; /* Program mode: 'c', 't', 'r', 'u', 'x' */
46
char symlink_mode; /* H or L, per BSD conventions */
47
const char *option_options; /* --options */
48
char day_first; /* show day before month in -tv output */
49
char has_mtime; /* --mtime exists (0 or 1) */
50
char clamp_mtime; /* --clamp-mtime (0 or 1)*/
51
time_t mtime; /* --mtime */
52
struct creation_set *cset;
53
54
/* Option parser state */
55
int getopt_state;
56
char *getopt_word;
57
58
/* If >= 0, then close this when done. */
59
int fd;
60
61
/* Miscellaneous state information */
62
int argc;
63
char **argv;
64
const char *argument;
65
size_t gs_width; /* For 'list_item' in read.c */
66
size_t u_width; /* for 'list_item' in read.c */
67
uid_t user_uid; /* UID running this program */
68
int return_value; /* Value returned by main() */
69
char warned_lead_slash; /* Already displayed warning */
70
char next_line_is_dir; /* Used for -C parsing in -cT */
71
72
/*
73
* Data for various subsystems. Full definitions are located in
74
* the file where they are used.
75
*/
76
struct archive *diskreader; /* for write.c */
77
struct archive_entry_linkresolver *resolver; /* for write.c */
78
struct archive_dir *archive_dir; /* for write.c */
79
struct name_cache *gname_cache; /* for write.c */
80
char *buff; /* for write.c */
81
size_t buff_size; /* for write.c */
82
int first_fs; /* for write.c */
83
struct archive *matching; /* for matching.c */
84
struct security *security; /* for read.c */
85
struct name_cache *uname_cache; /* for write.c */
86
struct siginfo_data *siginfo; /* for siginfo.c */
87
struct substitution *substitution; /* for subst.c */
88
char *ppbuff; /* for util.c */
89
};
90
91
/* Options for flags bitfield */
92
#define OPTFLAG_AUTO_COMPRESS (0x00000001) /* -a */
93
#define OPTFLAG_ABSOLUTE_PATHS (0x00000002) /* -P */
94
#define OPTFLAG_CHROOT (0x00000004) /* --chroot */
95
#define OPTFLAG_FAST_READ (0x00000008) /* --fast-read */
96
#define OPTFLAG_IGNORE_ZEROS (0x00000010) /* --ignore-zeros */
97
#define OPTFLAG_INTERACTIVE (0x00000020) /* -w */
98
#define OPTFLAG_NO_OWNER (0x00000040) /* -o */
99
#define OPTFLAG_NO_SUBDIRS (0x00000080) /* -n */
100
#define OPTFLAG_NULL (0x00000100) /* --null */
101
#define OPTFLAG_NUMERIC_OWNER (0x00000200) /* --numeric-owner */
102
#define OPTFLAG_O (0x00000400) /* -o */
103
#define OPTFLAG_STDOUT (0x00000800) /* -O */
104
#define OPTFLAG_TOTALS (0x00001000) /* --totals */
105
#define OPTFLAG_UNLINK_FIRST (0x00002000) /* -U */
106
#define OPTFLAG_WARN_LINKS (0x00004000) /* --check-links */
107
#define OPTFLAG_NO_XATTRS (0x00008000) /* --no-xattrs */
108
#define OPTFLAG_XATTRS (0x00010000) /* --xattrs */
109
#define OPTFLAG_NO_ACLS (0x00020000) /* --no-acls */
110
#define OPTFLAG_ACLS (0x00040000) /* --acls */
111
#define OPTFLAG_NO_FFLAGS (0x00080000) /* --no-fflags */
112
#define OPTFLAG_FFLAGS (0x00100000) /* --fflags */
113
#define OPTFLAG_NO_MAC_METADATA (0x00200000) /* --no-mac-metadata */
114
#define OPTFLAG_MAC_METADATA (0x00400000) /* --mac-metadata */
115
#define OPTFLAG_NO_READ_SPARSE (0x00800000) /* --no-read-sparse */
116
#define OPTFLAG_READ_SPARSE (0x01000000) /* --read-sparse */
117
118
/* Fake short equivalents for long options that otherwise lack them. */
119
enum {
120
OPTION_ACLS = 256,
121
OPTION_B64ENCODE,
122
OPTION_CHECK_LINKS,
123
OPTION_CHROOT,
124
OPTION_CLEAR_NOCHANGE_FFLAGS,
125
OPTION_EXCLUDE,
126
OPTION_EXCLUDE_VCS,
127
OPTION_FFLAGS,
128
OPTION_FORMAT,
129
OPTION_GID,
130
OPTION_GNAME,
131
OPTION_GROUP,
132
OPTION_GRZIP,
133
OPTION_HELP,
134
OPTION_HFS_COMPRESSION,
135
OPTION_IGNORE_ZEROS,
136
OPTION_INCLUDE,
137
OPTION_KEEP_NEWER_FILES,
138
OPTION_LRZIP,
139
OPTION_LZ4,
140
OPTION_LZIP,
141
OPTION_LZMA,
142
OPTION_LZOP,
143
OPTION_MAC_METADATA,
144
OPTION_NEWER_CTIME,
145
OPTION_NEWER_CTIME_THAN,
146
OPTION_NEWER_MTIME,
147
OPTION_NEWER_MTIME_THAN,
148
OPTION_NODUMP,
149
OPTION_NOPRESERVE_HFS_COMPRESSION,
150
OPTION_NO_ACLS,
151
OPTION_NO_FFLAGS,
152
OPTION_NO_MAC_METADATA,
153
OPTION_NO_READ_SPARSE,
154
OPTION_NO_SAFE_WRITES,
155
OPTION_NO_SAME_OWNER,
156
OPTION_NO_SAME_PERMISSIONS,
157
OPTION_NO_XATTRS,
158
OPTION_NULL,
159
OPTION_NUMERIC_OWNER,
160
OPTION_OLDER_CTIME,
161
OPTION_OLDER_CTIME_THAN,
162
OPTION_OLDER_MTIME,
163
OPTION_OLDER_MTIME_THAN,
164
OPTION_ONE_FILE_SYSTEM,
165
OPTION_OPTIONS,
166
OPTION_OWNER,
167
OPTION_PASSPHRASE,
168
OPTION_POSIX,
169
OPTION_READ_SPARSE,
170
OPTION_SAFE_WRITES,
171
OPTION_SAME_OWNER,
172
OPTION_STRIP_COMPONENTS,
173
OPTION_TOTALS,
174
OPTION_UID,
175
OPTION_UNAME,
176
OPTION_USE_COMPRESS_PROGRAM,
177
OPTION_UUENCODE,
178
OPTION_VERSION,
179
OPTION_XATTRS,
180
OPTION_ZSTD,
181
OPTION_MTIME,
182
OPTION_CLAMP_MTIME,
183
};
184
185
int bsdtar_getopt(struct bsdtar *);
186
void do_chdir(struct bsdtar *);
187
int edit_pathname(struct bsdtar *, struct archive_entry *);
188
void edit_mtime(struct bsdtar *, struct archive_entry *);
189
int need_report(void);
190
int pathcmp(const char *a, const char *b);
191
void safe_fprintf(FILE * restrict, const char * restrict fmt, ...) __LA_PRINTF(2, 3);
192
void set_chdir(struct bsdtar *, const char *newdir);
193
const char *tar_i64toa(int64_t);
194
void tar_mode_c(struct bsdtar *bsdtar);
195
void tar_mode_r(struct bsdtar *bsdtar);
196
void tar_mode_t(struct bsdtar *bsdtar);
197
void tar_mode_u(struct bsdtar *bsdtar);
198
void tar_mode_x(struct bsdtar *bsdtar);
199
__LA_NORETURN void usage(void);
200
int yes(const char *fmt, ...) __LA_PRINTF(1, 2);
201
202
#if defined(HAVE_REGEX_H) || defined(HAVE_PCREPOSIX_H) || defined(HAVE_PCRE2POSIX_H)
203
void add_substitution(struct bsdtar *, const char *);
204
int apply_substitution(struct bsdtar *, const char *, char **, int, int);
205
void cleanup_substitution(struct bsdtar *);
206
#endif
207
208
void cset_add_filter(struct creation_set *, const char *);
209
void cset_add_filter_program(struct creation_set *, const char *);
210
int cset_auto_compress(struct creation_set *, const char *);
211
void cset_free(struct creation_set *);
212
const char * cset_get_format(struct creation_set *);
213
struct creation_set *cset_new(void);
214
int cset_read_support_filter_program(struct creation_set *,
215
struct archive *);
216
void cset_set_format(struct creation_set *, const char *);
217
int cset_write_add_filters(struct creation_set *,
218
struct archive *, const void **);
219
220
const char * passphrase_callback(struct archive *, void *);
221
void passphrase_free(char *);
222
void list_item_verbose(struct bsdtar *, FILE *,
223
struct archive_entry *);
224
225
#endif
226
227