tar.h 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  1. /*
  2. * Copyright (c) Ian F. Darwin 1986-1995.
  3. * Software written by Ian F. Darwin and others;
  4. * maintained 1995-present by Christos Zoulas and others.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice immediately at the beginning of the file, without modification,
  11. * this list of conditions, and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. *
  16. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  17. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
  20. * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  22. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  23. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  24. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  25. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  26. * SUCH DAMAGE.
  27. */
  28. /*
  29. * Header file for public domain tar (tape archive) program.
  30. *
  31. * @(#)tar.h 1.20 86/10/29 Public Domain.
  32. *
  33. * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  34. *
  35. * $Id: tar.h,v 1.8 2004/09/11 19:15:58 christos Exp $ # checkin only
  36. */
  37. /*
  38. * Kludge for handling systems that cannot cope with multiple
  39. * external definitions of a variable. In ONE routine (tar.c),
  40. * we #define TAR_EXTERN to null; here, we set it to "extern" if
  41. * it is not already set.
  42. */
  43. #ifndef TAR_EXTERN
  44. #define TAR_EXTERN extern
  45. #endif
  46. /*
  47. * Header block on tape.
  48. *
  49. * I'm going to use traditional DP naming conventions here.
  50. * A "block" is a big chunk of stuff that we do I/O on.
  51. * A "record" is a piece of info that we care about.
  52. * Typically many "record"s fit into a "block".
  53. */
  54. #define RECORDSIZE 512
  55. #define NAMSIZ 100
  56. #define TUNMLEN 32
  57. #define TGNMLEN 32
  58. union record {
  59. char charptr[RECORDSIZE];
  60. struct header {
  61. char name[NAMSIZ];
  62. char mode[8];
  63. char uid[8];
  64. char gid[8];
  65. char size[12];
  66. char mtime[12];
  67. char chksum[8];
  68. char linkflag;
  69. char linkname[NAMSIZ];
  70. char magic[8];
  71. char uname[TUNMLEN];
  72. char gname[TGNMLEN];
  73. char devmajor[8];
  74. char devminor[8];
  75. } header;
  76. };
  77. /* The checksum field is filled with this while the checksum is computed. */
  78. #define CHKBLANKS " " /* 8 blanks, no null */
  79. /* The magic field is filled with this if uname and gname are valid. */
  80. #define TMAGIC "ustar " /* 7 chars and a null */
  81. /* The linkflag defines the type of file */
  82. #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
  83. #define LF_NORMAL '0' /* Normal disk file */
  84. #define LF_LINK '1' /* Link to previously dumped file */
  85. #define LF_SYMLINK '2' /* Symbolic link */
  86. #define LF_CHR '3' /* Character special file */
  87. #define LF_BLK '4' /* Block special file */
  88. #define LF_DIR '5' /* Directory */
  89. #define LF_FIFO '6' /* FIFO special file */
  90. #define LF_CONTIG '7' /* Contiguous file */
  91. /* Further link types may be defined later. */
  92. /*
  93. * Exit codes from the "tar" program
  94. */
  95. #define EX_SUCCESS 0 /* success! */
  96. #define EX_ARGSBAD 1 /* invalid args */
  97. #define EX_BADFILE 2 /* invalid filename */
  98. #define EX_BADARCH 3 /* bad archive */
  99. #define EX_SYSTEM 4 /* system gave unexpected error */
  100. /*
  101. * Global variables
  102. */
  103. TAR_EXTERN union record *ar_block; /* Start of block of archive */
  104. TAR_EXTERN union record *ar_record; /* Current record of archive */
  105. TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
  106. TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
  107. TAR_EXTERN int blocking; /* Size of each block, in records */
  108. TAR_EXTERN int blocksize; /* Size of each block, in bytes */
  109. TAR_EXTERN char *ar_file; /* File containing archive */
  110. TAR_EXTERN char *name_file; /* File containing names to work on */
  111. TAR_EXTERN char *tar; /* Name of this program */
  112. /*
  113. * Flags from the command line
  114. */
  115. TAR_EXTERN char f_reblock; /* -B */
  116. TAR_EXTERN char f_create; /* -c */
  117. TAR_EXTERN char f_debug; /* -d */
  118. TAR_EXTERN char f_sayblock; /* -D */
  119. TAR_EXTERN char f_follow_links; /* -h */
  120. TAR_EXTERN char f_ignorez; /* -i */
  121. TAR_EXTERN char f_keep; /* -k */
  122. TAR_EXTERN char f_modified; /* -m */
  123. TAR_EXTERN char f_oldarch; /* -o */
  124. TAR_EXTERN char f_use_protection; /* -p */
  125. TAR_EXTERN char f_sorted_names; /* -s */
  126. TAR_EXTERN char f_list; /* -t */
  127. TAR_EXTERN char f_namefile; /* -T */
  128. TAR_EXTERN char f_verbose; /* -v */
  129. TAR_EXTERN char f_extract; /* -x */
  130. TAR_EXTERN char f_compress; /* -z */
  131. /*
  132. * We now default to Unix Standard format rather than 4.2BSD tar format.
  133. * The code can actually produce all three:
  134. * f_standard ANSI standard
  135. * f_oldarch V7
  136. * neither 4.2BSD
  137. * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  138. * The only advantage to the "neither" option is that we can cmp(1) our
  139. * output to the output of 4.2BSD tar, for debugging.
  140. */
  141. #define f_standard (!f_oldarch)
  142. /*
  143. * Structure for keeping track of filenames and lists thereof.
  144. */
  145. struct name {
  146. struct name *next;
  147. short length;
  148. char found;
  149. char name[NAMSIZ+1];
  150. };
  151. TAR_EXTERN struct name *namelist; /* Points to first name in list */
  152. TAR_EXTERN struct name *namelast; /* Points to last name in list */
  153. TAR_EXTERN int archive; /* File descriptor for archive file */
  154. TAR_EXTERN int errors; /* # of files in error */
  155. /*
  156. *
  157. * Due to the next struct declaration, each routine that includes
  158. * "tar.h" must also include <sys/types.h>. I tried to make it automatic,
  159. * but System V has no defines in <sys/types.h>, so there is no way of
  160. * knowing when it has been included. In addition, it cannot be included
  161. * twice, but must be included exactly once. Argghh!
  162. *
  163. * Thanks, typedef. Thanks, USG.
  164. */
  165. struct link {
  166. struct link *next;
  167. dev_t dev;
  168. ino_t ino;
  169. short linkcount;
  170. char name[NAMSIZ+1];
  171. };
  172. TAR_EXTERN struct link *linklist; /* Points to first link in list */
  173. /*
  174. * Error recovery stuff
  175. */
  176. TAR_EXTERN char read_error_flag;
  177. #if 0
  178. /*
  179. * Declarations of functions available to the world.
  180. */
  181. /*LINTLIBRARY*/
  182. #define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */
  183. #define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */
  184. #endif