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