file_cmds-60.tar.gz
[apple/file_cmds.git] / file / tar.h
1 /*
2 * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7 * Reserved. This file contains Original Code and/or Modifications of
8 * Original Code as defined in and that are subject to the Apple Public
9 * Source License Version 1.1 (the "License"). You may not use this file
10 * except in compliance with the License. Please obtain a copy of the
11 * License at http://www.apple.com/publicsource and read it before using
12 * this file.
13 *
14 * The Original Code and all software distributed under the License are
15 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19 * License for the specific language governing rights and limitations
20 * under the License.
21 *
22 * @APPLE_LICENSE_HEADER_END@
23 */
24 /* $OpenBSD: tar.h,v 1.3 1997/02/09 23:58:37 millert Exp $ */
25
26 /*
27 * Header file for public domain tar (tape archive) program.
28 *
29 * @(#)tar.h 1.20 86/10/29 Public Domain.
30 *
31 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
32 *
33 */
34
35 /*
36 * Kludge for handling systems that can't cope with multiple
37 * external definitions of a variable. In ONE routine (tar.c),
38 * we #define TAR_EXTERN to null; here, we set it to "extern" if
39 * it is not already set.
40 */
41 #ifndef TAR_EXTERN
42 #define TAR_EXTERN extern
43 #endif
44
45 /*
46 * Header block on tape.
47 *
48 * I'm going to use traditional DP naming conventions here.
49 * A "block" is a big chunk of stuff that we do I/O on.
50 * A "record" is a piece of info that we care about.
51 * Typically many "record"s fit into a "block".
52 */
53 #define RECORDSIZE 512
54 #define NAMSIZ 100
55 #define TUNMLEN 32
56 #define TGNMLEN 32
57
58 union record {
59 char charptr[RECORDSIZE];
60 struct header {
61 char name[NAMSIZ];
62 char mode[8];
63 char uid[8];
64 char gid[8];
65 char size[12];
66 char mtime[12];
67 char chksum[8];
68 char linkflag;
69 char linkname[NAMSIZ];
70 char magic[8];
71 char uname[TUNMLEN];
72 char gname[TGNMLEN];
73 char devmajor[8];
74 char devminor[8];
75 } header;
76 };
77
78 /* The checksum field is filled with this while the checksum is computed. */
79 #define CHKBLANKS " " /* 8 blanks, no null */
80
81 /* The magic field is filled with this if uname and gname are valid. */
82 #define TMAGIC "ustar " /* 7 chars and a null */
83
84 /* The linkflag defines the type of file */
85 #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
86 #define LF_NORMAL '0' /* Normal disk file */
87 #define LF_LINK '1' /* Link to previously dumped file */
88 #define LF_SYMLINK '2' /* Symbolic link */
89 #define LF_CHR '3' /* Character special file */
90 #define LF_BLK '4' /* Block special file */
91 #define LF_DIR '5' /* Directory */
92 #define LF_FIFO '6' /* FIFO special file */
93 #define LF_CONTIG '7' /* Contiguous file */
94 /* Further link types may be defined later. */
95
96 /*
97 * Exit codes from the "tar" program
98 */
99 #define EX_SUCCESS 0 /* success! */
100 #define EX_ARGSBAD 1 /* invalid args */
101 #define EX_BADFILE 2 /* invalid filename */
102 #define EX_BADARCH 3 /* bad archive */
103 #define EX_SYSTEM 4 /* system gave unexpected error */
104
105
106 /*
107 * Global variables
108 */
109 TAR_EXTERN union record *ar_block; /* Start of block of archive */
110 TAR_EXTERN union record *ar_record; /* Current record of archive */
111 TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
112 TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
113 TAR_EXTERN int blocking; /* Size of each block, in records */
114 TAR_EXTERN int blocksize; /* Size of each block, in bytes */
115 TAR_EXTERN char *ar_file; /* File containing archive */
116 TAR_EXTERN char *name_file; /* File containing names to work on */
117 TAR_EXTERN char *tar; /* Name of this program */
118
119 /*
120 * Flags from the command line
121 */
122 TAR_EXTERN char f_reblock; /* -B */
123 TAR_EXTERN char f_create; /* -c */
124 TAR_EXTERN char f_debug; /* -d */
125 TAR_EXTERN char f_sayblock; /* -D */
126 TAR_EXTERN char f_follow_links; /* -h */
127 TAR_EXTERN char f_ignorez; /* -i */
128 TAR_EXTERN char f_keep; /* -k */
129 TAR_EXTERN char f_modified; /* -m */
130 TAR_EXTERN char f_oldarch; /* -o */
131 TAR_EXTERN char f_use_protection; /* -p */
132 TAR_EXTERN char f_sorted_names; /* -s */
133 TAR_EXTERN char f_list; /* -t */
134 TAR_EXTERN char f_namefile; /* -T */
135 TAR_EXTERN char f_verbose; /* -v */
136 TAR_EXTERN char f_extract; /* -x */
137 TAR_EXTERN char f_compress; /* -z */
138
139 /*
140 * We now default to Unix Standard format rather than 4.2BSD tar format.
141 * The code can actually produce all three:
142 * f_standard ANSI standard
143 * f_oldarch V7
144 * neither 4.2BSD
145 * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
146 * The only advantage to the "neither" option is that we can cmp(1) our
147 * output to the output of 4.2BSD tar, for debugging.
148 */
149 #define f_standard (!f_oldarch)
150
151 /*
152 * Structure for keeping track of filenames and lists thereof.
153 */
154 struct name {
155 struct name *next;
156 short length;
157 char found;
158 char name[NAMSIZ+1];
159 };
160
161 TAR_EXTERN struct name *namelist; /* Points to first name in list */
162 TAR_EXTERN struct name *namelast; /* Points to last name in list */
163
164 TAR_EXTERN int archive; /* File descriptor for archive file */
165 TAR_EXTERN int errors; /* # of files in error */
166
167 /*
168 *
169 * Due to the next struct declaration, each routine that includes
170 * "tar.h" must also include <sys/types.h>. I tried to make it automatic,
171 * but System V has no defines in <sys/types.h>, so there is no way of
172 * knowing when it has been included. In addition, it cannot be included
173 * twice, but must be included exactly once. Argghh!
174 *
175 * Thanks, typedef. Thanks, USG.
176 */
177 struct link {
178 struct link *next;
179 dev_t dev;
180 ino_t ino;
181 short linkcount;
182 char name[NAMSIZ+1];
183 };
184
185 TAR_EXTERN struct link *linklist; /* Points to first link in list */
186
187
188 /*
189 * Error recovery stuff
190 */
191 TAR_EXTERN char read_error_flag;
192
193
194 /*
195 * Declarations of functions available to the world.
196 */
197 /*LINTLIBRARY*/
198 union record *findrec();
199 void userec();
200 union record *endofrecs();
201 void anno();
202 #define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */
203 #define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */