tar.h 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. /*
  2. * Header file for public domain tar (tape archive) program.
  3. *
  4. * @(#)tar.h 1.20 86/10/29 Public Domain.
  5. *
  6. * Created 25 August 1985 by John Gilmore, ihnp4!hoptoad!gnu.
  7. *
  8. * $Id: tar.h,v 1.3 1992/09/08 15:32:41 ian Exp $ # checkin only
  9. */
  10. /*
  11. * Kludge for handling systems that can't cope with multiple
  12. * external definitions of a variable. In ONE routine (tar.c),
  13. * we #define TAR_EXTERN to null; here, we set it to "extern" if
  14. * it is not already set.
  15. */
  16. #ifndef TAR_EXTERN
  17. #define TAR_EXTERN extern
  18. #endif
  19. /*
  20. * Header block on tape.
  21. *
  22. * I'm going to use traditional DP naming conventions here.
  23. * A "block" is a big chunk of stuff that we do I/O on.
  24. * A "record" is a piece of info that we care about.
  25. * Typically many "record"s fit into a "block".
  26. */
  27. #define RECORDSIZE 512
  28. #define NAMSIZ 100
  29. #define TUNMLEN 32
  30. #define TGNMLEN 32
  31. union record {
  32. char charptr[RECORDSIZE];
  33. struct header {
  34. char name[NAMSIZ];
  35. char mode[8];
  36. char uid[8];
  37. char gid[8];
  38. char size[12];
  39. char mtime[12];
  40. char chksum[8];
  41. char linkflag;
  42. char linkname[NAMSIZ];
  43. char magic[8];
  44. char uname[TUNMLEN];
  45. char gname[TGNMLEN];
  46. char devmajor[8];
  47. char devminor[8];
  48. } header;
  49. };
  50. /* The checksum field is filled with this while the checksum is computed. */
  51. #define CHKBLANKS " " /* 8 blanks, no null */
  52. /* The magic field is filled with this if uname and gname are valid. */
  53. #define TMAGIC "ustar " /* 7 chars and a null */
  54. /* The linkflag defines the type of file */
  55. #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
  56. #define LF_NORMAL '0' /* Normal disk file */
  57. #define LF_LINK '1' /* Link to previously dumped file */
  58. #define LF_SYMLINK '2' /* Symbolic link */
  59. #define LF_CHR '3' /* Character special file */
  60. #define LF_BLK '4' /* Block special file */
  61. #define LF_DIR '5' /* Directory */
  62. #define LF_FIFO '6' /* FIFO special file */
  63. #define LF_CONTIG '7' /* Contiguous file */
  64. /* Further link types may be defined later. */
  65. /*
  66. * Exit codes from the "tar" program
  67. */
  68. #define EX_SUCCESS 0 /* success! */
  69. #define EX_ARGSBAD 1 /* invalid args */
  70. #define EX_BADFILE 2 /* invalid filename */
  71. #define EX_BADARCH 3 /* bad archive */
  72. #define EX_SYSTEM 4 /* system gave unexpected error */
  73. /*
  74. * Global variables
  75. */
  76. TAR_EXTERN union record *ar_block; /* Start of block of archive */
  77. TAR_EXTERN union record *ar_record; /* Current record of archive */
  78. TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
  79. TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
  80. TAR_EXTERN int blocking; /* Size of each block, in records */
  81. TAR_EXTERN int blocksize; /* Size of each block, in bytes */
  82. TAR_EXTERN char *ar_file; /* File containing archive */
  83. TAR_EXTERN char *name_file; /* File containing names to work on */
  84. TAR_EXTERN char *tar; /* Name of this program */
  85. /*
  86. * Flags from the command line
  87. */
  88. TAR_EXTERN char f_reblock; /* -B */
  89. TAR_EXTERN char f_create; /* -c */
  90. TAR_EXTERN char f_debug; /* -d */
  91. TAR_EXTERN char f_sayblock; /* -D */
  92. TAR_EXTERN char f_follow_links; /* -h */
  93. TAR_EXTERN char f_ignorez; /* -i */
  94. TAR_EXTERN char f_keep; /* -k */
  95. TAR_EXTERN char f_modified; /* -m */
  96. TAR_EXTERN char f_oldarch; /* -o */
  97. TAR_EXTERN char f_use_protection; /* -p */
  98. TAR_EXTERN char f_sorted_names; /* -s */
  99. TAR_EXTERN char f_list; /* -t */
  100. TAR_EXTERN char f_namefile; /* -T */
  101. TAR_EXTERN char f_verbose; /* -v */
  102. TAR_EXTERN char f_extract; /* -x */
  103. TAR_EXTERN char f_compress; /* -z */
  104. /*
  105. * We now default to Unix Standard format rather than 4.2BSD tar format.
  106. * The code can actually produce all three:
  107. * f_standard ANSI standard
  108. * f_oldarch V7
  109. * neither 4.2BSD
  110. * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  111. * The only advantage to the "neither" option is that we can cmp(1) our
  112. * output to the output of 4.2BSD tar, for debugging.
  113. */
  114. #define f_standard (!f_oldarch)
  115. /*
  116. * Structure for keeping track of filenames and lists thereof.
  117. */
  118. struct name {
  119. struct name *next;
  120. short length;
  121. char found;
  122. char name[NAMSIZ+1];
  123. };
  124. TAR_EXTERN struct name *namelist; /* Points to first name in list */
  125. TAR_EXTERN struct name *namelast; /* Points to last name in list */
  126. TAR_EXTERN int archive; /* File descriptor for archive file */
  127. TAR_EXTERN int errors; /* # of files in error */
  128. /*
  129. *
  130. * Due to the next struct declaration, each routine that includes
  131. * "tar.h" must also include <sys/types.h>. I tried to make it automatic,
  132. * but System V has no defines in <sys/types.h>, so there is no way of
  133. * knowing when it has been included. In addition, it cannot be included
  134. * twice, but must be included exactly once. Argghh!
  135. *
  136. * Thanks, typedef. Thanks, USG.
  137. */
  138. struct link {
  139. struct link *next;
  140. dev_t dev;
  141. ino_t ino;
  142. short linkcount;
  143. char name[NAMSIZ+1];
  144. };
  145. TAR_EXTERN struct link *linklist; /* Points to first link in list */
  146. /*
  147. * Error recovery stuff
  148. */
  149. TAR_EXTERN char read_error_flag;
  150. /*
  151. * Declarations of functions available to the world.
  152. */
  153. /*LINTLIBRARY*/
  154. union record *findrec();
  155. void userec();
  156. union record *endofrecs();
  157. void anno();
  158. #define annorec(stream, msg) anno(stream, msg, 0) /* Cur rec */
  159. #define annofile(stream, msg) anno(stream, msg, 1) /* Saved rec */