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