tar.h revision 139368
1144513Simp/* 2144513Simp * Copyright (c) Ian F. Darwin 1986-1995. 3144513Simp * Software written by Ian F. Darwin and others; 4144513Simp * maintained 1995-present by Christos Zoulas and others. 5144513Simp * 6232276Stijl * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions 8 * are met: 9 * 1. Redistributions of source code must retain the above copyright 10 * notice immediately at the beginning of the file, without modification, 11 * this list of conditions, and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26 * SUCH DAMAGE. 27 */ 28/* 29 * Header file for public domain tar (tape archive) program. 30 * 31 * @(#)tar.h 1.20 86/10/29 Public Domain. 32 * 33 * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu. 34 * 35 * $Id: tar.h,v 1.8 2004/09/11 19:15:58 christos Exp $ # checkin only 36 */ 37 38/* 39 * Kludge for handling systems that cannot cope with multiple 40 * external definitions of a variable. In ONE routine (tar.c), 41 * we #define TAR_EXTERN to null; here, we set it to "extern" if 42 * it is not already set. 43 */ 44#ifndef TAR_EXTERN 45#define TAR_EXTERN extern 46#endif 47 48/* 49 * Header block on tape. 50 * 51 * I'm going to use traditional DP naming conventions here. 52 * A "block" is a big chunk of stuff that we do I/O on. 53 * A "record" is a piece of info that we care about. 54 * Typically many "record"s fit into a "block". 55 */ 56#define RECORDSIZE 512 57#define NAMSIZ 100 58#define TUNMLEN 32 59#define TGNMLEN 32 60 61union record { 62 char charptr[RECORDSIZE]; 63 struct header { 64 char name[NAMSIZ]; 65 char mode[8]; 66 char uid[8]; 67 char gid[8]; 68 char size[12]; 69 char mtime[12]; 70 char chksum[8]; 71 char linkflag; 72 char linkname[NAMSIZ]; 73 char magic[8]; 74 char uname[TUNMLEN]; 75 char gname[TGNMLEN]; 76 char devmajor[8]; 77 char devminor[8]; 78 } header; 79}; 80 81/* The checksum field is filled with this while the checksum is computed. */ 82#define CHKBLANKS " " /* 8 blanks, no null */ 83 84/* The magic field is filled with this if uname and gname are valid. */ 85#define TMAGIC "ustar " /* 7 chars and a null */ 86 87/* The linkflag defines the type of file */ 88#define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */ 89#define LF_NORMAL '0' /* Normal disk file */ 90#define LF_LINK '1' /* Link to previously dumped file */ 91#define LF_SYMLINK '2' /* Symbolic link */ 92#define LF_CHR '3' /* Character special file */ 93#define LF_BLK '4' /* Block special file */ 94#define LF_DIR '5' /* Directory */ 95#define LF_FIFO '6' /* FIFO special file */ 96#define LF_CONTIG '7' /* Contiguous file */ 97/* Further link types may be defined later. */ 98 99/* 100 * Exit codes from the "tar" program 101 */ 102#define EX_SUCCESS 0 /* success! */ 103#define EX_ARGSBAD 1 /* invalid args */ 104#define EX_BADFILE 2 /* invalid filename */ 105#define EX_BADARCH 3 /* bad archive */ 106#define EX_SYSTEM 4 /* system gave unexpected error */ 107 108 109/* 110 * Global variables 111 */ 112TAR_EXTERN union record *ar_block; /* Start of block of archive */ 113TAR_EXTERN union record *ar_record; /* Current record of archive */ 114TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */ 115TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */ 116TAR_EXTERN int blocking; /* Size of each block, in records */ 117TAR_EXTERN int blocksize; /* Size of each block, in bytes */ 118TAR_EXTERN char *ar_file; /* File containing archive */ 119TAR_EXTERN char *name_file; /* File containing names to work on */ 120TAR_EXTERN char *tar; /* Name of this program */ 121 122/* 123 * Flags from the command line 124 */ 125TAR_EXTERN char f_reblock; /* -B */ 126TAR_EXTERN char f_create; /* -c */ 127TAR_EXTERN char f_debug; /* -d */ 128TAR_EXTERN char f_sayblock; /* -D */ 129TAR_EXTERN char f_follow_links; /* -h */ 130TAR_EXTERN char f_ignorez; /* -i */ 131TAR_EXTERN char f_keep; /* -k */ 132TAR_EXTERN char f_modified; /* -m */ 133TAR_EXTERN char f_oldarch; /* -o */ 134TAR_EXTERN char f_use_protection; /* -p */ 135TAR_EXTERN char f_sorted_names; /* -s */ 136TAR_EXTERN char f_list; /* -t */ 137TAR_EXTERN char f_namefile; /* -T */ 138TAR_EXTERN char f_verbose; /* -v */ 139TAR_EXTERN char f_extract; /* -x */ 140TAR_EXTERN char f_compress; /* -z */ 141 142/* 143 * We now default to Unix Standard format rather than 4.2BSD tar format. 144 * The code can actually produce all three: 145 * f_standard ANSI standard 146 * f_oldarch V7 147 * neither 4.2BSD 148 * but we don't bother, since 4.2BSD can read ANSI standard format anyway. 149 * The only advantage to the "neither" option is that we can cmp(1) our 150 * output to the output of 4.2BSD tar, for debugging. 151 */ 152#define f_standard (!f_oldarch) 153 154/* 155 * Structure for keeping track of filenames and lists thereof. 156 */ 157struct name { 158 struct name *next; 159 short length; 160 char found; 161 char name[NAMSIZ+1]; 162}; 163 164TAR_EXTERN struct name *namelist; /* Points to first name in list */ 165TAR_EXTERN struct name *namelast; /* Points to last name in list */ 166 167TAR_EXTERN int archive; /* File descriptor for archive file */ 168TAR_EXTERN int errors; /* # of files in error */ 169 170/* 171 * 172 * Due to the next struct declaration, each routine that includes 173 * "tar.h" must also include <sys/types.h>. I tried to make it automatic, 174 * but System V has no defines in <sys/types.h>, so there is no way of 175 * knowing when it has been included. In addition, it cannot be included 176 * twice, but must be included exactly once. Argghh! 177 * 178 * Thanks, typedef. Thanks, USG. 179 */ 180struct link { 181 struct link *next; 182 dev_t dev; 183 ino_t ino; 184 short linkcount; 185 char name[NAMSIZ+1]; 186}; 187 188TAR_EXTERN struct link *linklist; /* Points to first link in list */ 189 190 191/* 192 * Error recovery stuff 193 */ 194TAR_EXTERN char read_error_flag; 195 196 197#if 0 198/* 199 * Declarations of functions available to the world. 200 */ 201/*LINTLIBRARY*/ 202#define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */ 203#define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */ 204#endif 205