tar.h 3.7 KB

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