tar.h 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293
  1. /* Declarations for tar archives.
  2. Copyright (C) 1988, 1992, 1993 Free Software Foundation
  3. This file is part of GNU Tar.
  4. GNU Tar is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Tar 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
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Tar; see the file COPYING. If not, write to
  14. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
  15. #include "testpad.h"
  16. /* major() and minor() macros (among other things) defined here for hpux */
  17. #ifdef hpux
  18. #include <sys/mknod.h>
  19. #endif
  20. /*
  21. * Kludge for handling systems that can't cope with multiple
  22. * external definitions of a variable. In ONE routine (tar.c),
  23. * we #define TAR_EXTERN to null; here, we set it to "extern" if
  24. * it is not already set.
  25. */
  26. #ifndef TAR_EXTERN
  27. #define TAR_EXTERN extern
  28. #endif
  29. /*
  30. * Header block on tape.
  31. *
  32. * I'm going to use traditional DP naming conventions here.
  33. * A "block" is a big chunk of stuff that we do I/O on.
  34. * A "record" is a piece of info that we care about.
  35. * Typically many "record"s fit into a "block".
  36. */
  37. #define RECORDSIZE 512
  38. #define NAMSIZ 100
  39. #define TUNMLEN 32
  40. #define TGNMLEN 32
  41. #define SPARSE_EXT_HDR 21
  42. #define SPARSE_IN_HDR 4
  43. struct sparse
  44. {
  45. char offset[12];
  46. char numbytes[12];
  47. };
  48. struct sp_array
  49. {
  50. int offset;
  51. int numbytes;
  52. };
  53. union record
  54. {
  55. char charptr[RECORDSIZE];
  56. struct header
  57. {
  58. char arch_name[NAMSIZ];
  59. char mode[8];
  60. char uid[8];
  61. char gid[8];
  62. char size[12];
  63. char mtime[12];
  64. char chksum[8];
  65. char linkflag;
  66. char arch_linkname[NAMSIZ];
  67. char magic[8];
  68. char uname[TUNMLEN];
  69. char gname[TGNMLEN];
  70. char devmajor[8];
  71. char devminor[8];
  72. /* these following fields were added by JF for gnu */
  73. /* and are NOT standard */
  74. char atime[12];
  75. char ctime[12];
  76. char offset[12];
  77. char longnames[4];
  78. #ifdef NEEDPAD
  79. char pad;
  80. #endif
  81. struct sparse sp[SPARSE_IN_HDR];
  82. char isextended;
  83. char realsize[12]; /* true size of the sparse file */
  84. /* char ending_blanks[12];*//* number of nulls at the
  85. end of the file, if any */
  86. }
  87. header;
  88. struct extended_header
  89. {
  90. struct sparse sp[21];
  91. char isextended;
  92. }
  93. ext_hdr;
  94. };
  95. /* The checksum field is filled with this while the checksum is computed. */
  96. #define CHKBLANKS " " /* 8 blanks, no null */
  97. /* The magic field is filled with this if uname and gname are valid. */
  98. #define TMAGIC "ustar " /* 7 chars and a null */
  99. /* The linkflag defines the type of file */
  100. #define LF_OLDNORMAL '\0' /* Normal disk file, Unix compat */
  101. #define LF_NORMAL '0' /* Normal disk file */
  102. #define LF_LINK '1' /* Link to previously dumped file */
  103. #define LF_SYMLINK '2' /* Symbolic link */
  104. #define LF_CHR '3' /* Character special file */
  105. #define LF_BLK '4' /* Block special file */
  106. #define LF_DIR '5' /* Directory */
  107. #define LF_FIFO '6' /* FIFO special file */
  108. #define LF_CONTIG '7' /* Contiguous file */
  109. /* Further link types may be defined later. */
  110. /* Note that the standards committee allows only capital A through
  111. capital Z for user-defined expansion. This means that defining something
  112. as, say '8' is a *bad* idea. */
  113. #define LF_DUMPDIR 'D' /* This is a dir entry that contains
  114. the names of files that were in
  115. the dir at the time the dump
  116. was made */
  117. #define LF_LONGLINK 'K' /* Identifies the NEXT file on the tape
  118. as having a long linkname */
  119. #define LF_LONGNAME 'L' /* Identifies the NEXT file on the tape
  120. as having a long name. */
  121. #define LF_MULTIVOL 'M' /* This is the continuation
  122. of a file that began on another
  123. volume */
  124. #define LF_NAMES 'N' /* For storing filenames that didn't
  125. fit in 100 characters */
  126. #define LF_SPARSE 'S' /* This is for sparse files */
  127. #define LF_VOLHDR 'V' /* This file is a tape/volume header */
  128. /* Ignore it on extraction */
  129. /*
  130. * Exit codes from the "tar" program
  131. */
  132. #define EX_SUCCESS 0 /* success! */
  133. #define EX_ARGSBAD 1 /* invalid args */
  134. #define EX_BADFILE 2 /* invalid filename */
  135. #define EX_BADARCH 3 /* bad archive */
  136. #define EX_SYSTEM 4 /* system gave unexpected error */
  137. #define EX_BADVOL 5 /* Special error code means
  138. Tape volume doesn't match the one
  139. specified on the command line */
  140. /*
  141. * Global variables
  142. */
  143. TAR_EXTERN union record *ar_block; /* Start of block of archive */
  144. TAR_EXTERN union record *ar_record; /* Current record of archive */
  145. TAR_EXTERN union record *ar_last; /* Last+1 record of archive block */
  146. TAR_EXTERN char ar_reading; /* 0 writing, !0 reading archive */
  147. TAR_EXTERN int blocking; /* Size of each block, in records */
  148. TAR_EXTERN int blocksize; /* Size of each block, in bytes */
  149. TAR_EXTERN char *info_script; /* Script to run at end of each tape change */
  150. TAR_EXTERN char *name_file; /* File containing names to work on */
  151. TAR_EXTERN char filename_terminator; /* \n or \0. */
  152. TAR_EXTERN char *tar; /* Name of this program */
  153. TAR_EXTERN struct sp_array *sparsearray; /* Pointer to the start of the scratch space */
  154. TAR_EXTERN int sp_array_size; /* Initial size of the sparsearray */
  155. TAR_EXTERN int tot_written; /* Total written to output */
  156. TAR_EXTERN struct re_pattern_buffer
  157. *label_pattern; /* compiled regex for extract label */
  158. TAR_EXTERN char **ar_files; /* list of tape drive names */
  159. TAR_EXTERN int n_ar_files; /* number of tape drive names */
  160. TAR_EXTERN int cur_ar_file; /* tape drive currently being used */
  161. TAR_EXTERN int ar_files_len; /* malloced size of ar_files */
  162. TAR_EXTERN char *current_file_name, *current_link_name;
  163. /*
  164. * Flags from the command line
  165. */
  166. TAR_EXTERN int cmd_mode;
  167. #define CMD_NONE 0
  168. #define CMD_CAT 1 /* -A */
  169. #define CMD_CREATE 2 /* -c */
  170. #define CMD_DIFF 3 /* -d */
  171. #define CMD_APPEND 4 /* -r */
  172. #define CMD_LIST 5 /* -t */
  173. #define CMD_UPDATE 6 /* -u */
  174. #define CMD_EXTRACT 7 /* -x */
  175. #define CMD_DELETE 8 /* -D */
  176. #define CMD_VERSION 9 /* --version */
  177. TAR_EXTERN int f_reblock; /* -B */
  178. #if 0
  179. TAR_EXTERN char f_dironly; /* -D */
  180. #endif
  181. TAR_EXTERN int f_run_script_at_end; /* -F */
  182. TAR_EXTERN int f_gnudump; /* -G */
  183. TAR_EXTERN int f_follow_links; /* -h */
  184. TAR_EXTERN int f_ignorez; /* -i */
  185. TAR_EXTERN int f_keep; /* -k */
  186. TAR_EXTERN int f_startfile; /* -K */
  187. TAR_EXTERN int f_local_filesys; /* -l */
  188. TAR_EXTERN int tape_length; /* -L */
  189. TAR_EXTERN int f_modified; /* -m */
  190. TAR_EXTERN int f_multivol; /* -M */
  191. TAR_EXTERN int f_new_files; /* -N */
  192. TAR_EXTERN int f_oldarch; /* -o */
  193. TAR_EXTERN int f_exstdout; /* -O */
  194. TAR_EXTERN int f_use_protection;/* -p */
  195. TAR_EXTERN int f_absolute_paths;/* -P */
  196. TAR_EXTERN int f_sayblock; /* -R */
  197. TAR_EXTERN int f_sorted_names; /* -s */
  198. TAR_EXTERN int f_sparse_files; /* -S ... JK */
  199. TAR_EXTERN int f_namefile; /* -T */
  200. TAR_EXTERN int f_verbose; /* -v */
  201. TAR_EXTERN char *f_volhdr; /* -V */
  202. TAR_EXTERN int f_confirm; /* -w */
  203. TAR_EXTERN int f_verify; /* -W */
  204. TAR_EXTERN int f_exclude; /* -X */
  205. TAR_EXTERN char *f_compressprog; /* -z and -Z */
  206. TAR_EXTERN int f_do_chown; /* --do-chown */
  207. TAR_EXTERN int f_totals; /* --totals */
  208. TAR_EXTERN int f_remove_files; /* --remove-files */
  209. TAR_EXTERN int f_ignore_failed_read; /* --ignore-failed-read */
  210. TAR_EXTERN int f_checkpoint; /* --checkpoint */
  211. TAR_EXTERN int f_show_omitted_dirs; /* --show-omitted-dirs */
  212. TAR_EXTERN char *f_volno_file; /* --volno-file */
  213. TAR_EXTERN int f_force_local; /* --force-local */
  214. TAR_EXTERN int f_atime_preserve;/* --atime-preserve */
  215. TAR_EXTERN int f_compress_block; /* --compress-block */
  216. /*
  217. * We default to Unix Standard format rather than 4.2BSD tar format.
  218. * The code can actually produce all three:
  219. * f_standard ANSI standard
  220. * f_oldarch V7
  221. * neither 4.2BSD
  222. * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  223. * The only advantage to the "neither" option is that we can cmp our
  224. * output to the output of 4.2BSD tar, for debugging.
  225. */
  226. #define f_standard (!f_oldarch)
  227. /*
  228. * Structure for keeping track of filenames and lists thereof.
  229. */
  230. struct name
  231. {
  232. struct name *next;
  233. short length; /* cached strlen(name) */
  234. char found; /* A matching file has been found */
  235. char firstch; /* First char is literally matched */
  236. char regexp; /* This name is a regexp, not literal */
  237. char *change_dir; /* JF set with the -C option */
  238. char *dir_contents; /* JF for f_gnudump */
  239. char fake; /* dummy entry */
  240. char name[1];
  241. };
  242. TAR_EXTERN struct name *namelist; /* Points to first name in list */
  243. TAR_EXTERN struct name *namelast; /* Points to last name in list */
  244. TAR_EXTERN int archive; /* File descriptor for archive file */
  245. TAR_EXTERN int errors; /* # of files in error */
  246. TAR_EXTERN char *gnu_dumpfile;
  247. /*
  248. * Error recovery stuff
  249. */
  250. TAR_EXTERN char read_error_flag;
  251. /*
  252. * Declarations of functions available to the world.
  253. */
  254. union record *findrec ();
  255. void userec ();
  256. union record *endofrecs ();
  257. void anno ();
  258. #if defined (HAVE_VPRINTF) && __STDC__
  259. void msg (char *,...);
  260. void msg_perror (char *,...);
  261. #else
  262. void msg ();
  263. void msg_perror ();
  264. #endif