tar.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /* Extended tar format from POSIX.1.
  2. Copyright (C) 1992-2020 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. Written by David J. MacKenzie.
  5. The GNU C Library is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU Lesser General Public
  7. License as published by the Free Software Foundation; either
  8. version 2.1 of the License, or (at your option) any later version.
  9. The GNU C Library is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. Lesser General Public License for more details.
  13. You should have received a copy of the GNU Lesser General Public
  14. License along with the GNU C Library; if not, see
  15. <https://www.gnu.org/licenses/>. */
  16. #ifndef _TAR_H
  17. #define _TAR_H 1
  18. #include <features.h>
  19. /* A tar archive consists of 512-byte blocks.
  20. Each file in the archive has a header block followed by 0+ data blocks.
  21. Two blocks of NUL bytes indicate the end of the archive. */
  22. /* The fields of header blocks:
  23. All strings are stored as ISO 646 (approximately ASCII) strings.
  24. Fields are numeric unless otherwise noted below; numbers are ISO 646
  25. representations of octal numbers, with leading zeros as needed.
  26. linkname is only valid when typeflag==LNKTYPE. It doesn't use prefix;
  27. files that are links to pathnames >100 chars long can not be stored
  28. in a tar archive.
  29. If typeflag=={LNKTYPE,SYMTYPE,DIRTYPE} then size must be 0.
  30. devmajor and devminor are only valid for typeflag=={BLKTYPE,CHRTYPE}.
  31. chksum contains the sum of all 512 bytes in the header block,
  32. treating each byte as an 8-bit unsigned value and treating the
  33. 8 bytes of chksum as blank characters.
  34. uname and gname are used in preference to uid and gid, if those
  35. names exist locally.
  36. Field Name Byte Offset Length in Bytes Field Type
  37. name 0 100 NUL-terminated if NUL fits
  38. mode 100 8
  39. uid 108 8
  40. gid 116 8
  41. size 124 12
  42. mtime 136 12
  43. chksum 148 8
  44. typeflag 156 1 see below
  45. linkname 157 100 NUL-terminated if NUL fits
  46. magic 257 6 must be TMAGIC (NUL term.)
  47. version 263 2 must be TVERSION
  48. uname 265 32 NUL-terminated
  49. gname 297 32 NUL-terminated
  50. devmajor 329 8
  51. devminor 337 8
  52. prefix 345 155 NUL-terminated if NUL fits
  53. If the first character of prefix is '\0', the file name is name;
  54. otherwise, it is prefix/name. Files whose pathnames don't fit in that
  55. length can not be stored in a tar archive. */
  56. /* The bits in mode: */
  57. #define TSUID 04000
  58. #define TSGID 02000
  59. #if defined __USE_XOPEN || !defined __USE_XOPEN2K
  60. # define TSVTX 01000
  61. #endif
  62. #define TUREAD 00400
  63. #define TUWRITE 00200
  64. #define TUEXEC 00100
  65. #define TGREAD 00040
  66. #define TGWRITE 00020
  67. #define TGEXEC 00010
  68. #define TOREAD 00004
  69. #define TOWRITE 00002
  70. #define TOEXEC 00001
  71. /* The values for typeflag:
  72. Values 'A'-'Z' are reserved for custom implementations.
  73. All other values are reserved for future POSIX.1 revisions. */
  74. #define REGTYPE '0' /* Regular file (preferred code). */
  75. #define AREGTYPE '\0' /* Regular file (alternate code). */
  76. #define LNKTYPE '1' /* Hard link. */
  77. #define SYMTYPE '2' /* Symbolic link (hard if not supported). */
  78. #define CHRTYPE '3' /* Character special. */
  79. #define BLKTYPE '4' /* Block special. */
  80. #define DIRTYPE '5' /* Directory. */
  81. #define FIFOTYPE '6' /* Named pipe. */
  82. #define CONTTYPE '7' /* Contiguous file */
  83. /* (regular file if not supported). */
  84. /* Contents of magic field and its length. */
  85. #define TMAGIC "ustar"
  86. #define TMAGLEN 6
  87. /* Contents of the version field and its length. */
  88. #define TVERSION "00"
  89. #define TVERSLEN 2
  90. #endif /* tar.h */