/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1992 Keith Muller.4* Copyright (c) 1992, 19935* The Regents of the University of California. All rights reserved.6*7* This code is derived from software contributed to Berkeley by8* Keith Muller of the University of California, San Diego.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435/*36* defines and data structures common to all tar formats37*/38#define CHK_LEN 8 /* length of checksum field */39#define TNMSZ 100 /* size of name field */40#ifdef _PAX_41#define NULLCNT 2 /* number of null blocks in trailer */42#define CHK_OFFSET 148 /* start of checksum field */43#define BLNKSUM 256L /* sum of checksum field using ' ' */44#endif /* _PAX_ */4546/*47* Values used in typeflag field in all tar formats48* (only REGTYPE, LNKTYPE and SYMTYPE are used in old BSD tar headers)49*/50#define REGTYPE '0' /* Regular File */51#define AREGTYPE '\0' /* Regular File */52#define LNKTYPE '1' /* Link */53#define SYMTYPE '2' /* Symlink */54#define CHRTYPE '3' /* Character Special File */55#define BLKTYPE '4' /* Block Special File */56#define DIRTYPE '5' /* Directory */57#define FIFOTYPE '6' /* FIFO */58#define CONTTYPE '7' /* high perf file */5960/*61* Mode field encoding of the different file types - values in octal62*/63#define TSUID 04000 /* Set UID on execution */64#define TSGID 02000 /* Set GID on execution */65#define TSVTX 01000 /* Reserved */66#define TUREAD 00400 /* Read by owner */67#define TUWRITE 00200 /* Write by owner */68#define TUEXEC 00100 /* Execute/Search by owner */69#define TGREAD 00040 /* Read by group */70#define TGWRITE 00020 /* Write by group */71#define TGEXEC 00010 /* Execute/Search by group */72#define TOREAD 00004 /* Read by other */73#define TOWRITE 00002 /* Write by other */74#define TOEXEC 00001 /* Execute/Search by other */7576#ifdef _PAX_77/*78* Pad with a bit mask, much faster than doing a mod but only works on powers79* of 2. Macro below is for block of 512 bytes.80*/81#define TAR_PAD(x) ((512 - ((x) & 511)) & 511)82#endif /* _PAX_ */8384/*85* structure of an old tar header as it appeared in BSD releases86*/87typedef struct {88char name[TNMSZ]; /* name of entry */89char mode[8]; /* mode */90char uid[8]; /* uid */91char gid[8]; /* gid */92char size[12]; /* size */93char mtime[12]; /* modification time */94char chksum[CHK_LEN]; /* checksum */95char linkflag; /* norm, hard, or sym. */96char linkname[TNMSZ]; /* linked to name */97} HD_TAR __aligned(1);9899#ifdef _PAX_100/*101* -o options for BSD tar to not write directories to the archive102*/103#define TAR_NODIR "nodir"104#define TAR_OPTION "write_opt"105106/*107* default device names108*/109#define DEV_0 "/dev/rmt0"110#define DEV_1 "/dev/rmt1"111#define DEV_4 "/dev/rmt4"112#define DEV_5 "/dev/rmt5"113#define DEV_7 "/dev/rmt7"114#define DEV_8 "/dev/rmt8"115#endif /* _PAX_ */116117/*118* Data Interchange Format - Extended tar header format - POSIX 1003.1-1990119*/120#define TPFSZ 155121#define TMAGIC "ustar" /* ustar and a null */122#define TMAGLEN 6123#define TVERSION "00" /* 00 and no null */124#define TVERSLEN 2125126typedef struct {127char name[TNMSZ]; /* name of entry */128char mode[8]; /* mode */129char uid[8]; /* uid */130char gid[8]; /* gid */131char size[12]; /* size */132char mtime[12]; /* modification time */133char chksum[CHK_LEN]; /* checksum */134char typeflag; /* type of file. */135char linkname[TNMSZ]; /* linked to name */136char magic[TMAGLEN]; /* magic cookie */137char version[TVERSLEN]; /* version */138char uname[32]; /* ascii owner name */139char gname[32]; /* ascii group name */140char devmajor[8]; /* major device number */141char devminor[8]; /* minor device number */142char prefix[TPFSZ]; /* linked to name */143} HD_USTAR __aligned(1);144145146