]> Dogcows Code - chaz/tar/blob - src/common.h
(print_header): Revised
[chaz/tar] / src / common.h
1 /* Common declarations for the tar program.
2 Copyright (C) 1988, 92, 93, 94, 96, 97 Free Software Foundation, Inc.
3
4 This program is free software; you can redistribute it and/or modify it
5 under the terms of the GNU General Public License as published by the
6 Free Software Foundation; either version 2, or (at your option) any later
7 version.
8
9 This program is distributed in the hope that it will be useful, but
10 WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
12 Public License for more details.
13
14 You should have received a copy of the GNU General Public License along
15 with this program; if not, write to the Free Software Foundation, Inc.,
16 59 Place - Suite 330, Boston, MA 02111-1307, USA. */
17
18 /* Declare the GNU tar archive format. */
19 #include "tar.h"
20
21 /* The checksum field is filled with this while the checksum is computed. */
22 #define CHKBLANKS " " /* 8 blanks, no null */
23
24 /* Some constants from POSIX are given names. */
25 #define NAME_FIELD_SIZE 100
26 #define PREFIX_FIELD_SIZE 155
27 #define UNAME_FIELD_SIZE 32
28 #define GNAME_FIELD_SIZE 32
29
30 /* POSIX specified symbols currently unused are undefined here. */
31 #undef TSUID
32 #undef TSGID
33 #undef TSVTX
34 #undef TUREAD
35 #undef TUWRITE
36 #undef TUEXEC
37 #undef TGREAD
38 #undef TGWRITE
39 #undef TGEXEC
40 #undef TOREAD
41 #undef TOWRITE
42 #undef TOEXEC
43 \f
44 /* Some various global definitions. */
45
46 /* Name of file to use for interacting with user. */
47 #if MSDOS
48 # define TTY_NAME "con"
49 #else
50 # define TTY_NAME "/dev/tty"
51 #endif
52
53 /* GLOBAL is defined to empty in `tar.c' only, and left alone in other `*.c'
54 modules. Here, we merely set it to "extern" if it is not already set.
55 GNU tar does depend on the system loader to preset all GLOBAL variables to
56 neutral (or zero) values, explicit initialisation is usually not done. */
57 #ifndef GLOBAL
58 # define GLOBAL extern
59 #endif
60
61 /* Exit status for GNU tar. Let's try to keep this list as simple as
62 possible. -d option strongly invites a status different for unequal
63 comparison and other errors. */
64 GLOBAL int exit_status;
65
66 #define TAREXIT_SUCCESS 0
67 #define TAREXIT_DIFFERS 1
68 #define TAREXIT_FAILURE 2
69
70 /* Both WARN and ERROR write a message on stderr and continue processing,
71 however ERROR manages so tar will exit unsuccessfully. FATAL_ERROR
72 writes a message on stderr and aborts immediately, with another message
73 line telling so. USAGE_ERROR works like FATAL_ERROR except that the
74 other message line suggests trying --help. All four macros accept a
75 single argument of the form ((0, errno, _("FORMAT"), Args...)). `errno'
76 is `0' when the error is not being detected by the system. */
77
78 #define WARN(Args) \
79 error Args
80 #define ERROR(Args) \
81 (error Args, exit_status = TAREXIT_FAILURE)
82 #define FATAL_ERROR(Args) \
83 (error Args, error (TAREXIT_FAILURE, 0, \
84 _("Error is not recoverable: exiting now")), 0)
85 #define USAGE_ERROR(Args) \
86 (error Args, usage (TAREXIT_FAILURE), 0)
87 \f
88 /* Information gleaned from the command line. */
89
90 #include "arith.h"
91 #include "modechange.h"
92
93 /* Name of this program. */
94 GLOBAL const char *program_name;
95
96 /* Main command option. */
97
98 enum subcommand
99 {
100 UNKNOWN_SUBCOMMAND, /* none of the following */
101 APPEND_SUBCOMMAND, /* -r */
102 CAT_SUBCOMMAND, /* -A */
103 CREATE_SUBCOMMAND, /* -c */
104 DELETE_SUBCOMMAND, /* -D */
105 DIFF_SUBCOMMAND, /* -d */
106 EXTRACT_SUBCOMMAND, /* -x */
107 LIST_SUBCOMMAND, /* -t */
108 UPDATE_SUBCOMMAND /* -u */
109 };
110
111 GLOBAL enum subcommand subcommand_option;
112
113 /* Selected format for output archive. */
114 GLOBAL enum archive_format archive_format;
115
116 /* Either NL or NUL, as decided by the --null option. */
117 GLOBAL char filename_terminator;
118
119 /* Size of each record, once in blocks, once in bytes. Those two variables
120 are always related, the second being BLOCKSIZE times the first. They do
121 not have _option in their name, even if their values is derived from
122 option decoding, as these are especially important in tar. */
123 GLOBAL int blocking_factor;
124 GLOBAL int record_size;
125
126 /* Boolean value. */
127 GLOBAL int absolute_names_option;
128
129 /* This variable tells how to interpret newer_mtime_option, below. If zero,
130 files get archived if their mtime is not less than newer_mtime_option.
131 If nonzero, files get archived if *either* their ctime or mtime is not less
132 than newer_mtime_option. */
133 GLOBAL int after_date_option;
134
135 /* Boolean value. */
136 GLOBAL int atime_preserve_option;
137
138 /* Boolean value. */
139 GLOBAL int backup_option;
140
141 /* Boolean value. */
142 GLOBAL int block_number_option;
143
144 /* Boolean value. */
145 GLOBAL int checkpoint_option;
146
147 /* Specified name of compression program, or "gzip" as implied by -z. */
148 GLOBAL const char *use_compress_program_option;
149
150 /* Boolean value. */
151 GLOBAL int dereference_option;
152
153 /* Boolean value. */
154 GLOBAL int exclude_option;
155
156 /* Specified file containing names to work on. */
157 GLOBAL const char *files_from_option;
158
159 /* Boolean value. */
160 GLOBAL int force_local_option;
161
162 /* Specified value to be put into tar file in place of stat () results, or
163 just -1 if such an override should not take place. */
164 GLOBAL gid_t group_option;
165
166 /* Boolean value. */
167 GLOBAL int ignore_failed_read_option;
168
169 /* Boolean value. */
170 GLOBAL int ignore_zeros_option;
171
172 /* Boolean value. */
173 GLOBAL int incremental_option;
174
175 /* Specified name of script to run at end of each tape change. */
176 GLOBAL const char *info_script_option;
177
178 /* Boolean value. */
179 GLOBAL int interactive_option;
180
181 /* Boolean value. */
182 GLOBAL int keep_old_files_option;
183
184 /* Specified file name for incremental list. */
185 GLOBAL const char *listed_incremental_option;
186
187 /* Specified mode change string. */
188 GLOBAL struct mode_change *mode_option;
189
190 /* Boolean value. */
191 GLOBAL int multi_volume_option;
192
193 /* The same variable hold the time, whether mtime or ctime. Just fake a
194 non-existing option, for making the code clearer, elsewhere. */
195 #define newer_ctime_option newer_mtime_option
196
197 /* Specified threshold date and time. Files having a more recent timestamp
198 get archived (also see after_date_option above). If left to zero, it may
199 be interpreted as very low threshold, just usable as such. */
200 GLOBAL time_t newer_mtime_option;
201
202 /* Boolean value. */
203 GLOBAL int no_recurse_option;
204
205 /* Boolean value. */
206 GLOBAL int numeric_owner_option;
207
208 /* Boolean value. */
209 GLOBAL int one_file_system_option;
210
211 /* Specified value to be put into tar file in place of stat () results, or
212 just -1 if such an override should not take place. */
213 GLOBAL uid_t owner_option;
214
215 /* Boolean value. */
216 GLOBAL int recursive_unlink_option;
217
218 /* Boolean value. */
219 GLOBAL int read_full_records_option;
220
221 /* Boolean value. */
222 GLOBAL int remove_files_option;
223
224 /* Specified remote shell command. */
225 GLOBAL const char *rsh_command_option;
226
227 /* Boolean value. */
228 GLOBAL int same_order_option;
229
230 /* Boolean value. */
231 GLOBAL int same_owner_option;
232
233 /* Boolean value. */
234 GLOBAL int same_permissions_option;
235
236 /* Boolean value. */
237 GLOBAL int show_omitted_dirs_option;
238
239 /* Boolean value. */
240 GLOBAL int sparse_option;
241
242 /* Boolean value. */
243 GLOBAL int starting_file_option;
244
245 /* Specified maximum byte length of each tape volume (multiple of 1024). */
246 GLOBAL tarlong tape_length_option;
247
248 /* Boolean value. */
249 GLOBAL int to_stdout_option;
250
251 /* Boolean value. */
252 GLOBAL int totals_option;
253
254 /* Boolean value. */
255 GLOBAL int touch_option;
256
257 /* Boolean value. */
258 GLOBAL int unlink_first_option;
259
260 /* Count how many times the option has been set, multiple setting yields
261 more verbose behavior. Value 0 means no verbosity, 1 means file name
262 only, 2 means file name and all attributes. More than 2 is just like 2. */
263 GLOBAL int verbose_option;
264
265 /* Boolean value. */
266 GLOBAL int verify_option;
267
268 /* Specified name of file containing the volume number. */
269 GLOBAL const char *volno_file_option;
270
271 /* Specified value or pattern. */
272 GLOBAL const char *volume_label_option;
273 \f
274 /* Other global variables. */
275
276 /* File descriptor for archive file. */
277 GLOBAL int archive;
278
279 /* Nonzero when outputting to /dev/null. */
280 GLOBAL int dev_null_output;
281
282 /* Name of file for the current archive entry. */
283 GLOBAL char *current_file_name;
284
285 /* Name of link for the current archive entry. */
286 GLOBAL char *current_link_name;
287
288 /* List of tape drive names, number of such tape drives, allocated number,
289 and current cursor in list. */
290 GLOBAL const char **archive_name_array;
291 GLOBAL int archive_names;
292 GLOBAL int allocated_archive_names;
293 GLOBAL const char **archive_name_cursor;
294
295 /* Structure for keeping track of filenames and lists thereof. */
296 struct name
297 {
298 struct name *next;
299 short length; /* cached strlen(name) */
300 char found; /* a matching file has been found */
301 char firstch; /* first char is literally matched */
302 char regexp; /* this name is a regexp, not literal */
303 char *change_dir; /* set with the -C option */
304 char *dir_contents; /* for incremental_option */
305 char fake; /* dummy entry */
306 char name[1];
307 };
308 GLOBAL struct name *namelist; /* points to first name in list */
309 GLOBAL struct name *namelast; /* points to last name in list */
310
311 /* Pointer to the start of the scratch space. */
312 struct sp_array
313 {
314 off_t offset;
315 int numbytes;
316 };
317 GLOBAL struct sp_array *sparsearray;
318
319 /* Initial size of the sparsearray. */
320 GLOBAL int sp_array_size;
321 \f
322 /* Declarations for each module. */
323
324 /* FIXME: compare.c should not directly handle the following variable,
325 instead, this should be done in buffer.c only. */
326
327 enum access_mode
328 {
329 ACCESS_READ,
330 ACCESS_WRITE,
331 ACCESS_UPDATE
332 };
333 extern enum access_mode access_mode;
334
335 /* Module buffer.c. */
336
337 extern FILE *stdlis;
338 extern char *save_name;
339 extern long save_sizeleft;
340 extern long save_totsize;
341 extern int write_archive_to_stdout;
342
343 int available_space_after PARAMS ((union block *));
344 long current_block_ordinal PARAMS ((void));
345 void close_archive PARAMS ((void));
346 void closeout_volume_number PARAMS ((void));
347 union block *find_next_block PARAMS ((void));
348 void flush_read PARAMS ((void));
349 void flush_write PARAMS ((void));
350 void flush_archive PARAMS ((void));
351 void init_total_written PARAMS ((void));
352 void init_volume_number PARAMS ((void));
353 void open_archive PARAMS ((enum access_mode));
354 void print_total_written PARAMS ((void));
355 void reset_eof PARAMS ((void));
356 void set_next_block_after PARAMS ((union block *));
357
358 /* Module create.c. */
359
360 void create_archive PARAMS ((void));
361 void dump_file PARAMS ((char *, int, int));
362 void finish_header PARAMS ((union block *));
363 void to_oct PARAMS ((long, int, char *));
364 void write_eot PARAMS ((void));
365
366 /* Module diffarch.c. */
367
368 extern int now_verifying;
369
370 void diff_archive PARAMS ((void));
371 void diff_init PARAMS ((void));
372 void verify_volume PARAMS ((void));
373
374 /* Module extract.c. */
375
376 void extr_init PARAMS ((void));
377 void extract_archive PARAMS ((void));
378 void apply_delayed_set_stat PARAMS ((void));
379
380 /* Module delete.c. */
381
382 void delete_archive_members PARAMS ((void));
383
384 /* Module incremen.c. */
385
386 void collect_and_sort_names PARAMS ((void));
387 char *get_directory_contents PARAMS ((char *, int));
388 void write_dir_file PARAMS ((void));
389 void gnu_restore PARAMS ((int));
390 void write_directory_file PARAMS ((void));
391
392 /* Module list.c. */
393
394 enum read_header
395 {
396 HEADER_STILL_UNREAD, /* for when read_header has not been called */
397 HEADER_SUCCESS, /* header successfully read and checksummed */
398 HEADER_ZERO_BLOCK, /* zero block where header expected */
399 HEADER_END_OF_FILE, /* true end of file while header expected */
400 HEADER_FAILURE /* ill-formed header, or bad checksum */
401 };
402
403 extern union block *current_header;
404 extern struct stat current_stat;
405 extern enum archive_format current_format;
406
407 void decode_header PARAMS ((union block *, struct stat *,
408 enum archive_format *, int));
409 long from_oct PARAMS ((int, char *));
410 void list_archive PARAMS ((void));
411 void print_for_mkdir PARAMS ((char *, int, int));
412 void print_header PARAMS ((void));
413 void read_and PARAMS ((void (*do_) ()));
414 enum read_header read_header PARAMS ((void));
415 void skip_extended_headers PARAMS ((void));
416 void skip_file PARAMS ((long));
417
418 /* Module mangle.c. */
419
420 void extract_mangle PARAMS ((void));
421
422 /* Module misc.c. */
423
424 void assign_string PARAMS ((char **, const char *));
425 char *quote_copy_string PARAMS ((const char *));
426 int unquote_string PARAMS ((char *));
427
428 char *merge_sort PARAMS ((char *, int, int, int (*) (char *, char *)));
429
430 int is_dot_or_dotdot PARAMS ((const char *));
431 int remove_any_file PARAMS ((const char *, int));
432 int maybe_backup_file PARAMS ((const char *, int));
433 void undo_last_backup PARAMS ((void));
434
435 /* Module names.c. */
436
437 void gid_to_gname PARAMS ((gid_t, char gname[GNAME_FIELD_SIZE]));
438 int gname_to_gid PARAMS ((char gname[GNAME_FIELD_SIZE], gid_t *));
439 void uid_to_uname PARAMS ((uid_t, char uname[UNAME_FIELD_SIZE]));
440 int uname_to_uid PARAMS ((char uname[UNAME_FIELD_SIZE], uid_t *));
441
442 void init_names PARAMS ((void));
443 void name_add PARAMS ((const char *));
444 void name_init PARAMS ((int, char *const *));
445 void name_term PARAMS ((void));
446 char *name_next PARAMS ((int change_));
447 void name_close PARAMS ((void));
448 void name_gather PARAMS ((void));
449 void addname PARAMS ((const char *));
450 int name_match PARAMS ((const char *));
451 void names_notfound PARAMS ((void));
452 void name_expand PARAMS ((void));
453 struct name *name_scan PARAMS ((const char *));
454 char *name_from_list PARAMS ((void));
455 void blank_name_list PARAMS ((void));
456 char *new_name PARAMS ((const char *, const char *));
457
458 void add_exclude PARAMS ((char *));
459 void add_exclude_file PARAMS ((const char *));
460 int check_exclude PARAMS ((const char *));
461
462 /* Module tar.c. */
463
464 int confirm PARAMS ((const char *, const char *));
465 void request_stdin PARAMS ((const char *));
466
467 /* Module update.c. */
468
469 extern char *output_start;
470
471 void update_archive PARAMS ((void));
This page took 0.052963 seconds and 4 git commands to generate.