xref: /dragonfly/bin/pax/tar.h (revision 0db87cb7)
1 /*-
2  * Copyright (c) 1992 Keith Muller.
3  * Copyright (c) 1992, 1993
4  *	The Regents of the University of California.  All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * Keith Muller of the University of California, San Diego.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  * 3. All advertising materials mentioning features or use of this software
18  *    must display the following acknowledgement:
19  *	This product includes software developed by the University of
20  *	California, Berkeley and its contributors.
21  * 4. Neither the name of the University nor the names of its contributors
22  *    may be used to endorse or promote products derived from this software
23  *    without specific prior written permission.
24  *
25  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35  * SUCH DAMAGE.
36  *
37  *	@(#)tar.h	8.2 (Berkeley) 4/18/94
38  * $FreeBSD: src/bin/pax/tar.h,v 1.6 1999/08/27 23:14:47 peter Exp $
39  * $DragonFly: src/bin/pax/tar.h,v 1.2 2003/06/17 04:22:50 dillon Exp $
40  */
41 
42 /*
43  * defines and data structures common to all tar formats
44  */
45 #define CHK_LEN		8		/* length of checksum field */
46 #define TNMSZ		100		/* size of name field */
47 #ifdef _PAX_
48 #define NULLCNT		2		/* number of null blocks in trailer */
49 #define CHK_OFFSET	148		/* start of checksum field */
50 #define BLNKSUM		256L		/* sum of checksum field using ' ' */
51 #endif /* _PAX_ */
52 
53 /*
54  * Values used in typeflag field in all tar formats
55  * (only REGTYPE, LNKTYPE and SYMTYPE are used in old BSD tar headers)
56  */
57 #define	REGTYPE		'0'		/* Regular File */
58 #define	AREGTYPE	'\0'		/* Regular File */
59 #define	LNKTYPE		'1'		/* Link */
60 #define	SYMTYPE		'2'		/* Symlink */
61 #define	CHRTYPE		'3'		/* Character Special File */
62 #define	BLKTYPE		'4'		/* Block Special File */
63 #define	DIRTYPE		'5'		/* Directory */
64 #define	FIFOTYPE	'6'		/* FIFO */
65 #define	CONTTYPE	'7'		/* high perf file */
66 
67 /*
68  * Mode field encoding of the different file types - values in octal
69  */
70 #define TSUID		04000		/* Set UID on execution */
71 #define TSGID		02000		/* Set GID on execution */
72 #define TSVTX		01000		/* Reserved */
73 #define TUREAD		00400		/* Read by owner */
74 #define TUWRITE		00200		/* Write by owner */
75 #define TUEXEC		00100		/* Execute/Search by owner */
76 #define TGREAD		00040		/* Read by group */
77 #define TGWRITE		00020		/* Write by group */
78 #define TGEXEC		00010		/* Execute/Search by group */
79 #define TOREAD		00004		/* Read by other */
80 #define TOWRITE		00002		/* Write by other */
81 #define TOEXEC		00001		/* Execute/Search by other */
82 
83 #ifdef _PAX_
84 /*
85  * Pad with a bit mask, much faster than doing a mod but only works on powers
86  * of 2. Macro below is for block of 512 bytes.
87  */
88 #define TAR_PAD(x)	((512 - ((x) & 511)) & 511)
89 #endif /* _PAX_ */
90 
91 /*
92  * structure of an old tar header as it appeared in BSD releases
93  */
94 typedef struct {
95 	char name[TNMSZ];		/* name of entry */
96 	char mode[8]; 			/* mode */
97 	char uid[8]; 			/* uid */
98 	char gid[8];			/* gid */
99 	char size[12];			/* size */
100 	char mtime[12];			/* modification time */
101 	char chksum[CHK_LEN];		/* checksum */
102 	char linkflag;			/* norm, hard, or sym. */
103 	char linkname[TNMSZ];		/* linked to name */
104 } HD_TAR;
105 
106 #ifdef _PAX_
107 /*
108  * -o options for BSD tar to not write directories to the archive
109  */
110 #define TAR_NODIR	"nodir"
111 #define TAR_OPTION	"write_opt"
112 
113 /*
114  * default device names
115  */
116 #define	DEV_0		"/dev/rmt0"
117 #define	DEV_1		"/dev/rmt1"
118 #define	DEV_4		"/dev/rmt4"
119 #define	DEV_5		"/dev/rmt5"
120 #define	DEV_7		"/dev/rmt7"
121 #define	DEV_8		"/dev/rmt8"
122 #endif /* _PAX_ */
123 
124 /*
125  * Data Interchange Format - Extended tar header format - POSIX 1003.1-1990
126  */
127 #define TPFSZ		155
128 #define	TMAGIC		"ustar"		/* ustar and a null */
129 #define	TMAGLEN		6
130 #define	TVERSION	"00"		/* 00 and no null */
131 #define	TVERSLEN	2
132 
133 typedef struct {
134 	char name[TNMSZ];		/* name of entry */
135 	char mode[8]; 			/* mode */
136 	char uid[8]; 			/* uid */
137 	char gid[8];			/* gid */
138 	char size[12];			/* size */
139 	char mtime[12];			/* modification time */
140 	char chksum[CHK_LEN];		/* checksum */
141 	char typeflag;			/* type of file. */
142 	char linkname[TNMSZ];		/* linked to name */
143 	char magic[TMAGLEN];		/* magic cookie */
144 	char version[TVERSLEN];		/* version */
145 	char uname[32];			/* ascii owner name */
146 	char gname[32];			/* ascii group name */
147 	char devmajor[8];		/* major device number */
148 	char devminor[8];		/* minor device number */
149 	char prefix[TPFSZ];		/* linked to name */
150 } HD_USTAR;
151