386BSD 0.1 development
[unix-history] / usr / src / usr.bin / tar / tar.h
CommitLineData
876bbceb
WJ
1/*
2
3 Copyright (C) 1988 Free Software Foundation
4
5GNU tar is distributed in the hope that it will be useful, but WITHOUT ANY
6WARRANTY. No author or distributor accepts responsibility to anyone
7for the consequences of using it or for whether it serves any
8particular purpose or works at all, unless he says so in writing.
9Refer to the GNU tar General Public License for full details.
10
11Everyone is granted permission to copy, modify and redistribute GNU tar,
12but only under the conditions described in the GNU tar General Public
13License. A copy of this license is supposed to have been given to you
14along with GNU tar so you can know your rights and responsibilities. It
15should be in a file named COPYING. Among other things, the copyright
16notice and this notice must be preserved on all copies.
17
18In other words, go ahead and share GNU tar, but don't try to stop
19anyone else from sharing it farther. Help stamp out software hoarding!
20*/
21
22/*
23 * Header file for tar (tape archive) program.
24 *
25 * @(#)tar.h 1.24 87/11/06
26 *
27 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
28 */
29
30#ifndef __386BSD__
31#include "testpad.h"
32#endif
33
34/* major() and minor() macros (among other things) defined here for hpux */
35#ifdef hpux
36#include <sys/mknod.h>
37#endif
38
39/*
40 * Kludge for handling systems that can't cope with multiple
41 * external definitions of a variable. In ONE routine (tar.c),
42 * we #define TAR_EXTERN to null; here, we set it to "extern" if
43 * it is not already set.
44 */
45#ifndef TAR_EXTERN
46#define TAR_EXTERN extern
47#endif
48
49#if defined(USG) && !defined(XENIX) && !defined(HAVE_SIZE_T)
50typedef int size_t;
51#endif
52
53/*
54 * Header block on tape.
55 *
56 * I'm going to use traditional DP naming conventions here.
57 * A "block" is a big chunk of stuff that we do I/O on.
58 * A "record" is a piece of info that we care about.
59 * Typically many "record"s fit into a "block".
60 */
61#define RECORDSIZE 512
62#define NAMSIZ 100
63#define TUNMLEN 32
64#define TGNMLEN 32
65#define SPARSE_EXT_HDR 21
66#define SPARSE_IN_HDR 4
67
68struct sparse {
69 char offset[12];
70 char numbytes[12];
71};
72
73struct sp_array {
74 int offset;
75 int numbytes;
76};
77
78union record {
79 char charptr[RECORDSIZE];
80 struct header {
81 char name[NAMSIZ];
82 char mode[8];
83 char uid[8];
84 char gid[8];
85 char size[12];
86 char mtime[12];
87 char chksum[8];
88 char linkflag;
89 char linkname[NAMSIZ];
90 char magic[8];
91 char uname[TUNMLEN];
92 char gname[TGNMLEN];
93 char devmajor[8];
94 char devminor[8];
95 /* these following fields were added by JF for gnu */
96 /* and are NOT standard */
97 char atime[12];
98 char ctime[12];
99 char offset[12];
100 char longnames[4];
101#ifdef NEEDPAD
102 char pad;
103#endif
104 struct sparse sp[SPARSE_IN_HDR];
105 char isextended;
106 char realsize[12]; /* true size of the sparse file */
107/* char ending_blanks[12];*/ /* number of nulls at the
108 end of the file, if any */
109 } header;
110 struct extended_header {
111 struct sparse sp[21];
112 char isextended;
113 } ext_hdr;
114};
115
116/* The checksum field is filled with this while the checksum is computed. */
117#define CHKBLANKS " " /* 8 blanks, no null */
118
119/* The magic field is filled with this if uname and gname are valid. */
120#define TMAGIC "ustar " /* 7 chars and a null */
121
122/* The linkflag defines the type of file */
123#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
124#define LF_NORMAL '0' /* Normal disk file */
125#define LF_LINK '1' /* Link to previously dumped file */
126#define LF_SYMLINK '2' /* Symbolic link */
127#define LF_CHR '3' /* Character special file */
128#define LF_BLK '4' /* Block special file */
129#define LF_DIR '5' /* Directory */
130#define LF_FIFO '6' /* FIFO special file */
131#define LF_CONTIG '7' /* Contiguous file */
132/* Further link types may be defined later. */
133
134/* Note that the standards committee allows only capital A through
135 capital Z for user-defined expansion. This means that defining something
136 as, say '8' is a *bad* idea. */
137#define LF_DUMPDIR 'D' /* This is a dir entry that contains
138 the names of files that were in
139 the dir at the time the dump
140 was made */
141#define LF_MULTIVOL 'M' /* This is the continuation
142 of a file that began on another
143 volume */
144#define LF_NAMES 'N' /* For storing filenames that didn't
145 fit in 100 characters */
146#define LF_SPARSE 'S' /* This is for sparse files */
147#define LF_VOLHDR 'V' /* This file is a tape/volume header */
148 /* Ignore it on extraction */
149
150/*
151 * Exit codes from the "tar" program
152 */
153#define EX_SUCCESS 0 /* success! */
154#define EX_ARGSBAD 1 /* invalid args */
155#define EX_BADFILE 2 /* invalid filename */
156#define EX_BADARCH 3 /* bad archive */
157#define EX_SYSTEM 4 /* system gave unexpected error */
158#define EX_BADVOL 5 /* Special error code means
159 Tape volume doesn't match the one
160 specified on the command line */
161
162/*
163 * Global variables
164 */
165TAR_EXTERN union record *ar_block; /* Start of block of archive */
166TAR_EXTERN union record *ar_record; /* Current record of archive */
167TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
168TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
169TAR_EXTERN int blocking; /* Size of each block, in records */
170TAR_EXTERN int blocksize; /* Size of each block, in bytes */
171TAR_EXTERN char *ar_file; /* File containing archive */
172TAR_EXTERN char *info_script; /* Script to run at end of each tape change */
173TAR_EXTERN char *name_file; /* File containing names to work on */
174TAR_EXTERN char *tar; /* Name of this program */
175TAR_EXTERN struct sp_array *sparsearray;/* Pointer to the start of the scratch space */
176TAR_EXTERN int sp_array_size; /* Initial size of the sparsearray */
177TAR_EXTERN int tot_written; /* Total written to output */
178TAR_EXTERN struct re_pattern_buffer
179 *label_pattern; /* compiled regex for extract label */
180
181/*
182 * Flags from the command line
183 */
184TAR_EXTERN int cmd_mode;
185#define CMD_NONE 0
186#define CMD_CAT 1 /* -A */
187#define CMD_CREATE 2 /* -c */
188#define CMD_DIFF 3 /* -d */
189#define CMD_APPEND 4 /* -r */
190#define CMD_LIST 5 /* -t */
191#define CMD_UPDATE 6 /* -u */
192#define CMD_EXTRACT 7 /* -x */
193#define CMD_DELETE 8 /* -D */
194#define CMD_VERSION 9 /* +version */
195
196 /* -[0-9][lmh] */
197 /* CMD_CAT -A */
198 /* -b */
199TAR_EXTERN int f_reblock; /* -B */
200 /* CMD_CREATE -c */
201 /* -C */
202 /* CMD_DIFF -d */
203/* TAR_EXTERN char f_dironly; /* -D */
204 /* -f */
205TAR_EXTERN int f_run_script_at_end; /* -F */
206TAR_EXTERN int f_gnudump; /* -G */
207TAR_EXTERN int f_follow_links; /* -h */
208TAR_EXTERN int f_ignorez; /* -i */
209 /* CMD_DELETE -J */
210TAR_EXTERN int f_keep; /* -k */
211TAR_EXTERN int f_startfile; /* -K */
212TAR_EXTERN int f_local_filesys; /* -l */
213TAR_EXTERN int tape_length; /* -L */
214TAR_EXTERN int f_modified; /* -m */
215TAR_EXTERN int f_multivol; /* -M */
216TAR_EXTERN int f_new_files; /* -N */
217TAR_EXTERN int f_oldarch; /* -o */
218TAR_EXTERN int f_exstdout; /* -O */
219TAR_EXTERN int f_use_protection; /* -p */
220TAR_EXTERN int f_absolute_paths; /* -P */
221TAR_EXTERN int f_sayblock; /* -R */
222TAR_EXTERN int f_sorted_names; /* -s */
223TAR_EXTERN int f_sparse_files; /* -S ... JK */
224TAR_EXTERN int f_namefile; /* -T */
225 /* CMD_UPDATE -u */
226TAR_EXTERN int f_verbose; /* -v */
227TAR_EXTERN char *f_volhdr; /* -V */
228TAR_EXTERN int f_confirm; /* -w */
229TAR_EXTERN int f_verify; /* -W */
230 /* CMD_EXTRACT -x */
231TAR_EXTERN int f_exclude; /* -X */
232TAR_EXTERN int f_compress; /* -z */
233 /* -Z */
234TAR_EXTERN int f_do_chown; /* +do-chown */
235TAR_EXTERN int f_totals; /* +totals */
236
237/*
238 * We now default to Unix Standard format rather than 4.2BSD tar format.
239 * The code can actually produce all three:
240 * f_standard ANSI standard
241 * f_oldarch V7
242 * neither 4.2BSD
243 * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
244 * The only advantage to the "neither" option is that we can cmp our
245 * output to the output of 4.2BSD tar, for debugging.
246 */
247#define f_standard (!f_oldarch)
248
249/*
250 * Structure for keeping track of filenames and lists thereof.
251 */
252struct name {
253 struct name *next;
254 short length; /* cached strlen(name) */
255 char found; /* A matching file has been found */
256 char firstch; /* First char is literally matched */
257 char regexp; /* This name is a regexp, not literal */
258 char *change_dir; /* JF set with the -C option */
259 char *dir_contents; /* JF for f_gnudump */
260 char fake; /* dummy entry */
261 char name[1];
262};
263
264TAR_EXTERN struct name *namelist; /* Points to first name in list */
265TAR_EXTERN struct name *namelast; /* Points to last name in list */
266
267TAR_EXTERN int archive; /* File descriptor for archive file */
268TAR_EXTERN int errors; /* # of files in error */
269
270TAR_EXTERN char *gnu_dumpfile;
271
272/*
273 * Error recovery stuff
274 */
275TAR_EXTERN char read_error_flag;
276
277
278/*
279 * Declarations of functions available to the world.
280 */
281union record *findrec();
282void userec();
283union record *endofrecs();
284void anno();
285
286/* Do not prototype these for BSD--see port.c [DOPRNT_MSG]. */
287#if defined(__STDC__) && (!defined(BSD42) || defined(STDC_MSG))
288void msg(char *, ...);
289void msg_perror(char *, ...);
290#else
291void msg();
292void msg_perror();
293#endif
294/* #define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */
295/* #define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */