TAR(4-SysV) RISC/os Reference Manual TAR(4-SysV)
NAME
tar - tape archive file format
DESCRIPTION
tar, the tape archive command, dumps several files into one,
in a medium suitable for transportation.
A ``tar tape'' or file is a series of blocks. Each block is
of size TBLOCK. A file on the tape is represented by a
header block which describes the file, followed by zero or
more blocks which give the contents of the file. At the end
of the tape are two blocks filled with binary zeros, as an
end-of-file indicator.
The blocks are grouped for physical I/O operations. Each
group of n blocks (where n is set by the b keyletter on the
tar(1) command line - default is 20 blocks) is written with
a single system call; on nine-track tapes, the result of
this write is a single tape record. The last group is
always written at the full size, so blocks after the two
zero blocks contain random data. On reading, the specified
or default group size is used for the first read, but if
that read returns less than a full tape block, the reduced
block size is used for further reads.
The header block looks like:
#define TBLOCK 512
#define NAMSIZ 100
#define PREFSIZ 155
#define IDLEN 32
union hblock {
char dummy[TBLOCK];
struct header {
char name[NAMSIZ];
char mode[8];
char uid[8];
char gid[8];
char size[12];
char mtime[12];
char chksum[8];
char typeflag;
char linkname[NAMSIZ];
char magic[TMAGLEN];
char version[TVERSLEN];
char uname[IDLEN];
char gname[IDLEN];
char devmajor[8];
char devminor[8];
Printed 1/15/91 Page 1
TAR(4-SysV) RISC/os Reference Manual TAR(4-SysV)
char prefix[PREFSIZ];
} dbuf;
};
Symbolic constants used in the header blocks are defined in
the header <tar.h> as follows:
#define TMAGIC "ustar"
#define TMAGLEN 6
#define TVERSION "00" /* 00 and no null */
#define TVERSLEN 2
/* Values used in typeflag field */
#define REGTYPE '0' /* Regular File */
#define AREGTYPE '\0' /* Regular File */
#define LNKTYPE '1' /* Link */
#define SYMTYPE '2' /* Symbolic Link */
#define CHRTYPE '3' /* Character Special File */
#define BLKTYPE '4' /* Block Special File */
#define DIRTYPE '5' /* Directory */
#define FIFOTYPE '6' /* FIFO Special File */
#define CONTTYPE '7' /* Reserved */
/* Bits used in the mode field - values in octal */
#define TSUID 04000 /* Set UID on execution */
#define TSGID 02000 /* Set GID on execution */
#define TSVTX 01000 /* Set "sticky" bit on execution */
/* File permissions */
#define TUREAD 00400 /* read by owner */
#define TUWRITE 00200 /* write by owner */
#define TUEXEC 00100 /* execute/search by owner */
#define TGREAD 00040 /* read by group */
#define TGWRITE 00020 /* write by group */
#define TGEXEC 00010 /* execute/search by group */
#define TOREAD 00004 /* read by others */
#define TOWRITE 00002 /* write by others */
#define TOEXEC 00001 /* execute/search by others */
All characters are represented in the American Standard Code
for Information Exchange, ASCII.
Each field within the header block is contiguous; that is,
there is no padding used. Each character on the archive
medium is stored contiguously.
The fields magic, uname, and gname are null-terminated
strings. The fields name, linkname, and prefix are null-
terminated character strings except when all characters in
the array contain non-null characters including the last
character. The version field is two bytes containing the
characters "00" (zero-zero). The typeflag contains a single
character. All other fields are leading zero-filled octal
Page 2 Printed 1/15/91
TAR(4-SysV) RISC/os Reference Manual TAR(4-SysV)
numbers in ASCII. Each numeric field is terminated by one or
more spaces or nulls.
The name and the prefix fields produce the pathname of the
file. If the prefix contains non-null characters, then the
prefix, a slash character, and name are concatenated without
modification or addition of new characters to produce a new
pathname. The entire pathname is placed in name if it is
less than NAMSIZ characters.
The linkname field, described below, does not use the prefix
to produce a pathname.
The mode field provides 9 bits specifying file permissions
and 3 bits to specify the set UID, set GID, and TSVTX modes.
When extracting files with the set UID and/or set GID mode
bits set, if the user restoring the files from the archive
is not the super-user, these mode bits will be ignored.
The uid and gid fields are the user and group ID of the
file's owner and group, respectively.
The size field is the size of the file in bytes. Links and
symbolic links are dumped with this field specified as zero,
as are directories, block and character special files and
FIFOs. For other file types, the number of blocks written
following the header is (size + 511)/512 ignoring any frac-
tion in the result of the division.
The mtime field is the modification time of the file at the
time it was archived. It is the ASCII representation of the
octal value of the modification time obtained from stat(2).
The chksum field is the ASCII representation of the octal
value which represents the sum of all the bytes in the
header block. Each 8-bit byte in the header is treated as an
unsigned value. These values are added to an unsigned
integer, initialized to zero, the precision of which is 17
bits. When calculating the checksum, the chksum field is
treated as if it were all blanks.
The typeflag field specifies the type of file archived. If
tar encounters a type it does not recognize, the file will
be extracted as if it were a regular file and an error mes-
sage will be generated.
The typeflag field may contain one of the following:
REGTYPE represents a regular file. This value is
used when creating new archives.
AREGTYPE also represents a regular file. It is
Printed 1/15/91 Page 3
TAR(4-SysV) RISC/os Reference Manual TAR(4-SysV)
provided for backwards compatibility, and so,
it is only used when extracting files from an
archive.
LNKTYPE represents a file linked to another file, of
any type, previously archived. The linked-to
name is specified in the linkname field with
a trailing null.
SYMTYPE represents a symbolic link. The linked-to
name is specified in the linkname, field with
a trailing null.
CHRTYPE represents a character special file. The
devmajor and devminor fields contain the
ASCII representation of the octal values for
the device major and minor number, respec-
tively.
BLKTYPE represents a block special file. The devma-
jor and devminor fields contain the ASCII
representation of the octal values for the
device major and minor number, respectively.
DIRTYPE represents a directory or sub-directory.
FIFOTYPE represents a FIFO special file.
CONTTYPE This value is reserved for possible future
use.
The magic field is used to specify the format used to create
the archive. If this field contains TMAGIC, the uname and
gname fields contain the ASCII representation (truncated to
fit, if necessary) of the owner and group of the file,
respectively. When the file is restored, tar will scan the
password and group files for these names. If found, the
user and group IDs contained within these files will be used
rather than the values contained with in the uid and gid
fields.
Unused fields of the header are binary zeros (and are
included in the checksum).
The first time a given i-node number is dumped, it is dumped
as a regular file. The second and subsequent times, it is
dumped as a link instead. Upon retrieval, if a link entry
is retrieved, but not the file it was linked to, an error
message is printed and the tape must be manually re-scanned
to retrieve the linked-to file.
Page 4 Printed 1/15/91
TAR(4-SysV) RISC/os Reference Manual TAR(4-SysV)
The encoding of the header is designed to be portable across
machines.
SEE ALSO
tar(1)
BUGS
If name or linkname is longer than NAMSIZ, tar will produce
an error and the file will not be archived.
Printed 1/15/91 Page 5