intern.texi 16 KB

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