tar.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241
  1. /* Format of tar archives.
  2. Copyright (C) 1988, 92, 93, 94, 96, 97 Free Software Foundation, Inc.
  3. This program is free software; you can redistribute it and/or modify it
  4. under the terms of the GNU General Public License as published by the
  5. Free Software Foundation; either version 2, or (at your option) any later
  6. version.
  7. This program is distributed in the hope that it will be useful, but
  8. WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
  10. Public License for more details.
  11. You should have received a copy of the GNU General Public License along
  12. with this program; if not, write to the Free Software Foundation, Inc.,
  13. 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
  14. /* GNU tar Archive Format description. */
  15. /* If OLDGNU_COMPATIBILITY is not zero, tar produces archives which, by
  16. default, are readable by older versions of GNU tar. This can be
  17. overriden by using --posix; in this case, POSIXLY_CORRECT in environment
  18. may be set for enforcing stricter conformance. If OLDGNU_COMPATIBILITY
  19. is zero or undefined, tar will eventually produces archives which, by
  20. default, POSIX compatible; then either using --posix or defining
  21. POSIXLY_CORRECT enforces stricter conformance.
  22. This #define will disappear in a few years. FP, June 1995. */
  23. #define OLDGNU_COMPATIBILITY 1
  24. /*---------------------------------------------.
  25. | `tar' Header Block, from POSIX 1003.1-1990. |
  26. `---------------------------------------------*/
  27. /* POSIX header. */
  28. struct posix_header
  29. { /* byte offset */
  30. char name[100]; /* 0 */
  31. char mode[8]; /* 100 */
  32. char uid[8]; /* 108 */
  33. char gid[8]; /* 116 */
  34. char size[12]; /* 124 */
  35. char mtime[12]; /* 136 */
  36. char chksum[8]; /* 148 */
  37. char typeflag; /* 156 */
  38. char linkname[100]; /* 157 */
  39. char magic[6]; /* 257 */
  40. char version[2]; /* 263 */
  41. char uname[32]; /* 265 */
  42. char gname[32]; /* 297 */
  43. char devmajor[8]; /* 329 */
  44. char devminor[8]; /* 337 */
  45. char prefix[155]; /* 345 */
  46. /* 500 */
  47. };
  48. #define TMAGIC "ustar" /* ustar and a null */
  49. #define TMAGLEN 6
  50. #define TVERSION "00" /* 00 and no null */
  51. #define TVERSLEN 2
  52. /* Values used in typeflag field. */
  53. #define REGTYPE '0' /* regular file */
  54. #define AREGTYPE '\0' /* regular file */
  55. #define LNKTYPE '1' /* link */
  56. #define SYMTYPE '2' /* reserved */
  57. #define CHRTYPE '3' /* character special */
  58. #define BLKTYPE '4' /* block special */
  59. #define DIRTYPE '5' /* directory */
  60. #define FIFOTYPE '6' /* FIFO special */
  61. #define CONTTYPE '7' /* reserved */
  62. /* Bits used in the mode field, values in octal. */
  63. #define TSUID 04000 /* set UID on execution */
  64. #define TSGID 02000 /* set GID on execution */
  65. #define TSVTX 01000 /* reserved */
  66. /* file permissions */
  67. #define TUREAD 00400 /* read by owner */
  68. #define TUWRITE 00200 /* write by owner */
  69. #define TUEXEC 00100 /* execute/search by owner */
  70. #define TGREAD 00040 /* read by group */
  71. #define TGWRITE 00020 /* write by group */
  72. #define TGEXEC 00010 /* execute/search by group */
  73. #define TOREAD 00004 /* read by other */
  74. #define TOWRITE 00002 /* write by other */
  75. #define TOEXEC 00001 /* execute/search by other */
  76. /*-------------------------------------.
  77. | `tar' Header Block, GNU extensions. |
  78. `-------------------------------------*/
  79. /* In GNU tar, SYMTYPE is for to symbolic links, and CONTTYPE is for
  80. contiguous files, so maybe disobeying the `reserved' comment in POSIX
  81. header description. I suspect these were meant to be used this way, and
  82. should not have really been `reserved' in the published standards. */
  83. /* *BEWARE* *BEWARE* *BEWARE* that the following information is still
  84. boiling, and may change. Even if the OLDGNU format description should be
  85. accurate, the so-called GNU format is not yet fully decided. It is
  86. surely meant to use only extensions allowed by POSIX, but the sketch
  87. below repeats some ugliness from the OLDGNU format, which should rather
  88. go away. Sparse files should be saved in such a way that they do *not*
  89. require two passes at archive creation time. Huge files get some POSIX
  90. fields to overflow, alternate solutions have to be sought for this. */
  91. /* Descriptor for a single file hole. */
  92. struct sparse
  93. { /* byte offset */
  94. char offset[12]; /* 0 */
  95. char numbytes[12]; /* 12 */
  96. /* 24 */
  97. };
  98. /* Sparse files are not supported in POSIX ustar format. For sparse files
  99. with a POSIX header, a GNU extra header is provided which holds overall
  100. sparse information and a few sparse descriptors. When an old GNU header
  101. replaces both the POSIX header and the GNU extra header, it holds some
  102. sparse descriptors too. Whether POSIX or not, if more sparse descriptors
  103. are still needed, they are put into as many successive sparse headers as
  104. necessary. The following constants tell how many sparse descriptors fit
  105. in each kind of header able to hold them. */
  106. #define SPARSES_IN_EXTRA_HEADER 16
  107. #define SPARSES_IN_OLDGNU_HEADER 4
  108. #define SPARSES_IN_SPARSE_HEADER 21
  109. /* The GNU extra header contains some information GNU tar needs, but not
  110. foreseen in POSIX header format. It is only used after a POSIX header
  111. (and never with old GNU headers), and immediately follows this POSIX
  112. header, when typeflag is a letter rather than a digit, so signaling a GNU
  113. extension. */
  114. struct extra_header
  115. { /* byte offset */
  116. char atime[12]; /* 0 */
  117. char ctime[12]; /* 12 */
  118. char offset[12]; /* 24 */
  119. char realsize[12]; /* 36 */
  120. char longnames[4]; /* 48 */
  121. char unused_pad1[68]; /* 52 */
  122. struct sparse sp[SPARSES_IN_EXTRA_HEADER];
  123. /* 120 */
  124. char isextended; /* 504 */
  125. /* 505 */
  126. };
  127. /* Extension header for sparse files, used immediately after the GNU extra
  128. header, and used only if all sparse information cannot fit into that
  129. extra header. There might even be many such extension headers, one after
  130. the other, until all sparse information has been recorded. */
  131. struct sparse_header
  132. { /* byte offset */
  133. struct sparse sp[SPARSES_IN_SPARSE_HEADER];
  134. /* 0 */
  135. char isextended; /* 504 */
  136. /* 505 */
  137. };
  138. /* The old GNU format header conflicts with POSIX format in such a way that
  139. POSIX archives may fool old GNU tar's, and POSIX tar's might well be
  140. fooled by old GNU tar archives. An old GNU format header uses the space
  141. used by the prefix field in a POSIX header, and cumulates information
  142. normally found in a GNU extra header. With an old GNU tar header, we
  143. never see any POSIX header nor GNU extra header. Supplementary sparse
  144. headers are allowed, however. */
  145. struct oldgnu_header
  146. { /* byte offset */
  147. char unused_pad1[345]; /* 0 */
  148. char atime[12]; /* 345 */
  149. char ctime[12]; /* 357 */
  150. char offset[12]; /* 369 */
  151. char longnames[4]; /* 381 */
  152. char unused_pad2; /* 385 */
  153. struct sparse sp[SPARSES_IN_OLDGNU_HEADER];
  154. /* 386 */
  155. char isextended; /* 482 */
  156. char realsize[12]; /* 483 */
  157. /* 495 */
  158. };
  159. /* OLDGNU_MAGIC uses both magic and version fields, which are contiguous.
  160. Found in an archive, it indicates an old GNU header format, which will be
  161. hopefully become obsolescent. With OLDGNU_MAGIC, uname and gname are
  162. valid, though the header is not truly POSIX conforming. */
  163. #define OLDGNU_MAGIC "ustar " /* 7 chars and a null */
  164. /* The standards committee allows only capital A through capital Z for
  165. user-defined expansion. */
  166. /* This is a dir entry that contains the names of files that were in the
  167. dir at the time the dump was made. */
  168. #define GNUTYPE_DUMPDIR 'D'
  169. /* Identifies the *next* file on the tape as having a long linkname. */
  170. #define GNUTYPE_LONGLINK 'K'
  171. /* Identifies the *next* file on the tape as having a long name. */
  172. #define GNUTYPE_LONGNAME 'L'
  173. /* This is the continuation of a file that began on another volume. */
  174. #define GNUTYPE_MULTIVOL 'M'
  175. /* For storing filenames that do not fit into the main header. */
  176. #define GNUTYPE_NAMES 'N'
  177. /* This is for sparse files. */
  178. #define GNUTYPE_SPARSE 'S'
  179. /* This file is a tape/volume header. Ignore it on extraction. */
  180. #define GNUTYPE_VOLHDR 'V'
  181. /*--------------------------------------.
  182. | tar Header Block, overall structure. |
  183. `--------------------------------------*/
  184. /* tar files are made in basic blocks of this size. */
  185. #define BLOCKSIZE 512
  186. enum archive_format
  187. {
  188. DEFAULT_FORMAT, /* format to be decided later */
  189. V7_FORMAT, /* old V7 tar format */
  190. OLDGNU_FORMAT, /* GNU format as per before tar 1.12 */
  191. POSIX_FORMAT, /* restricted, pure POSIX format */
  192. GNU_FORMAT /* POSIX format with GNU extensions */
  193. };
  194. union block
  195. {
  196. char buffer[BLOCKSIZE];
  197. struct posix_header header;
  198. struct extra_header extra_header;
  199. struct oldgnu_header oldgnu_header;
  200. struct sparse_header sparse_header;
  201. };
  202. /* End of Format description. */