BSD 4_4 release
[unix-history] / usr / src / bin / pax / tar.h
CommitLineData
79aa58f4
KM
1/*-
2 * Copyright (c) 1992 Keith Muller.
f547d164
KB
3 * Copyright (c) 1992, 1993
4 * The Regents of the University of California. All rights reserved.
79aa58f4
KM
5 *
6 * This code is derived from software contributed to Berkeley by
7 * Keith Muller of the University of California, San Diego.
8 *
ad787160
C
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.
79aa58f4 24 *
ad787160
C
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.1 (Berkeley) 5/31/93
79aa58f4
KM
38 */
39
40/*
41 * defines and data structures common to all tar formats
42 */
445ebf89 43#define CHK_LEN 8 /* length of checksum field */
79aa58f4 44#define TNMSZ 100 /* size of name field */
445ebf89
KM
45#ifdef _PAX_
46#define NULLCNT 2 /* number of null blocks in trailer */
79aa58f4 47#define CHK_OFFSET 148 /* start of chksum field */
79aa58f4 48#define BLNKSUM 256L /* sum of checksum field using ' ' */
445ebf89 49#endif /* _PAX_ */
79aa58f4
KM
50
51/*
445ebf89
KM
52 * Values used in typeflag field in all tar formats
53 * (only REGTYPE, LNKTYPE and SYMTYPE are used in old bsd tar headers)
79aa58f4 54 */
445ebf89
KM
55#define REGTYPE '0' /* Regular File */
56#define AREGTYPE '\0' /* Regular File */
57#define LNKTYPE '1' /* Link */
58#define SYMTYPE '2' /* Symlink */
59#define CHRTYPE '3' /* Character Special File */
60#define BLKTYPE '4' /* Block Special File */
61#define DIRTYPE '5' /* Directory */
62#define FIFOTYPE '6' /* FIFO */
63#define CONTTYPE '7' /* high perf file */
79aa58f4
KM
64
65/*
445ebf89 66 * Mode field encoding of the different file types - values in octal
79aa58f4 67 */
445ebf89
KM
68#define TSUID 04000 /* Set UID on execution */
69#define TSGID 02000 /* Set GID on execution */
70#define TSVTX 01000 /* Reserved */
71#define TUREAD 00400 /* Read by owner */
72#define TUWRITE 00200 /* Write by owner */
73#define TUEXEC 00100 /* Execute/Search by owner */
74#define TGREAD 00040 /* Read by group */
75#define TGWRITE 00020 /* Write by group */
76#define TGEXEC 00010 /* Execute/Search by group */
77#define TOREAD 00004 /* Read by other */
78#define TOWRITE 00002 /* Write by other */
79#define TOEXEC 00001 /* Execute/Search by other */
79aa58f4 80
445ebf89 81#ifdef _PAX_
79aa58f4 82/*
445ebf89
KM
83 * Pad with a bit mask, much faster than doing a mod but only works on powers
84 * of 2. Macro below is for block of 512 bytes.
85 */
86#define TAR_PAD(x) ((512 - ((x) & 511)) & 511)
87#endif /* _PAX_ */
88
89/*
90 * structure of an old tar header as it appeared in BSD releases
79aa58f4
KM
91 */
92typedef struct {
93 char name[TNMSZ]; /* name of entry */
94 char mode[8]; /* mode */
95 char uid[8]; /* uid */
96 char gid[8]; /* gid */
97 char size[12]; /* size */
98 char mtime[12]; /* modification time */
445ebf89 99 char chksum[CHK_LEN]; /* checksum */
79aa58f4
KM
100 char linkflag; /* norm, hard, or sym. */
101 char linkname[TNMSZ]; /* linked to name */
102} HD_TAR;
103
445ebf89
KM
104#ifdef _PAX_
105/*
106 * -o options for BSD tar to not write directories to the archive
107 */
108#define TAR_NODIR "nodir"
109#define TAR_OPTION "write_opt"
110#endif /* _PAX_ */
111
79aa58f4 112/*
445ebf89 113 * Data Interchange Format - Extended tar header format - POSIX 1003.1-1990
79aa58f4
KM
114 */
115#define TPFSZ 155
116#define TMAGIC "ustar" /* ustar and a null */
117#define TMAGLEN 6
118#define TVERSION "00" /* 00 and no null */
119#define TVERSLEN 2
120
121typedef struct {
122 char name[TNMSZ]; /* name of entry */
123 char mode[8]; /* mode */
124 char uid[8]; /* uid */
125 char gid[8]; /* gid */
126 char size[12]; /* size */
127 char mtime[12]; /* modification time */
445ebf89 128 char chksum[CHK_LEN]; /* checksum */
79aa58f4
KM
129 char typeflag; /* type of file. */
130 char linkname[TNMSZ]; /* linked to name */
131 char magic[TMAGLEN]; /* magic cookie */
132 char version[TVERSLEN]; /* version */
133 char uname[32]; /* ascii owner name */
134 char gname[32]; /* ascii group name */
135 char devmajor[8]; /* major device number */
136 char devminor[8]; /* minor device number */
137 char prefix[TPFSZ]; /* linked to name */
138} HD_USTAR;