1 /* Common declarations for the tar program.
2 Copyright (C) 1988, 92, 93, 94, 96, 97 Free Software Foundation, Inc.
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
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.
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. */
18 /* Declare the GNU tar archive format. */
21 /* The checksum field is filled with this while the checksum is computed. */
22 #define CHKBLANKS " " /* 8 blanks, no null */
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
30 /* POSIX specified symbols currently unused are undefined here. */
44 /* Some various global definitions. */
46 /* Name of file to use for interacting with user. */
48 # define TTY_NAME "con"
50 # define TTY_NAME "/dev/tty"
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. */
58 # define GLOBAL extern
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
;
66 #define TAREXIT_SUCCESS 0
67 #define TAREXIT_DIFFERS 1
68 #define TAREXIT_FAILURE 2
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. */
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)
88 /* Information gleaned from the command line. */
91 #include "modechange.h"
93 /* Name of this program. */
94 GLOBAL
const char *program_name
;
96 /* Main command option. */
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 */
111 GLOBAL
enum subcommand subcommand_option
;
113 /* Selected format for output archive. */
114 GLOBAL
enum archive_format archive_format
;
116 /* Either NL or NUL, as decided by the --null option. */
117 GLOBAL
char filename_terminator
;
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
;
127 GLOBAL
int absolute_names_option
;
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
;
136 GLOBAL
int atime_preserve_option
;
139 GLOBAL
int backup_option
;
142 GLOBAL
int block_number_option
;
145 GLOBAL
int checkpoint_option
;
147 /* Specified name of compression program, or "gzip" as implied by -z. */
148 GLOBAL
const char *use_compress_program_option
;
151 GLOBAL
int dereference_option
;
154 GLOBAL
int exclude_option
;
156 /* Specified file containing names to work on. */
157 GLOBAL
const char *files_from_option
;
160 GLOBAL
int force_local_option
;
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
;
167 GLOBAL
int ignore_failed_read_option
;
170 GLOBAL
int ignore_zeros_option
;
173 GLOBAL
int incremental_option
;
175 /* Specified name of script to run at end of each tape change. */
176 GLOBAL
const char *info_script_option
;
179 GLOBAL
int interactive_option
;
182 GLOBAL
int keep_old_files_option
;
184 /* Specified file name for incremental list. */
185 GLOBAL
const char *listed_incremental_option
;
187 /* Specified mode change string. */
188 GLOBAL
struct mode_change
*mode_option
;
191 GLOBAL
int multi_volume_option
;
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
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
;
203 GLOBAL
int no_recurse_option
;
206 GLOBAL
int numeric_owner_option
;
209 GLOBAL
int one_file_system_option
;
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
;
216 GLOBAL
int recursive_unlink_option
;
219 GLOBAL
int read_full_records_option
;
222 GLOBAL
int remove_files_option
;
224 /* Specified remote shell command. */
225 GLOBAL
const char *rsh_command_option
;
228 GLOBAL
int same_order_option
;
231 GLOBAL
int same_owner_option
;
234 GLOBAL
int same_permissions_option
;
237 GLOBAL
int show_omitted_dirs_option
;
240 GLOBAL
int sparse_option
;
243 GLOBAL
int starting_file_option
;
245 /* Specified maximum byte length of each tape volume (multiple of 1024). */
246 GLOBAL tarlong tape_length_option
;
249 GLOBAL
int to_stdout_option
;
252 GLOBAL
int totals_option
;
255 GLOBAL
int touch_option
;
258 GLOBAL
int unlink_first_option
;
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
;
266 GLOBAL
int verify_option
;
268 /* Specified name of file containing the volume number. */
269 GLOBAL
const char *volno_file_option
;
271 /* Specified value or pattern. */
272 GLOBAL
const char *volume_label_option
;
274 /* Other global variables. */
276 /* File descriptor for archive file. */
279 /* Nonzero when outputting to /dev/null. */
280 GLOBAL
int dev_null_output
;
282 /* Name of file for the current archive entry. */
283 GLOBAL
char *current_file_name
;
285 /* Name of link for the current archive entry. */
286 GLOBAL
char *current_link_name
;
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
;
295 /* Structure for keeping track of filenames and lists thereof. */
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 */
308 GLOBAL
struct name
*namelist
; /* points to first name in list */
309 GLOBAL
struct name
*namelast
; /* points to last name in list */
311 /* Pointer to the start of the scratch space. */
317 GLOBAL
struct sp_array
*sparsearray
;
319 /* Initial size of the sparsearray. */
320 GLOBAL
int sp_array_size
;
322 /* Declarations for each module. */
324 /* FIXME: compare.c should not directly handle the following variable,
325 instead, this should be done in buffer.c only. */
333 extern enum access_mode access_mode
;
335 /* Module buffer.c. */
338 extern char *save_name
;
339 extern long save_sizeleft
;
340 extern long save_totsize
;
341 extern int write_archive_to_stdout
;
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
*));
358 /* Module create.c. */
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));
366 /* Module diffarch.c. */
368 extern int now_verifying
;
370 void diff_archive
PARAMS ((void));
371 void diff_init
PARAMS ((void));
372 void verify_volume
PARAMS ((void));
374 /* Module extract.c. */
376 void extr_init
PARAMS ((void));
377 void extract_archive
PARAMS ((void));
378 void apply_delayed_set_stat
PARAMS ((void));
380 /* Module delete.c. */
382 void delete_archive_members
PARAMS ((void));
384 /* Module incremen.c. */
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));
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 */
403 extern union block
*current_header
;
404 extern struct stat current_stat
;
405 extern enum archive_format current_format
;
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));
418 /* Module mangle.c. */
420 void extract_mangle
PARAMS ((void));
424 void assign_string
PARAMS ((char **, const char *));
425 char *quote_copy_string
PARAMS ((const char *));
426 int unquote_string
PARAMS ((char *));
428 char *merge_sort
PARAMS ((char *, int, int, int (*) (char *, char *)));
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));
435 /* Module names.c. */
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
*));
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 *));
458 void add_exclude
PARAMS ((char *));
459 void add_exclude_file
PARAMS ((const char *));
460 int check_exclude
PARAMS ((const char *));
464 int confirm
PARAMS ((const char *, const char *));
465 void request_stdin
PARAMS ((const char *));
467 /* Module update.c. */
469 extern char *output_start
;
471 void update_archive
PARAMS ((void));