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