source: trunk/essentials/app-arch/tar/doc/intern.texi

Last change on this file was 3342, checked in by bird, 18 years ago

tar 1.16.1

File size: 15.5 KB
Line 
1@c This is part of the paxutils manual.
2@c Copyright (C) 2006 Free Software Foundation, Inc.
3@c This file is distributed under GFDL 1.1 or any later version
4@c published by the Free Software Foundation.
5
6@menu
7* Standard:: Basic Tar Format
8* Extensions:: @acronym{GNU} Extensions to the Archive Format
9* Sparse Formats:: Storing Sparse Files
10* Snapshot Files::
11* Dumpdir::
12@end menu
13
14@node Standard
15@unnumberedsec Basic Tar Format
16@UNREVISED
17
18While an archive may contain many files, the archive itself is a
19single ordinary file. Like any other file, an archive file can be
20written to a storage device such as a tape or disk, sent through a
21pipe or over a network, saved on the active file system, or even
22stored in another archive. An archive file is not easy to read or
23manipulate without using the @command{tar} utility or Tar mode in
24@acronym{GNU} Emacs.
25
26Physically, an archive consists of a series of file entries terminated
27by an end-of-archive entry, which consists of two 512 blocks of zero
28bytes. A file
29entry usually describes one of the files in the archive (an
30@dfn{archive member}), and consists of a file header and the contents
31of the file. File headers contain file names and statistics, checksum
32information which @command{tar} uses to detect file corruption, and
33information about file types.
34
35Archives are permitted to have more than one member with the same
36member name. One way this situation can occur is if more than one
37version of a file has been stored in the archive. For information
38about adding new versions of a file to an archive, see @ref{update}.
39@FIXME-xref{To learn more about having more than one archive member with the
40same name, see -backup node, when it's written.}
41
42In addition to entries describing archive members, an archive may
43contain entries which @command{tar} itself uses to store information.
44@xref{label}, for an example of such an archive entry.
45
46A @command{tar} archive file contains a series of blocks. Each block
47contains @code{BLOCKSIZE} bytes. Although this format may be thought
48of as being on magnetic tape, other media are often used.
49
50Each file archived is represented by a header block which describes
51the file, followed by zero or more blocks which give the contents
52of the file. At the end of the archive file there are two 512-byte blocks
53filled with binary zeros as an end-of-file marker. A reasonable system
54should write such end-of-file marker at the end of an archive, but
55must not assume that such a block exists when reading an archive. In
56particular @GNUTAR{} always issues a warning if it does not encounter it.
57
58The blocks may be @dfn{blocked} for physical I/O operations.
59Each record of @var{n} blocks (where @var{n} is set by the
60@option{--blocking-factor=@var{512-size}} (@option{-b @var{512-size}}) option to @command{tar}) is written with a single
61@w{@samp{write ()}} operation. On magnetic tapes, the result of
62such a write is a single record. When writing an archive,
63the last record of blocks should be written at the full size, with
64blocks after the zero block containing all zeros. When reading
65an archive, a reasonable system should properly handle an archive
66whose last record is shorter than the rest, or which contains garbage
67records after a zero block.
68
69The header block is defined in C as follows. In the @GNUTAR{}
70distribution, this is part of file @file{src/tar.h}:
71
72@smallexample
73@include header.texi
74@end smallexample
75
76All characters in header blocks are represented by using 8-bit
77characters in the local variant of ASCII. Each field within the
78structure is contiguous; that is, there is no padding used within
79the structure. Each character on the archive medium is stored
80contiguously.
81
82Bytes representing the contents of files (after the header block
83of each file) are not translated in any way and are not constrained
84to represent characters in any character set. The @command{tar} format
85does not distinguish text files from binary files, and no translation
86of file contents is performed.
87
88The @code{name}, @code{linkname}, @code{magic}, @code{uname}, and
89@code{gname} are null-terminated character strings. All other fields
90are zero-filled octal numbers in ASCII. Each numeric field of width
91@var{w} contains @var{w} minus 1 digits, and a null.
92
93The @code{name} field is the file name of the file, with directory names
94(if any) preceding the file name, separated by slashes.
95
96@FIXME{how big a name before field overflows?}
97
98The @code{mode} field provides nine bits specifying file permissions
99and three bits to specify the Set UID, Set GID, and Save Text
100(@dfn{sticky}) modes. Values for these bits are defined above.
101When special permissions are required to create a file with a given
102mode, and the user restoring files from the archive does not hold such
103permissions, the mode bit(s) specifying those special permissions
104are ignored. Modes which are not supported by the operating system
105restoring files from the archive will be ignored. Unsupported modes
106should be faked up when creating or updating an archive; e.g., the
107group permission could be copied from the @emph{other} permission.
108
109The @code{uid} and @code{gid} fields are the numeric user and group
110ID of the file owners, respectively. If the operating system does
111not support numeric user or group IDs, these fields should be ignored.
112
113The @code{size} field is the size of the file in bytes; linked files
114are archived with this field specified as zero. @FIXME-xref{Modifiers, in
115particular the @option{--incremental} (@option{-G}) option.}
116
117The @code{mtime} field is the data modification time of the file at
118the time it was archived. It is the ASCII representation of the octal
119value of the last time the file's contents were modified, represented
120as an integer number of
121seconds since January 1, 1970, 00:00 Coordinated Universal Time.
122
123The @code{chksum} field is the ASCII representation of the octal value
124of the simple sum of all bytes in the header block. Each 8-bit
125byte in the header is added to an unsigned integer, initialized to
126zero, the precision of which shall be no less than seventeen bits.
127When calculating the checksum, the @code{chksum} field is treated as
128if it were all blanks.
129
130The @code{typeflag} field specifies the type of file archived. If a
131particular implementation does not recognize or permit the specified
132type, the file will be extracted as if it were a regular file. As this
133action occurs, @command{tar} issues a warning to the standard error.
134
135The @code{atime} and @code{ctime} fields are used in making incremental
136backups; they store, respectively, the particular file's access and
137status change times.
138
139The @code{offset} is used by the @option{--multi-volume} (@option{-M}) option, when
140making a multi-volume archive. The offset is number of bytes into
141the file that we need to restart at to continue the file on the next
142tape, i.e., where we store the location that a continued file is
143continued at.
144
145The following fields were added to deal with sparse files. A file
146is @dfn{sparse} if it takes in unallocated blocks which end up being
147represented as zeros, i.e., no useful data. A test to see if a file
148is sparse is to look at the number blocks allocated for it versus the
149number of characters in the file; if there are fewer blocks allocated
150for the file than would normally be allocated for a file of that
151size, then the file is sparse. This is the method @command{tar} uses to
152detect a sparse file, and once such a file is detected, it is treated
153differently from non-sparse files.
154
155Sparse files are often @code{dbm} files, or other database-type files
156which have data at some points and emptiness in the greater part of
157the file. Such files can appear to be very large when an @samp{ls
158-l} is done on them, when in truth, there may be a very small amount
159of important data contained in the file. It is thus undesirable
160to have @command{tar} think that it must back up this entire file, as
161great quantities of room are wasted on empty blocks, which can lead
162to running out of room on a tape far earlier than is necessary.
163Thus, sparse files are dealt with so that these empty blocks are
164not written to the tape. Instead, what is written to the tape is a
165description, of sorts, of the sparse file: where the holes are, how
166big the holes are, and how much data is found at the end of the hole.
167This way, the file takes up potentially far less room on the tape,
168and when the file is extracted later on, it will look exactly the way
169it looked beforehand. The following is a description of the fields
170used to handle a sparse file:
171
172The @code{sp} is an array of @code{struct sparse}. Each @code{struct
173sparse} contains two 12-character strings which represent an offset
174into the file and a number of bytes to be written at that offset.
175The offset is absolute, and not relative to the offset in preceding
176array element.
177
178The header can hold four of these @code{struct sparse} at the moment;
179if more are needed, they are not stored in the header.
180
181The @code{isextended} flag is set when an @code{extended_header}
182is needed to deal with a file. Note that this means that this flag
183can only be set when dealing with a sparse file, and it is only set
184in the event that the description of the file will not fit in the
185allotted room for sparse structures in the header. In other words,
186an extended_header is needed.
187
188The @code{extended_header} structure is used for sparse files which
189need more sparse structures than can fit in the header. The header can
190fit 4 such structures; if more are needed, the flag @code{isextended}
191gets set and the next block is an @code{extended_header}.
192
193Each @code{extended_header} structure contains an array of 21
194sparse structures, along with a similar @code{isextended} flag
195that the header had. There can be an indeterminate number of such
196@code{extended_header}s to describe a sparse file.
197
198@table @asis
199
200@item @code{REGTYPE}
201@itemx @code{AREGTYPE}
202These flags represent a regular file. In order to be compatible
203with older versions of @command{tar}, a @code{typeflag} value of
204@code{AREGTYPE} should be silently recognized as a regular file.
205New archives should be created using @code{REGTYPE}. Also, for
206backward compatibility, @command{tar} treats a regular file whose name
207ends with a slash as a directory.
208
209@item @code{LNKTYPE}
210This flag represents a file linked to another file, of any type,
211previously archived. Such files are identified in Unix by each
212file having the same device and inode number. The linked-to name is
213specified in the @code{linkname} field with a trailing null.
214
215@item @code{SYMTYPE}
216This represents a symbolic link to another file. The linked-to name
217is specified in the @code{linkname} field with a trailing null.
218
219@item @code{CHRTYPE}
220@itemx @code{BLKTYPE}
221These represent character special files and block special files
222respectively. In this case the @code{devmajor} and @code{devminor}
223fields will contain the major and minor device numbers respectively.
224Operating systems may map the device specifications to their own
225local specification, or may ignore the entry.
226
227@item @code{DIRTYPE}
228This flag specifies a directory or sub-directory. The directory
229name in the @code{name} field should end with a slash. On systems where
230disk allocation is performed on a directory basis, the @code{size} field
231will contain the maximum number of bytes (which may be rounded to
232the nearest disk block allocation unit) which the directory may
233hold. A @code{size} field of zero indicates no such limiting. Systems
234which do not support limiting in this manner should ignore the
235@code{size} field.
236
237@item @code{FIFOTYPE}
238This specifies a FIFO special file. Note that the archiving of a
239FIFO file archives the existence of this file and not its contents.
240
241@item @code{CONTTYPE}
242This specifies a contiguous file, which is the same as a normal
243file except that, in operating systems which support it, all its
244space is allocated contiguously on the disk. Operating systems
245which do not allow contiguous allocation should silently treat this
246type as a normal file.
247
248@item @code{A} @dots{} @code{Z}
249These are reserved for custom implementations. Some of these are
250used in the @acronym{GNU} modified format, as described below.
251
252@end table
253
254Other values are reserved for specification in future revisions of
255the P1003 standard, and should not be used by any @command{tar} program.
256
257The @code{magic} field indicates that this archive was output in
258the P1003 archive format. If this field contains @code{TMAGIC},
259the @code{uname} and @code{gname} fields will contain the ASCII
260representation of the owner and group of the file respectively.
261If found, the user and group IDs are used rather than the values in
262the @code{uid} and @code{gid} fields.
263
264For references, see ISO/IEC 9945-1:1990 or IEEE Std 1003.1-1990, pages
265169-173 (section 10.1) for @cite{Archive/Interchange File Format}; and
266IEEE Std 1003.2-1992, pages 380-388 (section 4.48) and pages 936-940
267(section E.4.48) for @cite{pax - Portable archive interchange}.
268
269@node Extensions
270@unnumberedsec @acronym{GNU} Extensions to the Archive Format
271@UNREVISED
272
273The @acronym{GNU} format uses additional file types to describe new types of
274files in an archive. These are listed below.
275
276@table @code
277@item GNUTYPE_DUMPDIR
278@itemx 'D'
279This represents a directory and a list of files created by the
280@option{--incremental} (@option{-G}) option. The @code{size} field gives the total
281size of the associated list of files. Each file name is preceded by
282either a @samp{Y} (the file should be in this archive) or an @samp{N}.
283(The file is a directory, or is not stored in the archive.) Each file
284name is terminated by a null. There is an additional null after the
285last file name.
286
287@item GNUTYPE_MULTIVOL
288@itemx 'M'
289This represents a file continued from another volume of a multi-volume
290archive created with the @option{--multi-volume} (@option{-M}) option. The original
291type of the file is not given here. The @code{size} field gives the
292maximum size of this piece of the file (assuming the volume does
293not end before the file is written out). The @code{offset} field
294gives the offset from the beginning of the file where this part of
295the file begins. Thus @code{size} plus @code{offset} should equal
296the original size of the file.
297
298@item GNUTYPE_SPARSE
299@itemx 'S'
300This flag indicates that we are dealing with a sparse file. Note
301that archiving a sparse file requires special operations to find
302holes in the file, which mark the positions of these holes, along
303with the number of bytes of data to be found after the hole.
304
305@item GNUTYPE_VOLHDR
306@itemx 'V'
307This file type is used to mark the volume header that was given with
308the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option when the archive was created. The @code{name}
309field contains the @code{name} given after the @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) option.
310The @code{size} field is zero. Only the first file in each volume
311of an archive should have this type.
312
313@end table
314
315You may have trouble reading a @acronym{GNU} format archive on a
316non-@acronym{GNU} system if the options @option{--incremental} (@option{-G}),
317@option{--multi-volume} (@option{-M}), @option{--sparse} (@option{-S}), or @option{--label=@var{archive-label}} (@option{-V @var{archive-label}}) were
318used when writing the archive. In general, if @command{tar} does not
319use the @acronym{GNU}-added fields of the header, other versions of
320@command{tar} should be able to read the archive. Otherwise, the
321@command{tar} program will give an error, the most likely one being a
322checksum error.
323
324@node Sparse Formats
325@unnumberedsec Storing Sparse Files
326@include sparse.texi
327
328@node Snapshot Files
329@unnumberedsec Format of the Incremental Snapshot Files
330@include snapshot.texi
331
332@node Dumpdir
333@unnumberedsec Dumpdir
334@include dumpdir.texi
335
Note: See TracBrowser for help on using the repository browser.