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