home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / tar-1.11.8-src.tgz / tar.out / fsf / tar / src / tar.h < prev    next >
C/C++ Source or Header  |  1996-09-28  |  14KB  |  467 lines

  1. /* Declarations for tar archives.
  2.    Copyright (C) 1988, 1992, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4.    This file is part of GNU Tar.
  5.  
  6.    GNU Tar is free software; you can redistribute it and/or modify
  7.    it under the terms of the GNU General Public License as published by
  8.    the Free Software Foundation; either version 2, or (at your option)
  9.    any later version.
  10.  
  11.    GNU Tar is distributed in the hope that it will be useful,
  12.    but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.    GNU General Public License for more details.
  15.  
  16.    You should have received a copy of the GNU General Public License
  17.    along with GNU Tar; see the file COPYING.  If not, write to
  18.    the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. /* Standard Archive Format - Standard TAR - USTAR.  */
  21.  
  22. /* Header block on tape.
  23.    
  24.    We use traditional DP naming conventions here.  A "block" is a big chunk
  25.    of stuff that we do I/O on.  A "record" is a piece of info that we care
  26.    about.  Typically many "record"s fit into a "block".  */
  27.  
  28. #define RECORDSIZE    512
  29. #define NAMSIZ        100
  30. #define TUNMLEN        32
  31. #define TGNMLEN        32
  32. #define SPARSE_EXT_HDR    21
  33. #define SPARSE_IN_HDR    4
  34.  
  35. struct sparse
  36.   {
  37.     char offset[12];
  38.     char numbytes[12];
  39.   };
  40.  
  41. union record
  42.   {
  43.     char charptr[RECORDSIZE];
  44.  
  45.     struct header
  46.       {
  47.     char arch_name[NAMSIZ];
  48.     char mode[8];
  49.     char uid[8];
  50.     char gid[8];
  51.     char size[12];
  52.     char mtime[12];
  53.     char chksum[8];
  54.     char linkflag;
  55.     char arch_linkname[NAMSIZ];
  56.     char magic[8];
  57.     char uname[TUNMLEN];
  58.     char gname[TGNMLEN];
  59.     char devmajor[8];
  60.     char devminor[8];
  61.  
  62.     /* The following fields were added for GNU and are not standard.  */
  63.  
  64.     char atime[12];
  65.     char ctime[12];
  66.     char offset[12];
  67.     char longnames[4];
  68.     /* Some compilers would insert the pad themselves, so pad was
  69.        once autoconfigured.  It is simpler to always insert it!  */
  70.     char pad;
  71.     struct sparse sp[SPARSE_IN_HDR];
  72.     char isextended;
  73.     char realsize[12];    /* true size of the sparse file */
  74. #if 0
  75.     char ending_blanks[12];    /* number of nulls at the end of the file,
  76.                    if any */
  77. #endif
  78.       }
  79.     header;
  80.  
  81.     struct extended_header
  82.       {
  83.     struct sparse sp[21];
  84.     char isextended;
  85.       }
  86.     ext_hdr;
  87.   };
  88.  
  89. /* The checksum field is filled with this while the checksum is computed.  */
  90. #define CHKBLANKS    "        "    /* 8 blanks, no null */
  91.  
  92. /* The magic field is filled with this value if uname and gname are valid,
  93.    marking the archive as being in standard POSIX format (though GNU tar
  94.    itself is not POSIX conforming).  */
  95. #define TMAGIC "ustar  "    /* 7 chars and a null */
  96.  
  97. /* The magic field is filled with this if this is a GNU format dump entry.
  98.    But I suspect this is not true anymore.  */
  99. #define GNUMAGIC "GNUtar "    /* 7 chars and a null */
  100.  
  101. /* The linkflag defines the type of file.  */
  102. #define LF_OLDNORMAL    '\0'    /* normal disk file, Unix compat */
  103. #define LF_NORMAL    '0'    /* normal disk file */
  104. #define LF_LINK        '1'    /* link to previously dumped file */
  105. #define LF_SYMLINK    '2'    /* symbolic link */
  106. #define LF_CHR        '3'    /* character special file */
  107. #define LF_BLK        '4'    /* block special file */
  108. #define LF_DIR        '5'    /* directory */
  109. #define LF_FIFO        '6'    /* FIFO special file */
  110. #define LF_CONTIG    '7'    /* contiguous file */
  111. /* Further link types may be defined later.  */
  112.  
  113. /* Note that the standards committee allows only capital A through
  114.    capital Z for user-defined expansion.  This means that defining
  115.    something as, say '8' is a *bad* idea.  */
  116.  
  117. /* This is a dir entry that contains the names of files that were in the
  118.    dir at the time the dump was made.  */
  119. #define LF_DUMPDIR    'D'
  120.  
  121. /* Identifies the NEXT file on the tape as having a long linkname.  */
  122. #define LF_LONGLINK    'K'
  123.  
  124. /* Identifies the NEXT file on the tape as having a long name.  */
  125. #define LF_LONGNAME    'L'
  126.  
  127. /* This is the continuation of a file that began on another volume.  */
  128. #define LF_MULTIVOL    'M'
  129.  
  130. /* For storing filenames that didn't fit in 100 characters.  */
  131. #define LF_NAMES    'N'
  132.  
  133. /* This is for sparse files.  */
  134. #define LF_SPARSE    'S'
  135.  
  136. /* This file is a tape/volume header.  Ignore it on extraction.  */
  137. #define LF_VOLHDR    'V'
  138.  
  139. #if 0
  140. /* The following two blocks of #define's are unused in GNU tar.  */
  141.  
  142. /* Bits used in the mode field - values in octal */
  143. #define  TSUID    04000        /* set UID on execution */
  144. #define  TSGID    02000        /* set GID on execution */
  145. #define  TSVTX    01000        /* save text (sticky bit) */
  146.  
  147. /* File permissions */
  148. #define  TUREAD   00400        /* read by owner */
  149. #define  TUWRITE  00200        /* write by owner */
  150. #define  TUEXEC   00100        /* execute/search by owner */
  151. #define  TGREAD   00040        /* read by group */
  152. #define  TGWRITE  00020        /* write by group */
  153. #define  TGEXEC   00010        /* execute/search by group */
  154. #define  TOREAD   00004        /* read by other */
  155. #define  TOWRITE  00002        /* write by other */
  156. #define  TOEXEC   00001        /* execute/search by other */
  157.  
  158. #endif
  159.  
  160. /* End of Standard Archive Format description.  */
  161.  
  162. /* Kludge for handling systems that can't cope with multiple external
  163.    definitions of a variable.  In ONE routine (tar.c), we #define GLOBAL to
  164.    null; here, we set it to "extern" if it is not already set.  */
  165.  
  166. #ifndef GLOBAL
  167. # define GLOBAL extern
  168. #endif
  169.  
  170. /* Exit status for GNU tar.  Let's try to keep this list as simple as
  171.    possible.  -d option strongly invites a different status for unequal
  172.    comparison and other errors.  */
  173.  
  174. #define TAREXIT_SUCCESS 0
  175. #define TAREXIT_DIFFERS 1
  176. #define TAREXIT_FAILURE 2
  177.  
  178. /* Global variables.  */
  179.  
  180. struct sp_array
  181.   {
  182.     off_t offset;
  183.     int numbytes;
  184.   };
  185.  
  186. /* Start of block of archive.  */
  187. GLOBAL union record *ar_block;
  188.  
  189. /* Current record of archive.  */
  190. GLOBAL union record *ar_record;
  191.  
  192. /* Last+1 record of archive block.  */
  193. GLOBAL union record *ar_last;
  194.  
  195. /* 0 writing, !0 reading archive.  */
  196. GLOBAL char ar_reading;
  197.  
  198. /* Size of each block, in records.  */
  199. GLOBAL int blocking;
  200.  
  201. /* Size of each block, in bytes.  */
  202. GLOBAL int blocksize;
  203.  
  204. /* Script to run at end of each tape change.  */
  205. GLOBAL char *info_script;
  206.  
  207. /* File containing names to work on.  */
  208. GLOBAL const char *namefile_name;
  209.  
  210. /* \n or \0.  */
  211. GLOBAL char filename_terminator;
  212.  
  213. /* Name of this program.  */
  214. GLOBAL const char *program_name;
  215.  
  216. /* Pointer to the start of the scratch space.  */
  217. GLOBAL struct sp_array *sparsearray;
  218.  
  219. /* Initial size of the sparsearray.  */
  220. GLOBAL int sp_array_size;
  221.  
  222. /* Total written to output.  */
  223. GLOBAL int tot_written;
  224.  
  225. /* Compiled regex for extract label.  */
  226. GLOBAL struct re_pattern_buffer *label_pattern;
  227.  
  228. /* List of tape drive names, number of such tape drives, allocated number,
  229.    and current cursor in list.  */
  230. GLOBAL const char **archive_name_array;
  231. GLOBAL int archive_names;
  232. GLOBAL int allocated_archive_names;
  233. GLOBAL const char **archive_name_cursor;
  234.  
  235. GLOBAL char *current_file_name;
  236. GLOBAL char *current_link_name;
  237.  
  238. /* Flags from the command line.  */
  239.  
  240. GLOBAL int command_mode;
  241. #define COMMAND_NONE    0    /* None of the following were specified */
  242. #define COMMAND_TOO_MANY 1    /* More than one of the following were given */
  243. #define COMMAND_CAT    2    /* -A */
  244. #define COMMAND_CREATE    3    /* -c */
  245. #define COMMAND_DIFF    4    /* -d */
  246. #define COMMAND_APPEND    5    /* -r */
  247. #define COMMAND_LIST    6    /* -t */
  248. #define COMMAND_UPDATE    7    /* -u */
  249. #define COMMAND_EXTRACT    8    /* -x */
  250. #define COMMAND_DELETE    9    /* -D */
  251.  
  252. GLOBAL int flag_reblock;    /* -B */
  253. #if 0
  254. GLOBAL char flag_dironly;    /* -D */
  255. #endif
  256. GLOBAL int flag_run_script_at_end; /* -F */
  257. GLOBAL int flag_gnudump;    /* -G */
  258. GLOBAL int flag_follow_links;    /* -h */
  259. GLOBAL int flag_ignorez;    /* -i */
  260. GLOBAL int flag_keep;        /* -k */
  261. GLOBAL int flag_startfile;    /* -K */
  262. GLOBAL int flag_local_filesys;    /* -l */
  263. GLOBAL int tape_length;        /* -L */
  264. GLOBAL int flag_modified;    /* -m */
  265. GLOBAL int flag_multivol;    /* -M */
  266. GLOBAL int flag_new_files;    /* -N */
  267. GLOBAL int flag_oldarch;    /* -o */
  268. GLOBAL int flag_exstdout;    /* -O */
  269. GLOBAL int flag_use_protection; /* -p */
  270. GLOBAL int flag_absolute_names; /* -P */
  271. GLOBAL int flag_sayblock;    /* -R */
  272. GLOBAL int flag_sorted_names;    /* -s */
  273. GLOBAL int flag_sparse_files;    /* -S */
  274. GLOBAL int flag_namefile;    /* -T */
  275. GLOBAL int flag_verbose;    /* -v */
  276. GLOBAL char *flag_volhdr;    /* -V */
  277. GLOBAL int flag_confirm;    /* -w */
  278. GLOBAL int flag_verify;        /* -W */
  279. GLOBAL int flag_exclude;    /* -X */
  280. GLOBAL const char *flag_compressprog; /* -z and -Z */
  281. GLOBAL const char *flag_rsh_command; /* --rsh-command */
  282. GLOBAL int flag_do_chown;    /* --do-chown */
  283. GLOBAL int flag_totals;        /* --totals */
  284. GLOBAL int flag_remove_files;    /* --remove-files */
  285. GLOBAL int flag_ignore_failed_read; /* --ignore-failed-read */
  286. GLOBAL int flag_checkpoint;    /* --checkpoint */
  287. GLOBAL int flag_show_omitted_dirs; /* --show-omitted-dirs */
  288. GLOBAL char *flag_volno_file;    /* --volno-file */
  289. GLOBAL int flag_force_local;    /* --force-local */
  290. GLOBAL int flag_atime_preserve; /* --atime-preserve */
  291. GLOBAL int flag_compress_block; /* --compress-block */
  292.  
  293. /* We default to Unix Standard format rather than 4.2BSD tar format.  The
  294.    code can actually produce all three:
  295.  
  296.     flag_standard    ANSI standard
  297.     flag_oldarch    V7
  298.     neither        4.2BSD
  299.  
  300.    but we don't bother, since 4.2BSD can read ANSI standard format
  301.    anyway.  The only advantage to the "neither" option is that we can cmp
  302.    our output to the output of 4.2BSD tar, for debugging.  */
  303.  
  304. #define flag_standard        (!flag_oldarch)
  305.  
  306. /* Structure for keeping track of filenames and lists thereof.  */
  307.  
  308. struct name
  309.   {
  310.     struct name *next;
  311.     short length;        /* cached strlen(name) */
  312.     char found;            /* a matching file has been found */
  313.     char firstch;        /* first char is literally matched */
  314.     char regexp;        /* this name is a regexp, not literal */
  315.     char *change_dir;        /* JF set with the -C option */
  316.     char *dir_contents;        /* JF for flag_gnudump */
  317.     char fake;            /* dummy entry */
  318.     char name[1];
  319.   };
  320.  
  321. GLOBAL struct name *namelist;    /* points to first name in list */
  322. GLOBAL struct name *namelast;    /* points to last name in list */
  323.  
  324. GLOBAL int archive;        /* file descriptor for archive file */
  325.  
  326. GLOBAL int exit_status;        /* status for exit when tar finishes */
  327.  
  328. GLOBAL char *gnu_dumpfile;
  329.  
  330. /* Error recovery stuff.  */
  331.  
  332. GLOBAL char read_error_flag;
  333.  
  334. #define WARN(Args) error Args
  335. #define ERROR(Args) (error Args, exit_status = TAREXIT_FAILURE)
  336.  
  337. /* Module buffer.c.  */
  338.  
  339. extern long baserec;
  340. extern FILE *stdlis;
  341. extern char *save_name;
  342. extern long save_sizeleft;
  343. extern long save_totsize;
  344. extern int write_archive_to_stdout;
  345.  
  346. void close_archive __P ((void));
  347. void closeout_volume_number __P ((void));
  348. union record *endofrecs __P ((void));
  349. union record *findrec __P ((void));
  350. void fl_read __P ((void));
  351. void fl_write __P ((void));
  352. void flush_archive __P ((void));
  353. void init_volume_number __P ((void));
  354. int isfile __P ((const char *));
  355. int no_op __P ((int, char *));
  356. void open_archive __P ((int));
  357. void reset_eof __P ((void));
  358. void saverec __P ((union record **));
  359. void userec __P ((union record *));
  360. int wantbytes __P ((long, int (*) ()));
  361.  
  362. /* Module create.c.  */
  363.  
  364. void create_archive __P ((void));
  365. void dump_file __P ((char *, int, int));
  366. void finish_header __P ((union record *));
  367. void to_oct __P ((long, int, char *));
  368. void write_eot __P ((void));
  369.  
  370. /* Module diffarch.c.  */
  371.  
  372. extern int now_verifying;
  373.  
  374. void diff_archive __P ((void));
  375. void diff_init __P ((void));
  376. void verify_volume __P ((void));
  377.  
  378. /* Module extract.c.  */
  379.  
  380. void extr_init __P ((void));
  381. void extract_archive __P ((void));
  382. void restore_saved_dir_info __P ((void));
  383.  
  384. /* Module gnu.c.  */
  385.  
  386. void collect_and_sort_names __P ((void));
  387. char *get_dir_contents __P ((char *, int));
  388. void gnu_restore __P ((int));
  389. int is_dot_or_dotdot __P ((char *));
  390. void write_dir_file __P ((void));
  391.  
  392. /* Module list.c.  */
  393.  
  394. extern union record *head;
  395. extern struct stat hstat;
  396. extern int head_standard;
  397.  
  398. void decode_header __P ((union record *, struct stat *, int *, int));
  399. long from_oct __P ((int, char *));
  400. void list_archive __P ((void));
  401. void pr_mkdir __P ((char *, int, int));
  402. void print_header __P ((void));
  403. void read_and __P ((void (*do_) ()));
  404. int read_header __P ((void));
  405. void skip_extended_headers __P ((void));
  406. void skip_file __P ((long));
  407.  
  408. /* Module mangle.c.  */
  409.  
  410. void extract_mangle __P ((void));
  411.  
  412. /* Module names.c.  */
  413.  
  414. int findgid __P ((char gname[TUNMLEN]));
  415. void findgname __P ((char gname[TGNMLEN], int));
  416. int finduid __P ((char uname[TUNMLEN]));
  417. void finduname __P ((char uname[TUNMLEN], int));
  418.  
  419. /* Module port.c.  */
  420.  
  421. extern char TTY_NAME[];
  422.  
  423. void add_buffer __P ((char *, const char *, int));
  424. void ck_close __P ((int));
  425. voidstar ck_malloc __P ((size_t));
  426. void ck_pipe __P ((int *));
  427. void flush_buffer __P ((char *));
  428. char *get_buffer __P ((char *));
  429. char *init_buffer __P ((void));
  430. char *merge_sort __P ((char *, unsigned, int, int (*) ()));
  431. char *quote_copy_string __P ((const char *));
  432. char *un_quote_string __P ((char *));
  433.  
  434. /* Module rtapelib.c.  */
  435.  
  436. int __rmt_close __P ((int));
  437. long __rmt_lseek __P ((int, off_t, int));
  438. int __rmt_open __P ((const char *, int, int, const char *));
  439. int __rmt_read __P ((int, char *, unsigned int));
  440. int __rmt_write __P ((int, char *, unsigned int));
  441.  
  442. /* Module tar.c.  */
  443.  
  444. extern time_t new_time;
  445.  
  446. void addname __P ((const char *));
  447. void assign_string __P ((char **, const char *));
  448. void blank_name_list __P ((void));
  449. int check_exclude __P ((const char *));
  450. int confirm __P ((const char *, const char *));
  451. void name_close __P ((void));
  452. void name_expand __P ((void));
  453. char *name_from_list __P ((void));
  454. void name_gather __P ((void));
  455. int name_match __P ((const char *));
  456. char *name_next __P ((int change_));
  457. struct name *name_scan __P ((const char *));
  458. void names_notfound __P ((void));
  459. char *new_name __P ((char *, char *));
  460.  
  461. /* Module update.c.  */
  462.  
  463. extern char *output_start;
  464.  
  465. void junk_archive __P ((void));
  466. void update_archive __P ((void));
  467.