1*0a6a1f1dSLionel Sambuc /* $NetBSD: options.c,v 1.116 2015/04/11 15:41:33 christos Exp $ */
285fee539SLionel Sambuc
385fee539SLionel Sambuc /*-
485fee539SLionel Sambuc * Copyright (c) 1992 Keith Muller.
585fee539SLionel Sambuc * Copyright (c) 1992, 1993
685fee539SLionel Sambuc * The Regents of the University of California. All rights reserved.
785fee539SLionel Sambuc *
885fee539SLionel Sambuc * This code is derived from software contributed to Berkeley by
985fee539SLionel Sambuc * Keith Muller of the University of California, San Diego.
1085fee539SLionel Sambuc *
1185fee539SLionel Sambuc * Redistribution and use in source and binary forms, with or without
1285fee539SLionel Sambuc * modification, are permitted provided that the following conditions
1385fee539SLionel Sambuc * are met:
1485fee539SLionel Sambuc * 1. Redistributions of source code must retain the above copyright
1585fee539SLionel Sambuc * notice, this list of conditions and the following disclaimer.
1685fee539SLionel Sambuc * 2. Redistributions in binary form must reproduce the above copyright
1785fee539SLionel Sambuc * notice, this list of conditions and the following disclaimer in the
1885fee539SLionel Sambuc * documentation and/or other materials provided with the distribution.
1985fee539SLionel Sambuc * 3. Neither the name of the University nor the names of its contributors
2085fee539SLionel Sambuc * may be used to endorse or promote products derived from this software
2185fee539SLionel Sambuc * without specific prior written permission.
2285fee539SLionel Sambuc *
2385fee539SLionel Sambuc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2485fee539SLionel Sambuc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2585fee539SLionel Sambuc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2685fee539SLionel Sambuc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2785fee539SLionel Sambuc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2885fee539SLionel Sambuc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2985fee539SLionel Sambuc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3085fee539SLionel Sambuc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
3185fee539SLionel Sambuc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3285fee539SLionel Sambuc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3385fee539SLionel Sambuc * SUCH DAMAGE.
3485fee539SLionel Sambuc */
3585fee539SLionel Sambuc
3685fee539SLionel Sambuc #if HAVE_NBTOOL_CONFIG_H
3785fee539SLionel Sambuc #include "nbtool_config.h"
3885fee539SLionel Sambuc #endif
3985fee539SLionel Sambuc
4085fee539SLionel Sambuc #include <sys/cdefs.h>
4185fee539SLionel Sambuc #if !defined(lint)
4285fee539SLionel Sambuc #if 0
4385fee539SLionel Sambuc static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
4485fee539SLionel Sambuc #else
45*0a6a1f1dSLionel Sambuc __RCSID("$NetBSD: options.c,v 1.116 2015/04/11 15:41:33 christos Exp $");
4685fee539SLionel Sambuc #endif
4785fee539SLionel Sambuc #endif /* not lint */
4885fee539SLionel Sambuc
4985fee539SLionel Sambuc #include <sys/types.h>
5085fee539SLionel Sambuc #include <sys/time.h>
5185fee539SLionel Sambuc #include <sys/stat.h>
5285fee539SLionel Sambuc #include <sys/param.h>
5385fee539SLionel Sambuc #include <ctype.h>
5485fee539SLionel Sambuc #include <errno.h>
5585fee539SLionel Sambuc #if HAVE_NBTOOL_CONFIG_H
5685fee539SLionel Sambuc #include "compat_getopt.h"
5785fee539SLionel Sambuc #else
5885fee539SLionel Sambuc #include <getopt.h>
5985fee539SLionel Sambuc #endif
6085fee539SLionel Sambuc #include <limits.h>
6185fee539SLionel Sambuc #include <stdio.h>
6285fee539SLionel Sambuc #include <stdlib.h>
6385fee539SLionel Sambuc #include <string.h>
6485fee539SLionel Sambuc #include <unistd.h>
6585fee539SLionel Sambuc #include <inttypes.h>
6685fee539SLionel Sambuc #include <paths.h>
6785fee539SLionel Sambuc #include "pax.h"
6885fee539SLionel Sambuc #include "options.h"
6985fee539SLionel Sambuc #include "cpio.h"
7085fee539SLionel Sambuc #include "tar.h"
7185fee539SLionel Sambuc #include "extern.h"
7285fee539SLionel Sambuc #ifndef SMALL
7385fee539SLionel Sambuc #include "mtree.h"
7485fee539SLionel Sambuc #endif /* SMALL */
7585fee539SLionel Sambuc
7685fee539SLionel Sambuc /*
7785fee539SLionel Sambuc * Routines which handle command line options
7885fee539SLionel Sambuc */
7985fee539SLionel Sambuc
8085fee539SLionel Sambuc static int nopids; /* tar mode: suppress "pids" for -p option */
8185fee539SLionel Sambuc static char flgch[] = FLGCH; /* list of all possible flags (pax) */
8285fee539SLionel Sambuc static OPLIST *ophead = NULL; /* head for format specific options -x */
8385fee539SLionel Sambuc static OPLIST *optail = NULL; /* option tail */
8485fee539SLionel Sambuc
8585fee539SLionel Sambuc static int opt_add(const char *);
8685fee539SLionel Sambuc static int no_op(void);
8785fee539SLionel Sambuc static void printflg(unsigned int);
8885fee539SLionel Sambuc static int c_frmt(const void *, const void *);
8985fee539SLionel Sambuc static off_t str_offt(char *);
9085fee539SLionel Sambuc static char *get_line(FILE *fp);
9185fee539SLionel Sambuc static void pax_options(int, char **);
9285fee539SLionel Sambuc __dead static void pax_usage(void);
9385fee539SLionel Sambuc static void tar_options(int, char **);
9485fee539SLionel Sambuc __dead static void tar_usage(void);
9585fee539SLionel Sambuc #ifndef NO_CPIO
9685fee539SLionel Sambuc static void cpio_options(int, char **);
9785fee539SLionel Sambuc __dead static void cpio_usage(void);
9885fee539SLionel Sambuc #endif
9985fee539SLionel Sambuc
10085fee539SLionel Sambuc /* errors from get_line */
10185fee539SLionel Sambuc #define GETLINE_FILE_CORRUPT 1
10285fee539SLionel Sambuc #define GETLINE_OUT_OF_MEM 2
10385fee539SLionel Sambuc static int get_line_error;
10485fee539SLionel Sambuc
10585fee539SLionel Sambuc #define BZIP2_CMD "bzip2" /* command to run as bzip2 */
10685fee539SLionel Sambuc #define GZIP_CMD "gzip" /* command to run as gzip */
10785fee539SLionel Sambuc #define XZ_CMD "xz" /* command to run as xz */
10885fee539SLionel Sambuc #define COMPRESS_CMD "compress" /* command to run as compress */
10985fee539SLionel Sambuc
11085fee539SLionel Sambuc /*
11185fee539SLionel Sambuc * Long options.
11285fee539SLionel Sambuc */
11385fee539SLionel Sambuc #define OPT_USE_COMPRESS_PROGRAM 0
11485fee539SLionel Sambuc #define OPT_CHECKPOINT 1
11585fee539SLionel Sambuc #define OPT_UNLINK 2
11685fee539SLionel Sambuc #define OPT_HELP 3
11785fee539SLionel Sambuc #define OPT_ATIME_PRESERVE 4
11885fee539SLionel Sambuc #define OPT_IGNORE_FAILED_READ 5
11985fee539SLionel Sambuc #define OPT_REMOVE_FILES 6
12085fee539SLionel Sambuc #define OPT_NULL 7
12185fee539SLionel Sambuc #define OPT_TOTALS 8
12285fee539SLionel Sambuc #define OPT_VERSION 9
12385fee539SLionel Sambuc #define OPT_EXCLUDE 10
12485fee539SLionel Sambuc #define OPT_BLOCK_COMPRESS 11
12585fee539SLionel Sambuc #define OPT_NORECURSE 12
12685fee539SLionel Sambuc #define OPT_FORCE_LOCAL 13
12785fee539SLionel Sambuc #define OPT_INSECURE 14
12885fee539SLionel Sambuc #define OPT_STRICT 15
12985fee539SLionel Sambuc #define OPT_SPARSE 16
13085fee539SLionel Sambuc #define OPT_XZ 17
13184d9c625SLionel Sambuc #define OPT_GNU 18
13285fee539SLionel Sambuc #if !HAVE_NBTOOL_CONFIG_H
13384d9c625SLionel Sambuc #define OPT_CHROOT 19
13485fee539SLionel Sambuc #endif
13585fee539SLionel Sambuc
13685fee539SLionel Sambuc /*
13785fee539SLionel Sambuc * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
13885fee539SLionel Sambuc * (see pax.h for description of each function)
13985fee539SLionel Sambuc *
14085fee539SLionel Sambuc * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
14185fee539SLionel Sambuc * read, end_read, st_write, write, end_write, trail,
14285fee539SLionel Sambuc * subtrail, rd_data, wr_data, options
14385fee539SLionel Sambuc */
14485fee539SLionel Sambuc
14585fee539SLionel Sambuc FSUB fsub[] = {
14685fee539SLionel Sambuc #ifndef NO_CPIO
14785fee539SLionel Sambuc /* 0: OLD BINARY CPIO */
14885fee539SLionel Sambuc { "bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
14985fee539SLionel Sambuc bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, NULL,
15085fee539SLionel Sambuc cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
15185fee539SLionel Sambuc
15285fee539SLionel Sambuc /* 1: OLD OCTAL CHARACTER CPIO */
15385fee539SLionel Sambuc { "cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
15485fee539SLionel Sambuc cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, NULL,
15585fee539SLionel Sambuc cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
15685fee539SLionel Sambuc
15785fee539SLionel Sambuc /* 2: SVR4 HEX CPIO */
15885fee539SLionel Sambuc { "sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
15985fee539SLionel Sambuc vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, NULL,
16085fee539SLionel Sambuc cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
16185fee539SLionel Sambuc
16285fee539SLionel Sambuc /* 3: SVR4 HEX CPIO WITH CRC */
16385fee539SLionel Sambuc { "sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
16485fee539SLionel Sambuc vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, NULL,
16585fee539SLionel Sambuc cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
16685fee539SLionel Sambuc #endif
16785fee539SLionel Sambuc /* 4: OLD TAR */
16885fee539SLionel Sambuc { "tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
16985fee539SLionel Sambuc tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
17085fee539SLionel Sambuc NULL, rd_wrfile, wr_rdfile, tar_opt },
17185fee539SLionel Sambuc
17285fee539SLionel Sambuc /* 5: POSIX USTAR */
17385fee539SLionel Sambuc { "ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
17485fee539SLionel Sambuc ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
17585fee539SLionel Sambuc NULL, rd_wrfile, wr_rdfile, bad_opt }
17685fee539SLionel Sambuc };
17785fee539SLionel Sambuc #ifndef NO_CPIO
17885fee539SLionel Sambuc #define F_BCPIO 0 /* old binary cpio format */
17985fee539SLionel Sambuc #define F_CPIO 1 /* old octal character cpio format */
18085fee539SLionel Sambuc #define F_SV4CPIO 2 /* SVR4 hex cpio format */
18185fee539SLionel Sambuc #define F_SV4CRC 3 /* SVR4 hex with crc cpio format */
18285fee539SLionel Sambuc #define F_TAR 4 /* old V7 UNIX tar format */
18385fee539SLionel Sambuc #define F_USTAR 5 /* ustar format */
18485fee539SLionel Sambuc #else
18585fee539SLionel Sambuc #define F_TAR 0 /* old V7 UNIX tar format */
18685fee539SLionel Sambuc #define F_USTAR 1 /* ustar format */
18785fee539SLionel Sambuc #endif
18885fee539SLionel Sambuc #define DEFLT F_USTAR /* default write format from list above */
18985fee539SLionel Sambuc
19085fee539SLionel Sambuc /*
19185fee539SLionel Sambuc * ford is the archive search order used by get_arc() to determine what kind
19285fee539SLionel Sambuc * of archive we are dealing with. This helps to properly id archive formats
19385fee539SLionel Sambuc * some formats may be subsets of others....
19485fee539SLionel Sambuc */
19585fee539SLionel Sambuc int ford[] = {F_USTAR, F_TAR,
19685fee539SLionel Sambuc #ifndef NO_CPIO
19785fee539SLionel Sambuc F_SV4CRC, F_SV4CPIO, F_CPIO, F_BCPIO,
19885fee539SLionel Sambuc #endif
19985fee539SLionel Sambuc -1};
20085fee539SLionel Sambuc
20185fee539SLionel Sambuc /*
20285fee539SLionel Sambuc * filename record separator
20385fee539SLionel Sambuc */
20485fee539SLionel Sambuc int sep = '\n';
20585fee539SLionel Sambuc
20685fee539SLionel Sambuc /*
20785fee539SLionel Sambuc * Do we have -C anywhere?
20885fee539SLionel Sambuc */
20985fee539SLionel Sambuc int havechd = 0;
21085fee539SLionel Sambuc
21185fee539SLionel Sambuc /*
21285fee539SLionel Sambuc * options()
21385fee539SLionel Sambuc * figure out if we are pax, tar or cpio. Call the appropriate options
21485fee539SLionel Sambuc * parser
21585fee539SLionel Sambuc */
21685fee539SLionel Sambuc
21785fee539SLionel Sambuc void
options(int argc,char ** argv)21885fee539SLionel Sambuc options(int argc, char **argv)
21985fee539SLionel Sambuc {
22085fee539SLionel Sambuc
22185fee539SLionel Sambuc /*
22285fee539SLionel Sambuc * Are we acting like pax, tar or cpio (based on argv[0])
22385fee539SLionel Sambuc */
22485fee539SLionel Sambuc if ((argv0 = strrchr(argv[0], '/')) != NULL)
22585fee539SLionel Sambuc argv0++;
22685fee539SLionel Sambuc else
22785fee539SLionel Sambuc argv0 = argv[0];
22885fee539SLionel Sambuc
22985fee539SLionel Sambuc if (strstr(argv0, NM_TAR)) {
23085fee539SLionel Sambuc argv0 = NM_TAR;
23185fee539SLionel Sambuc tar_options(argc, argv);
23285fee539SLionel Sambuc #ifndef NO_CPIO
23385fee539SLionel Sambuc } else if (strstr(argv0, NM_CPIO)) {
23485fee539SLionel Sambuc argv0 = NM_CPIO;
23585fee539SLionel Sambuc cpio_options(argc, argv);
23685fee539SLionel Sambuc #endif
23785fee539SLionel Sambuc } else {
23885fee539SLionel Sambuc argv0 = NM_PAX;
23985fee539SLionel Sambuc pax_options(argc, argv);
24085fee539SLionel Sambuc }
24185fee539SLionel Sambuc }
24285fee539SLionel Sambuc
24385fee539SLionel Sambuc struct option pax_longopts[] = {
24485fee539SLionel Sambuc { "insecure", no_argument, 0,
24585fee539SLionel Sambuc OPT_INSECURE },
24685fee539SLionel Sambuc { "force-local", no_argument, 0,
24785fee539SLionel Sambuc OPT_FORCE_LOCAL },
24885fee539SLionel Sambuc { "use-compress-program", required_argument, 0,
24985fee539SLionel Sambuc OPT_USE_COMPRESS_PROGRAM },
25085fee539SLionel Sambuc { "xz", no_argument, 0,
25185fee539SLionel Sambuc OPT_XZ },
25284d9c625SLionel Sambuc { "gnu", no_argument, 0,
25384d9c625SLionel Sambuc OPT_GNU },
25485fee539SLionel Sambuc { 0, 0, 0,
25585fee539SLionel Sambuc 0 },
25685fee539SLionel Sambuc };
25785fee539SLionel Sambuc
25885fee539SLionel Sambuc /*
25985fee539SLionel Sambuc * pax_options()
26085fee539SLionel Sambuc * look at the user specified flags. set globals as required and check if
26185fee539SLionel Sambuc * the user specified a legal set of flags. If not, complain and exit
26285fee539SLionel Sambuc */
26385fee539SLionel Sambuc
26485fee539SLionel Sambuc static void
pax_options(int argc,char ** argv)26585fee539SLionel Sambuc pax_options(int argc, char **argv)
26685fee539SLionel Sambuc {
26785fee539SLionel Sambuc int c;
26885fee539SLionel Sambuc size_t i;
26985fee539SLionel Sambuc u_int64_t flg = 0;
27085fee539SLionel Sambuc u_int64_t bflg = 0;
27185fee539SLionel Sambuc char *pt;
27285fee539SLionel Sambuc FSUB tmp;
27385fee539SLionel Sambuc
27485fee539SLionel Sambuc /*
27585fee539SLionel Sambuc * process option flags
27685fee539SLionel Sambuc */
27785fee539SLionel Sambuc while ((c = getopt_long(argc, argv,
27885fee539SLionel Sambuc "0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:VXYZ",
27985fee539SLionel Sambuc pax_longopts, NULL)) != -1) {
28085fee539SLionel Sambuc switch (c) {
28185fee539SLionel Sambuc case '0':
28285fee539SLionel Sambuc sep = '\0';
28385fee539SLionel Sambuc break;
28485fee539SLionel Sambuc case 'a':
28585fee539SLionel Sambuc /*
28685fee539SLionel Sambuc * append
28785fee539SLionel Sambuc */
28885fee539SLionel Sambuc flg |= AF;
28985fee539SLionel Sambuc break;
29085fee539SLionel Sambuc case 'b':
29185fee539SLionel Sambuc /*
29285fee539SLionel Sambuc * specify blocksize
29385fee539SLionel Sambuc */
29485fee539SLionel Sambuc flg |= BF;
29585fee539SLionel Sambuc if ((wrblksz = (int)str_offt(optarg)) <= 0) {
29685fee539SLionel Sambuc tty_warn(1, "Invalid block size %s", optarg);
29785fee539SLionel Sambuc pax_usage();
29885fee539SLionel Sambuc }
29985fee539SLionel Sambuc break;
30085fee539SLionel Sambuc case 'c':
30185fee539SLionel Sambuc /*
30285fee539SLionel Sambuc * inverse match on patterns
30385fee539SLionel Sambuc */
30485fee539SLionel Sambuc cflag = 1;
30585fee539SLionel Sambuc flg |= CF;
30685fee539SLionel Sambuc break;
30785fee539SLionel Sambuc case 'd':
30885fee539SLionel Sambuc /*
30985fee539SLionel Sambuc * match only dir on extract, not the subtree at dir
31085fee539SLionel Sambuc */
31185fee539SLionel Sambuc dflag = 1;
31285fee539SLionel Sambuc flg |= DF;
31385fee539SLionel Sambuc break;
31485fee539SLionel Sambuc case 'f':
31585fee539SLionel Sambuc /*
31685fee539SLionel Sambuc * filename where the archive is stored
31785fee539SLionel Sambuc */
31885fee539SLionel Sambuc arcname = optarg;
31985fee539SLionel Sambuc flg |= FF;
32085fee539SLionel Sambuc break;
32185fee539SLionel Sambuc case 'i':
32285fee539SLionel Sambuc /*
32385fee539SLionel Sambuc * interactive file rename
32485fee539SLionel Sambuc */
32585fee539SLionel Sambuc iflag = 1;
32685fee539SLionel Sambuc flg |= IF;
32785fee539SLionel Sambuc break;
32885fee539SLionel Sambuc case 'j':
32985fee539SLionel Sambuc /*
33085fee539SLionel Sambuc * pass through bzip2
33185fee539SLionel Sambuc */
33285fee539SLionel Sambuc gzip_program = BZIP2_CMD;
33385fee539SLionel Sambuc break;
33485fee539SLionel Sambuc case 'k':
33585fee539SLionel Sambuc /*
33685fee539SLionel Sambuc * do not clobber files that exist
33785fee539SLionel Sambuc */
33885fee539SLionel Sambuc kflag = 1;
33985fee539SLionel Sambuc flg |= KF;
34085fee539SLionel Sambuc break;
34185fee539SLionel Sambuc case 'l':
34285fee539SLionel Sambuc /*
34385fee539SLionel Sambuc * try to link src to dest with copy (-rw)
34485fee539SLionel Sambuc */
34585fee539SLionel Sambuc lflag = 1;
34685fee539SLionel Sambuc flg |= LF;
34785fee539SLionel Sambuc break;
34885fee539SLionel Sambuc case 'n':
34985fee539SLionel Sambuc /*
35085fee539SLionel Sambuc * select first match for a pattern only
35185fee539SLionel Sambuc */
35285fee539SLionel Sambuc nflag = 1;
35385fee539SLionel Sambuc flg |= NF;
35485fee539SLionel Sambuc break;
35585fee539SLionel Sambuc case 'o':
35685fee539SLionel Sambuc /*
35785fee539SLionel Sambuc * pass format specific options
35885fee539SLionel Sambuc */
35985fee539SLionel Sambuc flg |= OF;
36085fee539SLionel Sambuc if (opt_add(optarg) < 0)
36185fee539SLionel Sambuc pax_usage();
36285fee539SLionel Sambuc break;
36385fee539SLionel Sambuc case 'p':
36485fee539SLionel Sambuc /*
36585fee539SLionel Sambuc * specify file characteristic options
36685fee539SLionel Sambuc */
36785fee539SLionel Sambuc for (pt = optarg; *pt != '\0'; ++pt) {
36885fee539SLionel Sambuc switch(*pt) {
36985fee539SLionel Sambuc case 'a':
37085fee539SLionel Sambuc /*
37185fee539SLionel Sambuc * do not preserve access time
37285fee539SLionel Sambuc */
37385fee539SLionel Sambuc patime = 0;
37485fee539SLionel Sambuc break;
37585fee539SLionel Sambuc case 'e':
37685fee539SLionel Sambuc /*
37785fee539SLionel Sambuc * preserve user id, group id, file
37885fee539SLionel Sambuc * mode, access/modification times
37985fee539SLionel Sambuc * and file flags.
38085fee539SLionel Sambuc */
38185fee539SLionel Sambuc pids = 1;
38285fee539SLionel Sambuc pmode = 1;
38385fee539SLionel Sambuc patime = 1;
38485fee539SLionel Sambuc pmtime = 1;
38585fee539SLionel Sambuc pfflags = 1;
38685fee539SLionel Sambuc break;
38785fee539SLionel Sambuc #if 0
38885fee539SLionel Sambuc case 'f':
38985fee539SLionel Sambuc /*
39085fee539SLionel Sambuc * do not preserve file flags
39185fee539SLionel Sambuc */
39285fee539SLionel Sambuc pfflags = 0;
39385fee539SLionel Sambuc break;
39485fee539SLionel Sambuc #endif
39585fee539SLionel Sambuc case 'm':
39685fee539SLionel Sambuc /*
39785fee539SLionel Sambuc * do not preserve modification time
39885fee539SLionel Sambuc */
39985fee539SLionel Sambuc pmtime = 0;
40085fee539SLionel Sambuc break;
40185fee539SLionel Sambuc case 'o':
40285fee539SLionel Sambuc /*
40385fee539SLionel Sambuc * preserve uid/gid
40485fee539SLionel Sambuc */
40585fee539SLionel Sambuc pids = 1;
40685fee539SLionel Sambuc break;
40785fee539SLionel Sambuc case 'p':
40885fee539SLionel Sambuc /*
40985fee539SLionel Sambuc * preserve file mode bits
41085fee539SLionel Sambuc */
41185fee539SLionel Sambuc pmode = 1;
41285fee539SLionel Sambuc break;
41385fee539SLionel Sambuc default:
41485fee539SLionel Sambuc tty_warn(1, "Invalid -p string: %c",
41585fee539SLionel Sambuc *pt);
41685fee539SLionel Sambuc pax_usage();
41785fee539SLionel Sambuc break;
41885fee539SLionel Sambuc }
41985fee539SLionel Sambuc }
42085fee539SLionel Sambuc flg |= PF;
42185fee539SLionel Sambuc break;
42285fee539SLionel Sambuc case 'r':
42385fee539SLionel Sambuc /*
42485fee539SLionel Sambuc * read the archive
42585fee539SLionel Sambuc */
42685fee539SLionel Sambuc flg |= RF;
42785fee539SLionel Sambuc break;
42885fee539SLionel Sambuc case 's':
42985fee539SLionel Sambuc /*
43085fee539SLionel Sambuc * file name substitution name pattern
43185fee539SLionel Sambuc */
43285fee539SLionel Sambuc if (rep_add(optarg) < 0) {
43385fee539SLionel Sambuc pax_usage();
43485fee539SLionel Sambuc break;
43585fee539SLionel Sambuc }
43685fee539SLionel Sambuc flg |= SF;
43785fee539SLionel Sambuc break;
43885fee539SLionel Sambuc case 't':
43985fee539SLionel Sambuc /*
44085fee539SLionel Sambuc * preserve access time on filesystem nodes we read
44185fee539SLionel Sambuc */
44285fee539SLionel Sambuc tflag = 1;
44385fee539SLionel Sambuc flg |= TF;
44485fee539SLionel Sambuc break;
44585fee539SLionel Sambuc case 'u':
44685fee539SLionel Sambuc /*
44785fee539SLionel Sambuc * ignore those older files
44885fee539SLionel Sambuc */
44985fee539SLionel Sambuc uflag = 1;
45085fee539SLionel Sambuc flg |= UF;
45185fee539SLionel Sambuc break;
45285fee539SLionel Sambuc case 'v':
45385fee539SLionel Sambuc /*
45485fee539SLionel Sambuc * verbose operation mode
45585fee539SLionel Sambuc */
45685fee539SLionel Sambuc vflag = 1;
45785fee539SLionel Sambuc flg |= VF;
45885fee539SLionel Sambuc break;
45985fee539SLionel Sambuc case 'w':
46085fee539SLionel Sambuc /*
46185fee539SLionel Sambuc * write an archive
46285fee539SLionel Sambuc */
46385fee539SLionel Sambuc flg |= WF;
46485fee539SLionel Sambuc break;
46585fee539SLionel Sambuc case 'x':
46685fee539SLionel Sambuc /*
46785fee539SLionel Sambuc * specify an archive format on write
46885fee539SLionel Sambuc */
46985fee539SLionel Sambuc tmp.name = optarg;
47085fee539SLionel Sambuc frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
47185fee539SLionel Sambuc sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt);
47285fee539SLionel Sambuc if (frmt != NULL) {
47385fee539SLionel Sambuc flg |= XF;
47485fee539SLionel Sambuc break;
47585fee539SLionel Sambuc }
47685fee539SLionel Sambuc tty_warn(1, "Unknown -x format: %s", optarg);
47785fee539SLionel Sambuc (void)fputs("pax: Known -x formats are:", stderr);
47885fee539SLionel Sambuc for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
47985fee539SLionel Sambuc (void)fprintf(stderr, " %s", fsub[i].name);
48085fee539SLionel Sambuc (void)fputs("\n\n", stderr);
48185fee539SLionel Sambuc pax_usage();
48285fee539SLionel Sambuc break;
48385fee539SLionel Sambuc case 'z':
48485fee539SLionel Sambuc /*
48585fee539SLionel Sambuc * use gzip. Non standard option.
48685fee539SLionel Sambuc */
48785fee539SLionel Sambuc gzip_program = GZIP_CMD;
48885fee539SLionel Sambuc break;
48985fee539SLionel Sambuc case 'A':
49085fee539SLionel Sambuc Aflag = 1;
49185fee539SLionel Sambuc flg |= CAF;
49285fee539SLionel Sambuc break;
49385fee539SLionel Sambuc case 'B':
49485fee539SLionel Sambuc /*
49585fee539SLionel Sambuc * non-standard option on number of bytes written on a
49685fee539SLionel Sambuc * single archive volume.
49785fee539SLionel Sambuc */
49885fee539SLionel Sambuc if ((wrlimit = str_offt(optarg)) <= 0) {
49985fee539SLionel Sambuc tty_warn(1, "Invalid write limit %s", optarg);
50085fee539SLionel Sambuc pax_usage();
50185fee539SLionel Sambuc }
50285fee539SLionel Sambuc if (wrlimit % BLKMULT) {
50385fee539SLionel Sambuc tty_warn(1,
50485fee539SLionel Sambuc "Write limit is not a %d byte multiple",
50585fee539SLionel Sambuc BLKMULT);
50685fee539SLionel Sambuc pax_usage();
50785fee539SLionel Sambuc }
50885fee539SLionel Sambuc flg |= CBF;
50985fee539SLionel Sambuc break;
51085fee539SLionel Sambuc case 'D':
51185fee539SLionel Sambuc /*
51285fee539SLionel Sambuc * On extraction check file inode change time before the
51385fee539SLionel Sambuc * modification of the file name. Non standard option.
51485fee539SLionel Sambuc */
51585fee539SLionel Sambuc Dflag = 1;
51685fee539SLionel Sambuc flg |= CDF;
51785fee539SLionel Sambuc break;
51885fee539SLionel Sambuc case 'E':
51985fee539SLionel Sambuc /*
52085fee539SLionel Sambuc * non-standard limit on read faults
52185fee539SLionel Sambuc * 0 indicates stop after first error, values
52285fee539SLionel Sambuc * indicate a limit, "none" try forever
52385fee539SLionel Sambuc */
52485fee539SLionel Sambuc flg |= CEF;
52585fee539SLionel Sambuc if (strcmp(none, optarg) == 0)
52685fee539SLionel Sambuc maxflt = -1;
52785fee539SLionel Sambuc else if ((maxflt = atoi(optarg)) < 0) {
52885fee539SLionel Sambuc tty_warn(1,
52985fee539SLionel Sambuc "Error count value must be positive");
53085fee539SLionel Sambuc pax_usage();
53185fee539SLionel Sambuc }
53285fee539SLionel Sambuc break;
53385fee539SLionel Sambuc case 'G':
53485fee539SLionel Sambuc /*
53585fee539SLionel Sambuc * non-standard option for selecting files within an
53685fee539SLionel Sambuc * archive by group (gid or name)
53785fee539SLionel Sambuc */
53885fee539SLionel Sambuc if (grp_add(optarg) < 0) {
53985fee539SLionel Sambuc pax_usage();
54085fee539SLionel Sambuc break;
54185fee539SLionel Sambuc }
54285fee539SLionel Sambuc flg |= CGF;
54385fee539SLionel Sambuc break;
54485fee539SLionel Sambuc case 'H':
54585fee539SLionel Sambuc /*
54685fee539SLionel Sambuc * follow command line symlinks only
54785fee539SLionel Sambuc */
54885fee539SLionel Sambuc Hflag = 1;
54985fee539SLionel Sambuc flg |= CHF;
55085fee539SLionel Sambuc break;
55185fee539SLionel Sambuc case 'L':
55285fee539SLionel Sambuc /*
55385fee539SLionel Sambuc * follow symlinks
55485fee539SLionel Sambuc */
55585fee539SLionel Sambuc Lflag = 1;
55685fee539SLionel Sambuc flg |= CLF;
55785fee539SLionel Sambuc break;
55885fee539SLionel Sambuc #ifdef SMALL
55985fee539SLionel Sambuc case 'M':
56085fee539SLionel Sambuc case 'N':
56185fee539SLionel Sambuc tty_warn(1, "Support for -%c is not compiled in", c);
56285fee539SLionel Sambuc exit(1);
56385fee539SLionel Sambuc #else /* !SMALL */
56485fee539SLionel Sambuc case 'M':
56585fee539SLionel Sambuc /*
56685fee539SLionel Sambuc * Treat list of filenames on stdin as an
56785fee539SLionel Sambuc * mtree(8) specfile. Non standard option.
56885fee539SLionel Sambuc */
56985fee539SLionel Sambuc Mflag = 1;
57085fee539SLionel Sambuc flg |= CMF;
57185fee539SLionel Sambuc break;
57285fee539SLionel Sambuc case 'N':
57385fee539SLionel Sambuc /*
57485fee539SLionel Sambuc * Use alternative directory for user db lookups.
57585fee539SLionel Sambuc */
57685fee539SLionel Sambuc if (!setup_getid(optarg)) {
57785fee539SLionel Sambuc tty_warn(1,
57885fee539SLionel Sambuc "Unable to use user and group databases in `%s'",
57985fee539SLionel Sambuc optarg);
58085fee539SLionel Sambuc pax_usage();
58185fee539SLionel Sambuc }
58285fee539SLionel Sambuc break;
58385fee539SLionel Sambuc #endif /* !SMALL */
58485fee539SLionel Sambuc case 'O':
58585fee539SLionel Sambuc /*
58685fee539SLionel Sambuc * Force one volume. Non standard option.
58785fee539SLionel Sambuc */
58885fee539SLionel Sambuc force_one_volume = 1;
58985fee539SLionel Sambuc break;
59085fee539SLionel Sambuc case 'P':
59185fee539SLionel Sambuc /*
59285fee539SLionel Sambuc * do NOT follow symlinks (default)
59385fee539SLionel Sambuc */
59485fee539SLionel Sambuc Lflag = 0;
59585fee539SLionel Sambuc flg |= CPF;
59685fee539SLionel Sambuc break;
59785fee539SLionel Sambuc case 'T':
59885fee539SLionel Sambuc /*
59985fee539SLionel Sambuc * non-standard option for selecting files within an
60085fee539SLionel Sambuc * archive by modification time range (lower,upper)
60185fee539SLionel Sambuc */
60285fee539SLionel Sambuc if (trng_add(optarg) < 0) {
60385fee539SLionel Sambuc pax_usage();
60485fee539SLionel Sambuc break;
60585fee539SLionel Sambuc }
60685fee539SLionel Sambuc flg |= CTF;
60785fee539SLionel Sambuc break;
60885fee539SLionel Sambuc case 'U':
60985fee539SLionel Sambuc /*
61085fee539SLionel Sambuc * non-standard option for selecting files within an
61185fee539SLionel Sambuc * archive by user (uid or name)
61285fee539SLionel Sambuc */
61385fee539SLionel Sambuc if (usr_add(optarg) < 0) {
61485fee539SLionel Sambuc pax_usage();
61585fee539SLionel Sambuc break;
61685fee539SLionel Sambuc }
61785fee539SLionel Sambuc flg |= CUF;
61885fee539SLionel Sambuc break;
61985fee539SLionel Sambuc case 'V':
62085fee539SLionel Sambuc /*
62185fee539SLionel Sambuc * somewhat verbose operation mode (no listing)
62285fee539SLionel Sambuc */
62385fee539SLionel Sambuc Vflag = 1;
62485fee539SLionel Sambuc flg |= VSF;
62585fee539SLionel Sambuc break;
62685fee539SLionel Sambuc case 'X':
62785fee539SLionel Sambuc /*
62885fee539SLionel Sambuc * do not pass over mount points in the file system
62985fee539SLionel Sambuc */
63085fee539SLionel Sambuc Xflag = 1;
63185fee539SLionel Sambuc flg |= CXF;
63285fee539SLionel Sambuc break;
63385fee539SLionel Sambuc case 'Y':
63485fee539SLionel Sambuc /*
63585fee539SLionel Sambuc * On extraction check file inode change time after the
63685fee539SLionel Sambuc * modification of the file name. Non standard option.
63785fee539SLionel Sambuc */
63885fee539SLionel Sambuc Yflag = 1;
63985fee539SLionel Sambuc flg |= CYF;
64085fee539SLionel Sambuc break;
64185fee539SLionel Sambuc case 'Z':
64285fee539SLionel Sambuc /*
64385fee539SLionel Sambuc * On extraction check modification time after the
64485fee539SLionel Sambuc * modification of the file name. Non standard option.
64585fee539SLionel Sambuc */
64685fee539SLionel Sambuc Zflag = 1;
64785fee539SLionel Sambuc flg |= CZF;
64885fee539SLionel Sambuc break;
64985fee539SLionel Sambuc case OPT_INSECURE:
65085fee539SLionel Sambuc secure = 0;
65185fee539SLionel Sambuc break;
65285fee539SLionel Sambuc case OPT_FORCE_LOCAL:
65385fee539SLionel Sambuc forcelocal = 1;
65485fee539SLionel Sambuc break;
65585fee539SLionel Sambuc case OPT_USE_COMPRESS_PROGRAM:
65685fee539SLionel Sambuc gzip_program = optarg;
65785fee539SLionel Sambuc break;
65885fee539SLionel Sambuc case OPT_XZ:
65985fee539SLionel Sambuc gzip_program = XZ_CMD;
66085fee539SLionel Sambuc break;
66184d9c625SLionel Sambuc case OPT_GNU:
66284d9c625SLionel Sambuc is_gnutar = 1;
66384d9c625SLionel Sambuc break;
66485fee539SLionel Sambuc case '?':
66585fee539SLionel Sambuc default:
66685fee539SLionel Sambuc pax_usage();
66785fee539SLionel Sambuc break;
66885fee539SLionel Sambuc }
66985fee539SLionel Sambuc }
67085fee539SLionel Sambuc
67185fee539SLionel Sambuc /*
67285fee539SLionel Sambuc * figure out the operation mode of pax read,write,extract,copy,append
67385fee539SLionel Sambuc * or list. check that we have not been given a bogus set of flags
67485fee539SLionel Sambuc * for the operation mode.
67585fee539SLionel Sambuc */
67685fee539SLionel Sambuc if (ISLIST(flg)) {
67785fee539SLionel Sambuc act = LIST;
67885fee539SLionel Sambuc listf = stdout;
67985fee539SLionel Sambuc bflg = flg & BDLIST;
68085fee539SLionel Sambuc } else if (ISEXTRACT(flg)) {
68185fee539SLionel Sambuc act = EXTRACT;
68285fee539SLionel Sambuc bflg = flg & BDEXTR;
68385fee539SLionel Sambuc } else if (ISARCHIVE(flg)) {
68485fee539SLionel Sambuc act = ARCHIVE;
68585fee539SLionel Sambuc bflg = flg & BDARCH;
68685fee539SLionel Sambuc } else if (ISAPPND(flg)) {
68785fee539SLionel Sambuc act = APPND;
68885fee539SLionel Sambuc bflg = flg & BDARCH;
68985fee539SLionel Sambuc } else if (ISCOPY(flg)) {
69085fee539SLionel Sambuc act = COPY;
69185fee539SLionel Sambuc bflg = flg & BDCOPY;
69285fee539SLionel Sambuc } else
69385fee539SLionel Sambuc pax_usage();
69485fee539SLionel Sambuc if (bflg) {
69585fee539SLionel Sambuc printflg(flg);
69685fee539SLionel Sambuc pax_usage();
69785fee539SLionel Sambuc }
69885fee539SLionel Sambuc
69985fee539SLionel Sambuc /*
70085fee539SLionel Sambuc * if we are writing (ARCHIVE) we use the default format if the user
70185fee539SLionel Sambuc * did not specify a format. when we write during an APPEND, we will
70285fee539SLionel Sambuc * adopt the format of the existing archive if none was supplied.
70385fee539SLionel Sambuc */
70485fee539SLionel Sambuc if (!(flg & XF) && (act == ARCHIVE))
70585fee539SLionel Sambuc frmt = &(fsub[DEFLT]);
70685fee539SLionel Sambuc
70785fee539SLionel Sambuc /*
70885fee539SLionel Sambuc * process the args as they are interpreted by the operation mode
70985fee539SLionel Sambuc */
71085fee539SLionel Sambuc switch (act) {
71185fee539SLionel Sambuc case LIST:
71285fee539SLionel Sambuc case EXTRACT:
71385fee539SLionel Sambuc for (; optind < argc; optind++)
71485fee539SLionel Sambuc if (pat_add(argv[optind], NULL, 0) < 0)
71585fee539SLionel Sambuc pax_usage();
71685fee539SLionel Sambuc break;
71785fee539SLionel Sambuc case COPY:
71885fee539SLionel Sambuc if (optind >= argc) {
71985fee539SLionel Sambuc tty_warn(0, "Destination directory was not supplied");
72085fee539SLionel Sambuc pax_usage();
72185fee539SLionel Sambuc }
72285fee539SLionel Sambuc --argc;
72385fee539SLionel Sambuc dirptr = argv[argc];
72485fee539SLionel Sambuc if (mkpath(dirptr) < 0)
72585fee539SLionel Sambuc exit(1);
72685fee539SLionel Sambuc /* FALLTHROUGH */
72785fee539SLionel Sambuc case ARCHIVE:
72885fee539SLionel Sambuc case APPND:
72985fee539SLionel Sambuc for (; optind < argc; optind++)
73085fee539SLionel Sambuc if (ftree_add(argv[optind], 0) < 0)
73185fee539SLionel Sambuc pax_usage();
73285fee539SLionel Sambuc /*
73385fee539SLionel Sambuc * no read errors allowed on updates/append operation!
73485fee539SLionel Sambuc */
73585fee539SLionel Sambuc maxflt = 0;
73685fee539SLionel Sambuc break;
73785fee539SLionel Sambuc }
73885fee539SLionel Sambuc }
73985fee539SLionel Sambuc
74085fee539SLionel Sambuc
74185fee539SLionel Sambuc /*
74285fee539SLionel Sambuc * tar_options()
74385fee539SLionel Sambuc * look at the user specified flags. set globals as required and check if
74485fee539SLionel Sambuc * the user specified a legal set of flags. If not, complain and exit
74585fee539SLionel Sambuc */
74685fee539SLionel Sambuc
74785fee539SLionel Sambuc struct option tar_longopts[] = {
74885fee539SLionel Sambuc { "block-size", required_argument, 0, 'b' },
74985fee539SLionel Sambuc { "bunzip2", no_argument, 0, 'j' },
75085fee539SLionel Sambuc { "bzip2", no_argument, 0, 'j' },
75185fee539SLionel Sambuc { "create", no_argument, 0, 'c' }, /* F */
75285fee539SLionel Sambuc /* -e -- no corresponding long option */
75385fee539SLionel Sambuc { "file", required_argument, 0, 'f' },
75485fee539SLionel Sambuc { "dereference", no_argument, 0, 'h' },
75585fee539SLionel Sambuc { "keep-old-files", no_argument, 0, 'k' },
75685fee539SLionel Sambuc { "one-file-system", no_argument, 0, 'l' },
75785fee539SLionel Sambuc { "modification-time", no_argument, 0, 'm' },
75885fee539SLionel Sambuc { "old-archive", no_argument, 0, 'o' },
75985fee539SLionel Sambuc { "portability", no_argument, 0, 'o' },
76085fee539SLionel Sambuc { "same-permissions", no_argument, 0, 'p' },
76185fee539SLionel Sambuc { "preserve-permissions", no_argument, 0, 'p' },
76285fee539SLionel Sambuc { "preserve", no_argument, 0, 'p' },
76385fee539SLionel Sambuc { "fast-read", no_argument, 0, 'q' },
76485fee539SLionel Sambuc { "append", no_argument, 0, 'r' }, /* F */
76585fee539SLionel Sambuc { "update", no_argument, 0, 'u' }, /* F */
76685fee539SLionel Sambuc { "list", no_argument, 0, 't' }, /* F */
76785fee539SLionel Sambuc { "verbose", no_argument, 0, 'v' },
76885fee539SLionel Sambuc { "interactive", no_argument, 0, 'w' },
76985fee539SLionel Sambuc { "confirmation", no_argument, 0, 'w' },
77085fee539SLionel Sambuc { "extract", no_argument, 0, 'x' }, /* F */
77185fee539SLionel Sambuc { "get", no_argument, 0, 'x' }, /* F */
77285fee539SLionel Sambuc { "gzip", no_argument, 0, 'z' },
77385fee539SLionel Sambuc { "gunzip", no_argument, 0, 'z' },
77485fee539SLionel Sambuc { "read-full-blocks", no_argument, 0, 'B' },
77585fee539SLionel Sambuc { "directory", required_argument, 0, 'C' },
776*0a6a1f1dSLionel Sambuc { "xz", no_argument, 0, 'J' },
77785fee539SLionel Sambuc { "to-stdout", no_argument, 0, 'O' },
77885fee539SLionel Sambuc { "absolute-paths", no_argument, 0, 'P' },
77985fee539SLionel Sambuc { "sparse", no_argument, 0, 'S' },
78085fee539SLionel Sambuc { "files-from", required_argument, 0, 'T' },
78185fee539SLionel Sambuc { "summary", no_argument, 0, 'V' },
78285fee539SLionel Sambuc { "stats", no_argument, 0, 'V' },
78385fee539SLionel Sambuc { "exclude-from", required_argument, 0, 'X' },
78485fee539SLionel Sambuc { "compress", no_argument, 0, 'Z' },
78585fee539SLionel Sambuc { "uncompress", no_argument, 0, 'Z' },
78685fee539SLionel Sambuc { "strict", no_argument, 0,
78785fee539SLionel Sambuc OPT_STRICT },
78885fee539SLionel Sambuc { "atime-preserve", no_argument, 0,
78985fee539SLionel Sambuc OPT_ATIME_PRESERVE },
79085fee539SLionel Sambuc { "unlink", no_argument, 0,
79185fee539SLionel Sambuc OPT_UNLINK },
79285fee539SLionel Sambuc { "use-compress-program", required_argument, 0,
79385fee539SLionel Sambuc OPT_USE_COMPRESS_PROGRAM },
79485fee539SLionel Sambuc { "force-local", no_argument, 0,
79585fee539SLionel Sambuc OPT_FORCE_LOCAL },
79685fee539SLionel Sambuc { "insecure", no_argument, 0,
79785fee539SLionel Sambuc OPT_INSECURE },
79885fee539SLionel Sambuc { "exclude", required_argument, 0,
79985fee539SLionel Sambuc OPT_EXCLUDE },
80085fee539SLionel Sambuc { "no-recursion", no_argument, 0,
80185fee539SLionel Sambuc OPT_NORECURSE },
80285fee539SLionel Sambuc #if !HAVE_NBTOOL_CONFIG_H
80385fee539SLionel Sambuc { "chroot", no_argument, 0,
80485fee539SLionel Sambuc OPT_CHROOT },
80585fee539SLionel Sambuc #endif
80685fee539SLionel Sambuc #if 0 /* Not implemented */
80785fee539SLionel Sambuc { "catenate", no_argument, 0, 'A' }, /* F */
80885fee539SLionel Sambuc { "concatenate", no_argument, 0, 'A' }, /* F */
80985fee539SLionel Sambuc { "diff", no_argument, 0, 'd' }, /* F */
81085fee539SLionel Sambuc { "compare", no_argument, 0, 'd' }, /* F */
81185fee539SLionel Sambuc { "checkpoint", no_argument, 0,
81285fee539SLionel Sambuc OPT_CHECKPOINT },
81385fee539SLionel Sambuc { "help", no_argument, 0,
81485fee539SLionel Sambuc OPT_HELP },
81585fee539SLionel Sambuc { "info-script", required_argument, 0, 'F' },
81685fee539SLionel Sambuc { "new-volume-script", required_argument, 0, 'F' },
81785fee539SLionel Sambuc { "incremental", no_argument, 0, 'G' },
81885fee539SLionel Sambuc { "listed-incremental", required_argument, 0, 'g' },
81985fee539SLionel Sambuc { "ignore-zeros", no_argument, 0, 'i' },
82085fee539SLionel Sambuc { "ignore-failed-read", no_argument, 0,
82185fee539SLionel Sambuc OPT_IGNORE_FAILED_READ },
82285fee539SLionel Sambuc { "starting-file", no_argument, 0, 'K' },
82385fee539SLionel Sambuc { "tape-length", required_argument, 0, 'L' },
82485fee539SLionel Sambuc { "multi-volume", no_argument, 0, 'M' },
82585fee539SLionel Sambuc { "after-date", required_argument, 0, 'N' },
82685fee539SLionel Sambuc { "newer", required_argument, 0, 'N' },
82785fee539SLionel Sambuc { "record-number", no_argument, 0, 'R' },
82885fee539SLionel Sambuc { "remove-files", no_argument, 0,
82985fee539SLionel Sambuc OPT_REMOVE_FILES },
83085fee539SLionel Sambuc { "same-order", no_argument, 0, 's' },
83185fee539SLionel Sambuc { "preserve-order", no_argument, 0, 's' },
83285fee539SLionel Sambuc { "null", no_argument, 0,
83385fee539SLionel Sambuc OPT_NULL },
83485fee539SLionel Sambuc { "totals", no_argument, 0,
83585fee539SLionel Sambuc OPT_TOTALS },
83685fee539SLionel Sambuc { "volume-name", required_argument, 0, 'V' }, /* XXX */
83785fee539SLionel Sambuc { "label", required_argument, 0, 'V' }, /* XXX */
83885fee539SLionel Sambuc { "version", no_argument, 0,
83985fee539SLionel Sambuc OPT_VERSION },
84085fee539SLionel Sambuc { "verify", no_argument, 0, 'W' },
84185fee539SLionel Sambuc { "block-compress", no_argument, 0,
84285fee539SLionel Sambuc OPT_BLOCK_COMPRESS },
84385fee539SLionel Sambuc #endif
84485fee539SLionel Sambuc { 0, 0, 0, 0 },
84585fee539SLionel Sambuc };
84685fee539SLionel Sambuc
84785fee539SLionel Sambuc static void
tar_set_action(int op)84885fee539SLionel Sambuc tar_set_action(int op)
84985fee539SLionel Sambuc {
85085fee539SLionel Sambuc if (act != ERROR && act != op)
85185fee539SLionel Sambuc tar_usage();
85285fee539SLionel Sambuc act = op;
85385fee539SLionel Sambuc }
85485fee539SLionel Sambuc
85585fee539SLionel Sambuc static void
tar_options(int argc,char ** argv)85685fee539SLionel Sambuc tar_options(int argc, char **argv)
85785fee539SLionel Sambuc {
85885fee539SLionel Sambuc int c;
85985fee539SLionel Sambuc int fstdin = 0;
86085fee539SLionel Sambuc int Oflag = 0;
86185fee539SLionel Sambuc int nincfiles = 0;
86285fee539SLionel Sambuc int incfiles_max = 0;
86385fee539SLionel Sambuc struct incfile {
86485fee539SLionel Sambuc char *file;
86585fee539SLionel Sambuc char *dir;
86685fee539SLionel Sambuc };
86785fee539SLionel Sambuc struct incfile *incfiles = NULL;
86885fee539SLionel Sambuc
86985fee539SLionel Sambuc /*
87085fee539SLionel Sambuc * Set default values.
87185fee539SLionel Sambuc */
87285fee539SLionel Sambuc rmleadslash = 1;
87385fee539SLionel Sambuc is_gnutar = 1;
87485fee539SLionel Sambuc
87585fee539SLionel Sambuc /*
87685fee539SLionel Sambuc * process option flags
87785fee539SLionel Sambuc */
87885fee539SLionel Sambuc while ((c = getoldopt(argc, argv,
879*0a6a1f1dSLionel Sambuc "+b:cef:hjklmopqrs:tuvwxzBC:HI:JOPST:X:Z014578",
88085fee539SLionel Sambuc tar_longopts, NULL))
88185fee539SLionel Sambuc != -1) {
88285fee539SLionel Sambuc switch(c) {
88385fee539SLionel Sambuc case 'b':
88485fee539SLionel Sambuc /*
88585fee539SLionel Sambuc * specify blocksize in 512-byte blocks
88685fee539SLionel Sambuc */
88785fee539SLionel Sambuc if ((wrblksz = (int)str_offt(optarg)) <= 0) {
88885fee539SLionel Sambuc tty_warn(1, "Invalid block size %s", optarg);
88985fee539SLionel Sambuc tar_usage();
89085fee539SLionel Sambuc }
89185fee539SLionel Sambuc wrblksz *= 512; /* XXX - check for int oflow */
89285fee539SLionel Sambuc break;
89385fee539SLionel Sambuc case 'c':
89485fee539SLionel Sambuc /*
89585fee539SLionel Sambuc * create an archive
89685fee539SLionel Sambuc */
89785fee539SLionel Sambuc tar_set_action(ARCHIVE);
89885fee539SLionel Sambuc break;
89985fee539SLionel Sambuc case 'e':
90085fee539SLionel Sambuc /*
90185fee539SLionel Sambuc * stop after first error
90285fee539SLionel Sambuc */
90385fee539SLionel Sambuc maxflt = 0;
90485fee539SLionel Sambuc break;
90585fee539SLionel Sambuc case 'f':
90685fee539SLionel Sambuc /*
90785fee539SLionel Sambuc * filename where the archive is stored
90885fee539SLionel Sambuc */
90985fee539SLionel Sambuc if ((optarg[0] == '-') && (optarg[1]== '\0')) {
91085fee539SLionel Sambuc /*
91185fee539SLionel Sambuc * treat a - as stdin
91285fee539SLionel Sambuc */
91385fee539SLionel Sambuc fstdin = 1;
91485fee539SLionel Sambuc arcname = NULL;
91585fee539SLionel Sambuc break;
91685fee539SLionel Sambuc }
91785fee539SLionel Sambuc fstdin = 0;
91885fee539SLionel Sambuc arcname = optarg;
91985fee539SLionel Sambuc break;
92085fee539SLionel Sambuc case 'h':
92185fee539SLionel Sambuc /*
92285fee539SLionel Sambuc * follow symlinks
92385fee539SLionel Sambuc */
92485fee539SLionel Sambuc Lflag = 1;
92585fee539SLionel Sambuc break;
92685fee539SLionel Sambuc case 'j':
92785fee539SLionel Sambuc /*
92885fee539SLionel Sambuc * pass through bzip2. not a standard option
92985fee539SLionel Sambuc */
93085fee539SLionel Sambuc gzip_program = BZIP2_CMD;
93185fee539SLionel Sambuc break;
93285fee539SLionel Sambuc case 'k':
93385fee539SLionel Sambuc /*
93485fee539SLionel Sambuc * do not clobber files that exist
93585fee539SLionel Sambuc */
93685fee539SLionel Sambuc kflag = 1;
93785fee539SLionel Sambuc break;
93885fee539SLionel Sambuc case 'l':
93985fee539SLionel Sambuc /*
94085fee539SLionel Sambuc * do not pass over mount points in the file system
94185fee539SLionel Sambuc */
94285fee539SLionel Sambuc Xflag = 1;
94385fee539SLionel Sambuc break;
94485fee539SLionel Sambuc case 'm':
94585fee539SLionel Sambuc /*
94685fee539SLionel Sambuc * do not preserve modification time
94785fee539SLionel Sambuc */
94885fee539SLionel Sambuc pmtime = 0;
94985fee539SLionel Sambuc break;
95085fee539SLionel Sambuc case 'o':
95185fee539SLionel Sambuc /*
95285fee539SLionel Sambuc * This option does several things based on whether
95385fee539SLionel Sambuc * this is a create or extract operation.
95485fee539SLionel Sambuc */
95585fee539SLionel Sambuc if (act == ARCHIVE) {
95685fee539SLionel Sambuc /* GNU tar: write V7 format archives. */
95785fee539SLionel Sambuc Oflag = 1;
95885fee539SLionel Sambuc /* 4.2BSD: don't add directory entries. */
95985fee539SLionel Sambuc if (opt_add("write_opt=nodir") < 0)
96085fee539SLionel Sambuc tar_usage();
96185fee539SLionel Sambuc
96285fee539SLionel Sambuc } else {
96385fee539SLionel Sambuc /* SUS: don't preserve owner/group. */
96485fee539SLionel Sambuc pids = 0;
96585fee539SLionel Sambuc nopids = 1;
96685fee539SLionel Sambuc }
96785fee539SLionel Sambuc break;
96885fee539SLionel Sambuc case 'p':
96985fee539SLionel Sambuc /*
97085fee539SLionel Sambuc * preserve user id, group id, file
97185fee539SLionel Sambuc * mode, access/modification times
97285fee539SLionel Sambuc */
97385fee539SLionel Sambuc if (!nopids)
97485fee539SLionel Sambuc pids = 1;
97585fee539SLionel Sambuc pmode = 1;
97685fee539SLionel Sambuc patime = 1;
97785fee539SLionel Sambuc pmtime = 1;
97885fee539SLionel Sambuc break;
97985fee539SLionel Sambuc case 'q':
98085fee539SLionel Sambuc /*
98185fee539SLionel Sambuc * select first match for a pattern only
98285fee539SLionel Sambuc */
98385fee539SLionel Sambuc nflag = 1;
98485fee539SLionel Sambuc break;
98585fee539SLionel Sambuc case 'r':
98685fee539SLionel Sambuc case 'u':
98785fee539SLionel Sambuc /*
98885fee539SLionel Sambuc * append to the archive
98985fee539SLionel Sambuc */
99085fee539SLionel Sambuc tar_set_action(APPND);
99185fee539SLionel Sambuc break;
99285fee539SLionel Sambuc case 's':
99385fee539SLionel Sambuc /*
99485fee539SLionel Sambuc * file name substitution name pattern
99585fee539SLionel Sambuc */
99685fee539SLionel Sambuc if (rep_add(optarg) < 0) {
99785fee539SLionel Sambuc tar_usage();
99885fee539SLionel Sambuc break;
99985fee539SLionel Sambuc }
100085fee539SLionel Sambuc break;
100185fee539SLionel Sambuc case 't':
100285fee539SLionel Sambuc /*
100385fee539SLionel Sambuc * list contents of the tape
100485fee539SLionel Sambuc */
100585fee539SLionel Sambuc tar_set_action(LIST);
100685fee539SLionel Sambuc break;
100785fee539SLionel Sambuc case 'v':
100885fee539SLionel Sambuc /*
100985fee539SLionel Sambuc * verbose operation mode
101085fee539SLionel Sambuc */
101185fee539SLionel Sambuc vflag = 1;
101285fee539SLionel Sambuc break;
101385fee539SLionel Sambuc case 'w':
101485fee539SLionel Sambuc /*
101585fee539SLionel Sambuc * interactive file rename
101685fee539SLionel Sambuc */
101785fee539SLionel Sambuc iflag = 1;
101885fee539SLionel Sambuc break;
101985fee539SLionel Sambuc case 'x':
102085fee539SLionel Sambuc /*
102185fee539SLionel Sambuc * extract an archive, preserving mode,
102285fee539SLionel Sambuc * and mtime if possible.
102385fee539SLionel Sambuc */
102485fee539SLionel Sambuc tar_set_action(EXTRACT);
102585fee539SLionel Sambuc pmtime = 1;
102685fee539SLionel Sambuc break;
102785fee539SLionel Sambuc case 'z':
102885fee539SLionel Sambuc /*
102985fee539SLionel Sambuc * use gzip. Non standard option.
103085fee539SLionel Sambuc */
103185fee539SLionel Sambuc gzip_program = GZIP_CMD;
103285fee539SLionel Sambuc break;
103385fee539SLionel Sambuc case 'B':
103485fee539SLionel Sambuc /*
103585fee539SLionel Sambuc * Nothing to do here, this is pax default
103685fee539SLionel Sambuc */
103785fee539SLionel Sambuc break;
103885fee539SLionel Sambuc case 'C':
103985fee539SLionel Sambuc havechd++;
104085fee539SLionel Sambuc chdname = optarg;
104185fee539SLionel Sambuc break;
104285fee539SLionel Sambuc case 'H':
104385fee539SLionel Sambuc /*
104485fee539SLionel Sambuc * follow command line symlinks only
104585fee539SLionel Sambuc */
104685fee539SLionel Sambuc Hflag = 1;
104785fee539SLionel Sambuc break;
104885fee539SLionel Sambuc case 'I':
104985fee539SLionel Sambuc case 'T':
105085fee539SLionel Sambuc if (++nincfiles > incfiles_max) {
105185fee539SLionel Sambuc incfiles_max = nincfiles + 3;
105285fee539SLionel Sambuc incfiles = realloc(incfiles,
105385fee539SLionel Sambuc sizeof(*incfiles) * incfiles_max);
105485fee539SLionel Sambuc if (incfiles == NULL) {
105585fee539SLionel Sambuc tty_warn(0, "Unable to allocate space "
105685fee539SLionel Sambuc "for option list");
105785fee539SLionel Sambuc exit(1);
105885fee539SLionel Sambuc }
105985fee539SLionel Sambuc }
106085fee539SLionel Sambuc incfiles[nincfiles - 1].file = optarg;
106185fee539SLionel Sambuc incfiles[nincfiles - 1].dir = chdname;
106285fee539SLionel Sambuc break;
1063*0a6a1f1dSLionel Sambuc case 'J':
1064*0a6a1f1dSLionel Sambuc gzip_program = XZ_CMD;
1065*0a6a1f1dSLionel Sambuc break;
1066*0a6a1f1dSLionel Sambuc case 'O':
1067*0a6a1f1dSLionel Sambuc Oflag = 1;
1068*0a6a1f1dSLionel Sambuc break;
106985fee539SLionel Sambuc case 'P':
107085fee539SLionel Sambuc /*
107185fee539SLionel Sambuc * do not remove leading '/' from pathnames
107285fee539SLionel Sambuc */
107385fee539SLionel Sambuc rmleadslash = 0;
107485fee539SLionel Sambuc Aflag = 1;
107585fee539SLionel Sambuc break;
107685fee539SLionel Sambuc case 'S':
107785fee539SLionel Sambuc /* do nothing; we already generate sparse files */
107885fee539SLionel Sambuc break;
107985fee539SLionel Sambuc case 'V':
108085fee539SLionel Sambuc /*
108185fee539SLionel Sambuc * semi-verbose operation mode (no listing)
108285fee539SLionel Sambuc */
108385fee539SLionel Sambuc Vflag = 1;
108485fee539SLionel Sambuc break;
108585fee539SLionel Sambuc case 'X':
108685fee539SLionel Sambuc /*
108785fee539SLionel Sambuc * GNU tar compat: exclude the files listed in optarg
108885fee539SLionel Sambuc */
108985fee539SLionel Sambuc if (tar_gnutar_X_compat(optarg) != 0)
109085fee539SLionel Sambuc tar_usage();
109185fee539SLionel Sambuc break;
109285fee539SLionel Sambuc case 'Z':
109385fee539SLionel Sambuc /*
109485fee539SLionel Sambuc * use compress.
109585fee539SLionel Sambuc */
109685fee539SLionel Sambuc gzip_program = COMPRESS_CMD;
109785fee539SLionel Sambuc break;
109885fee539SLionel Sambuc case '0':
109985fee539SLionel Sambuc arcname = DEV_0;
110085fee539SLionel Sambuc break;
110185fee539SLionel Sambuc case '1':
110285fee539SLionel Sambuc arcname = DEV_1;
110385fee539SLionel Sambuc break;
110485fee539SLionel Sambuc case '4':
110585fee539SLionel Sambuc arcname = DEV_4;
110685fee539SLionel Sambuc break;
110785fee539SLionel Sambuc case '5':
110885fee539SLionel Sambuc arcname = DEV_5;
110985fee539SLionel Sambuc break;
111085fee539SLionel Sambuc case '7':
111185fee539SLionel Sambuc arcname = DEV_7;
111285fee539SLionel Sambuc break;
111385fee539SLionel Sambuc case '8':
111485fee539SLionel Sambuc arcname = DEV_8;
111585fee539SLionel Sambuc break;
111685fee539SLionel Sambuc case OPT_ATIME_PRESERVE:
111785fee539SLionel Sambuc patime = 1;
111885fee539SLionel Sambuc break;
111985fee539SLionel Sambuc case OPT_UNLINK:
112085fee539SLionel Sambuc /* Just ignore -- we always unlink first. */
112185fee539SLionel Sambuc break;
112285fee539SLionel Sambuc case OPT_USE_COMPRESS_PROGRAM:
112385fee539SLionel Sambuc gzip_program = optarg;
112485fee539SLionel Sambuc break;
112585fee539SLionel Sambuc case OPT_FORCE_LOCAL:
112685fee539SLionel Sambuc forcelocal = 1;
112785fee539SLionel Sambuc break;
112885fee539SLionel Sambuc case OPT_INSECURE:
112985fee539SLionel Sambuc secure = 0;
113085fee539SLionel Sambuc break;
113185fee539SLionel Sambuc case OPT_STRICT:
113285fee539SLionel Sambuc /* disable gnu extensions */
113385fee539SLionel Sambuc is_gnutar = 0;
113485fee539SLionel Sambuc break;
113585fee539SLionel Sambuc case OPT_EXCLUDE:
113685fee539SLionel Sambuc if (tar_gnutar_minus_minus_exclude(optarg) != 0)
113785fee539SLionel Sambuc tar_usage();
113885fee539SLionel Sambuc break;
113985fee539SLionel Sambuc case OPT_NORECURSE:
114085fee539SLionel Sambuc dflag = 1;
114185fee539SLionel Sambuc break;
114285fee539SLionel Sambuc #if !HAVE_NBTOOL_CONFIG_H
114385fee539SLionel Sambuc case OPT_CHROOT:
114485fee539SLionel Sambuc do_chroot = 1;
114585fee539SLionel Sambuc break;
114685fee539SLionel Sambuc #endif
114785fee539SLionel Sambuc default:
114885fee539SLionel Sambuc tar_usage();
114985fee539SLionel Sambuc break;
115085fee539SLionel Sambuc }
115185fee539SLionel Sambuc }
115285fee539SLionel Sambuc argc -= optind;
115385fee539SLionel Sambuc argv += optind;
115485fee539SLionel Sambuc
115585fee539SLionel Sambuc /* Tar requires an action. */
115685fee539SLionel Sambuc if (act == ERROR)
115785fee539SLionel Sambuc tar_usage();
115885fee539SLionel Sambuc
115985fee539SLionel Sambuc /* Traditional tar behaviour (pax uses stderr unless in list mode) */
116085fee539SLionel Sambuc if (fstdin == 1 && act == ARCHIVE)
116185fee539SLionel Sambuc listf = stderr;
116285fee539SLionel Sambuc else
116385fee539SLionel Sambuc listf = stdout;
116485fee539SLionel Sambuc
116585fee539SLionel Sambuc /* Traditional tar behaviour (pax wants to read file list from stdin) */
116685fee539SLionel Sambuc if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0)
116785fee539SLionel Sambuc exit(0);
116885fee539SLionel Sambuc /*
116985fee539SLionel Sambuc * if we are writing (ARCHIVE) specify tar, otherwise run like pax
117085fee539SLionel Sambuc * (unless -o specified)
117185fee539SLionel Sambuc */
117285fee539SLionel Sambuc if (act == ARCHIVE || act == APPND)
117385fee539SLionel Sambuc frmt = &(fsub[Oflag ? F_TAR : F_USTAR]);
117485fee539SLionel Sambuc else if (Oflag) {
117585fee539SLionel Sambuc if (act == EXTRACT)
117685fee539SLionel Sambuc to_stdout = 1;
117785fee539SLionel Sambuc else {
117885fee539SLionel Sambuc tty_warn(1, "The -O/-o options are only valid when "
117985fee539SLionel Sambuc "writing or extracting an archive");
118085fee539SLionel Sambuc tar_usage();
118185fee539SLionel Sambuc }
118285fee539SLionel Sambuc }
118385fee539SLionel Sambuc
118485fee539SLionel Sambuc /*
118585fee539SLionel Sambuc * process the args as they are interpreted by the operation mode
118685fee539SLionel Sambuc */
118785fee539SLionel Sambuc switch (act) {
118885fee539SLionel Sambuc case LIST:
118985fee539SLionel Sambuc case EXTRACT:
119085fee539SLionel Sambuc default:
119185fee539SLionel Sambuc {
119285fee539SLionel Sambuc int sawpat = 0;
119385fee539SLionel Sambuc int dirisnext = 0;
119485fee539SLionel Sambuc char *file, *dir = NULL;
119585fee539SLionel Sambuc int mustfreedir = 0;
119685fee539SLionel Sambuc
119785fee539SLionel Sambuc while (nincfiles || *argv != NULL) {
119885fee539SLionel Sambuc /*
119985fee539SLionel Sambuc * If we queued up any include files,
120085fee539SLionel Sambuc * pull them in now. Otherwise, check
120185fee539SLionel Sambuc * for -I and -C positional flags.
120285fee539SLionel Sambuc * Anything else must be a file to
120385fee539SLionel Sambuc * extract.
120485fee539SLionel Sambuc */
120585fee539SLionel Sambuc if (nincfiles) {
120685fee539SLionel Sambuc file = incfiles->file;
120785fee539SLionel Sambuc dir = incfiles->dir;
120885fee539SLionel Sambuc mustfreedir = 0;
120985fee539SLionel Sambuc incfiles++;
121085fee539SLionel Sambuc nincfiles--;
121185fee539SLionel Sambuc } else if (strcmp(*argv, "-I") == 0) {
121285fee539SLionel Sambuc if (*++argv == NULL)
121385fee539SLionel Sambuc break;
121485fee539SLionel Sambuc file = *argv++;
121585fee539SLionel Sambuc dir = chdname;
121685fee539SLionel Sambuc mustfreedir = 0;
121785fee539SLionel Sambuc } else {
121885fee539SLionel Sambuc file = NULL;
121985fee539SLionel Sambuc dir = NULL;
122085fee539SLionel Sambuc mustfreedir = 0;
122185fee539SLionel Sambuc }
122285fee539SLionel Sambuc if (file != NULL) {
122385fee539SLionel Sambuc FILE *fp;
122485fee539SLionel Sambuc char *str;
122585fee539SLionel Sambuc
122685fee539SLionel Sambuc if (strcmp(file, "-") == 0)
122785fee539SLionel Sambuc fp = stdin;
122885fee539SLionel Sambuc else if ((fp = fopen(file, "r")) == NULL) {
122985fee539SLionel Sambuc tty_warn(1, "Unable to open file '%s' for read", file);
123085fee539SLionel Sambuc tar_usage();
123185fee539SLionel Sambuc }
123285fee539SLionel Sambuc while ((str = get_line(fp)) != NULL) {
123385fee539SLionel Sambuc if (dirisnext) {
123485fee539SLionel Sambuc if (dir && mustfreedir)
123585fee539SLionel Sambuc free(dir);
123685fee539SLionel Sambuc dir = str;
123785fee539SLionel Sambuc mustfreedir = 1;
123885fee539SLionel Sambuc dirisnext = 0;
123985fee539SLionel Sambuc continue;
124085fee539SLionel Sambuc }
124185fee539SLionel Sambuc if (strcmp(str, "-C") == 0) {
124285fee539SLionel Sambuc havechd++;
124385fee539SLionel Sambuc dirisnext = 1;
124485fee539SLionel Sambuc free(str);
124585fee539SLionel Sambuc continue;
124685fee539SLionel Sambuc }
124785fee539SLionel Sambuc if (strncmp(str, "-C ", 3) == 0) {
124885fee539SLionel Sambuc havechd++;
124985fee539SLionel Sambuc if (dir && mustfreedir)
125085fee539SLionel Sambuc free(dir);
125185fee539SLionel Sambuc dir = strdup(str + 3);
125285fee539SLionel Sambuc mustfreedir = 1;
125385fee539SLionel Sambuc free(str);
125485fee539SLionel Sambuc continue;
125585fee539SLionel Sambuc }
125685fee539SLionel Sambuc if (pat_add(str, dir, NOGLOB_MTCH) < 0)
125785fee539SLionel Sambuc tar_usage();
125885fee539SLionel Sambuc sawpat = 1;
125985fee539SLionel Sambuc }
126085fee539SLionel Sambuc /* Bomb if given -C w/out a dir. */
126185fee539SLionel Sambuc if (dirisnext)
126285fee539SLionel Sambuc tar_usage();
126385fee539SLionel Sambuc if (dir && mustfreedir)
126485fee539SLionel Sambuc free(dir);
126585fee539SLionel Sambuc if (strcmp(file, "-") != 0)
126685fee539SLionel Sambuc fclose(fp);
126785fee539SLionel Sambuc if (get_line_error) {
126885fee539SLionel Sambuc tty_warn(1, "Problem with file '%s'", file);
126985fee539SLionel Sambuc tar_usage();
127085fee539SLionel Sambuc }
127185fee539SLionel Sambuc } else if (strcmp(*argv, "-C") == 0) {
127285fee539SLionel Sambuc if (*++argv == NULL)
127385fee539SLionel Sambuc break;
127485fee539SLionel Sambuc chdname = *argv++;
127585fee539SLionel Sambuc havechd++;
127685fee539SLionel Sambuc } else if (pat_add(*argv++, chdname, 0) < 0)
127785fee539SLionel Sambuc tar_usage();
127885fee539SLionel Sambuc else
127985fee539SLionel Sambuc sawpat = 1;
128085fee539SLionel Sambuc }
128185fee539SLionel Sambuc /*
128285fee539SLionel Sambuc * if patterns were added, we are doing chdir()
128385fee539SLionel Sambuc * on a file-by-file basis, else, just one
128485fee539SLionel Sambuc * global chdir (if any) after opening input.
128585fee539SLionel Sambuc */
128685fee539SLionel Sambuc if (sawpat > 0)
128785fee539SLionel Sambuc chdname = NULL;
128885fee539SLionel Sambuc }
128985fee539SLionel Sambuc break;
129085fee539SLionel Sambuc case ARCHIVE:
129185fee539SLionel Sambuc case APPND:
129285fee539SLionel Sambuc if (chdname != NULL) { /* initial chdir() */
129385fee539SLionel Sambuc if (ftree_add(chdname, 1) < 0)
129485fee539SLionel Sambuc tar_usage();
129585fee539SLionel Sambuc }
129685fee539SLionel Sambuc
129785fee539SLionel Sambuc while (nincfiles || *argv != NULL) {
129885fee539SLionel Sambuc char *file, *dir;
129985fee539SLionel Sambuc
130085fee539SLionel Sambuc /*
130185fee539SLionel Sambuc * If we queued up any include files, pull them in
130285fee539SLionel Sambuc * now. Otherwise, check for -I and -C positional
130385fee539SLionel Sambuc * flags. Anything else must be a file to include
130485fee539SLionel Sambuc * in the archive.
130585fee539SLionel Sambuc */
130685fee539SLionel Sambuc if (nincfiles) {
130785fee539SLionel Sambuc file = incfiles->file;
130885fee539SLionel Sambuc dir = incfiles->dir;
130985fee539SLionel Sambuc incfiles++;
131085fee539SLionel Sambuc nincfiles--;
131185fee539SLionel Sambuc } else if (strcmp(*argv, "-I") == 0) {
131285fee539SLionel Sambuc if (*++argv == NULL)
131385fee539SLionel Sambuc break;
131485fee539SLionel Sambuc file = *argv++;
131585fee539SLionel Sambuc dir = NULL;
131685fee539SLionel Sambuc } else {
131785fee539SLionel Sambuc file = NULL;
131885fee539SLionel Sambuc dir = NULL;
131985fee539SLionel Sambuc }
132085fee539SLionel Sambuc if (file != NULL) {
132185fee539SLionel Sambuc FILE *fp;
132285fee539SLionel Sambuc char *str;
132385fee539SLionel Sambuc int dirisnext = 0;
132485fee539SLionel Sambuc
132585fee539SLionel Sambuc /* Set directory if needed */
132685fee539SLionel Sambuc if (dir) {
132785fee539SLionel Sambuc if (ftree_add(dir, 1) < 0)
132885fee539SLionel Sambuc tar_usage();
132985fee539SLionel Sambuc }
133085fee539SLionel Sambuc
133185fee539SLionel Sambuc if (strcmp(file, "-") == 0)
133285fee539SLionel Sambuc fp = stdin;
133385fee539SLionel Sambuc else if ((fp = fopen(file, "r")) == NULL) {
133485fee539SLionel Sambuc tty_warn(1, "Unable to open file '%s' for read", file);
133585fee539SLionel Sambuc tar_usage();
133685fee539SLionel Sambuc }
133785fee539SLionel Sambuc while ((str = get_line(fp)) != NULL) {
133885fee539SLionel Sambuc if (dirisnext) {
133985fee539SLionel Sambuc if (ftree_add(str, 1) < 0)
134085fee539SLionel Sambuc tar_usage();
134185fee539SLionel Sambuc dirisnext = 0;
134285fee539SLionel Sambuc continue;
134385fee539SLionel Sambuc }
134485fee539SLionel Sambuc if (strcmp(str, "-C") == 0) {
134585fee539SLionel Sambuc dirisnext = 1;
134685fee539SLionel Sambuc continue;
134785fee539SLionel Sambuc }
134885fee539SLionel Sambuc if (strncmp(str, "-C ", 3) == 0) {
134985fee539SLionel Sambuc if (ftree_add(str + 3, 1) < 0)
135085fee539SLionel Sambuc tar_usage();
135185fee539SLionel Sambuc continue;
135285fee539SLionel Sambuc }
135385fee539SLionel Sambuc if (ftree_add(str, 0) < 0)
135485fee539SLionel Sambuc tar_usage();
135585fee539SLionel Sambuc }
135685fee539SLionel Sambuc /* Bomb if given -C w/out a dir. */
135785fee539SLionel Sambuc if (dirisnext)
135885fee539SLionel Sambuc tar_usage();
135985fee539SLionel Sambuc if (strcmp(file, "-") != 0)
136085fee539SLionel Sambuc fclose(fp);
136185fee539SLionel Sambuc if (get_line_error) {
136285fee539SLionel Sambuc tty_warn(1, "Problem with file '%s'",
136385fee539SLionel Sambuc file);
136485fee539SLionel Sambuc tar_usage();
136585fee539SLionel Sambuc }
136685fee539SLionel Sambuc } else if (strcmp(*argv, "-C") == 0) {
136785fee539SLionel Sambuc if (*++argv == NULL)
136885fee539SLionel Sambuc break;
136985fee539SLionel Sambuc if (ftree_add(*argv++, 1) < 0)
137085fee539SLionel Sambuc tar_usage();
137185fee539SLionel Sambuc } else if (ftree_add(*argv++, 0) < 0)
137285fee539SLionel Sambuc tar_usage();
137385fee539SLionel Sambuc }
137485fee539SLionel Sambuc /*
137585fee539SLionel Sambuc * no read errors allowed on updates/append operation!
137685fee539SLionel Sambuc */
137785fee539SLionel Sambuc maxflt = 0;
137885fee539SLionel Sambuc break;
137985fee539SLionel Sambuc }
138085fee539SLionel Sambuc if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) {
138185fee539SLionel Sambuc arcname = getenv("TAPE");
138285fee539SLionel Sambuc if ((arcname == NULL) || (*arcname == '\0'))
138385fee539SLionel Sambuc arcname = _PATH_DEFTAPE;
138485fee539SLionel Sambuc }
138585fee539SLionel Sambuc }
138685fee539SLionel Sambuc
138785fee539SLionel Sambuc int
mkpath(char * path)138885fee539SLionel Sambuc mkpath(char *path)
138985fee539SLionel Sambuc {
139085fee539SLionel Sambuc char *slash;
139185fee539SLionel Sambuc int done = 0;
139285fee539SLionel Sambuc
139385fee539SLionel Sambuc slash = path;
139485fee539SLionel Sambuc
139585fee539SLionel Sambuc while (!done) {
139685fee539SLionel Sambuc slash += strspn(slash, "/");
139785fee539SLionel Sambuc slash += strcspn(slash, "/");
139885fee539SLionel Sambuc
139985fee539SLionel Sambuc done = (*slash == '\0');
140085fee539SLionel Sambuc *slash = '\0';
140185fee539SLionel Sambuc
140285fee539SLionel Sambuc if (domkdir(path, 0777) == -1)
140385fee539SLionel Sambuc goto out;
140485fee539SLionel Sambuc
140585fee539SLionel Sambuc if (!done)
140685fee539SLionel Sambuc *slash = '/';
140785fee539SLionel Sambuc }
140885fee539SLionel Sambuc
140985fee539SLionel Sambuc return 0;
141085fee539SLionel Sambuc out:
141185fee539SLionel Sambuc /* Can't create or or not a directory */
141285fee539SLionel Sambuc syswarn(1, errno, "Cannot create directory `%s'", path);
141385fee539SLionel Sambuc return -1;
141485fee539SLionel Sambuc }
141585fee539SLionel Sambuc
141685fee539SLionel Sambuc
141785fee539SLionel Sambuc #ifndef NO_CPIO
141885fee539SLionel Sambuc struct option cpio_longopts[] = {
141985fee539SLionel Sambuc { "reset-access-time", no_argument, 0, 'a' },
142085fee539SLionel Sambuc { "make-directories", no_argument, 0, 'd' },
142185fee539SLionel Sambuc { "nonmatching", no_argument, 0, 'f' },
142285fee539SLionel Sambuc { "extract", no_argument, 0, 'i' },
142385fee539SLionel Sambuc { "link", no_argument, 0, 'l' },
142485fee539SLionel Sambuc { "preserve-modification-time", no_argument, 0, 'm' },
142585fee539SLionel Sambuc { "create", no_argument, 0, 'o' },
142685fee539SLionel Sambuc { "pass-through", no_argument, 0, 'p' },
142785fee539SLionel Sambuc { "rename", no_argument, 0, 'r' },
142885fee539SLionel Sambuc { "list", no_argument, 0, 't' },
142985fee539SLionel Sambuc { "unconditional", no_argument, 0, 'u' },
143085fee539SLionel Sambuc { "verbose", no_argument, 0, 'v' },
143185fee539SLionel Sambuc { "append", no_argument, 0, 'A' },
143285fee539SLionel Sambuc { "pattern-file", required_argument, 0, 'E' },
143385fee539SLionel Sambuc { "file", required_argument, 0, 'F' },
143485fee539SLionel Sambuc { "force-local", no_argument, 0,
143585fee539SLionel Sambuc OPT_FORCE_LOCAL },
143685fee539SLionel Sambuc { "format", required_argument, 0, 'H' },
143785fee539SLionel Sambuc { "dereference", no_argument, 0, 'L' },
143885fee539SLionel Sambuc { "swap-halfwords", no_argument, 0, 'S' },
143985fee539SLionel Sambuc { "summary", no_argument, 0, 'V' },
144085fee539SLionel Sambuc { "stats", no_argument, 0, 'V' },
144185fee539SLionel Sambuc { "insecure", no_argument, 0,
144285fee539SLionel Sambuc OPT_INSECURE },
144385fee539SLionel Sambuc { "sparse", no_argument, 0,
144485fee539SLionel Sambuc OPT_SPARSE },
144585fee539SLionel Sambuc { "xz", no_argument, 0,
144685fee539SLionel Sambuc OPT_XZ },
144785fee539SLionel Sambuc
144885fee539SLionel Sambuc #ifdef notyet
144985fee539SLionel Sambuc /* Not implemented */
145085fee539SLionel Sambuc { "null", no_argument, 0, '0' },
145185fee539SLionel Sambuc { "swap", no_argument, 0, 'b' },
145285fee539SLionel Sambuc { "numeric-uid-gid", no_argument, 0, 'n' },
145385fee539SLionel Sambuc { "swap-bytes", no_argument, 0, 's' },
145485fee539SLionel Sambuc { "message", required_argument, 0, 'M' },
145585fee539SLionel Sambuc { "owner", required_argument, 0 'R' },
145685fee539SLionel Sambuc { "dot", no_argument, 0, 'V' }, /* xxx */
145785fee539SLionel Sambuc { "block-size", required_argument, 0,
145885fee539SLionel Sambuc OPT_BLOCK_SIZE },
145985fee539SLionel Sambuc { "no-absolute-pathnames", no_argument, 0,
146085fee539SLionel Sambuc OPT_NO_ABSOLUTE_PATHNAMES },
146185fee539SLionel Sambuc { "no-preserve-owner", no_argument, 0,
146285fee539SLionel Sambuc OPT_NO_PRESERVE_OWNER },
146385fee539SLionel Sambuc { "only-verify-crc", no_argument, 0,
146485fee539SLionel Sambuc OPT_ONLY_VERIFY_CRC },
146585fee539SLionel Sambuc { "rsh-command", required_argument, 0,
146685fee539SLionel Sambuc OPT_RSH_COMMAND },
146785fee539SLionel Sambuc { "version", no_argument, 0,
146885fee539SLionel Sambuc OPT_VERSION },
146985fee539SLionel Sambuc #endif
147085fee539SLionel Sambuc { 0, 0, 0, 0 },
147185fee539SLionel Sambuc };
147285fee539SLionel Sambuc
147385fee539SLionel Sambuc static void
cpio_set_action(int op)147485fee539SLionel Sambuc cpio_set_action(int op)
147585fee539SLionel Sambuc {
147685fee539SLionel Sambuc if ((act == APPND && op == ARCHIVE) || (act == ARCHIVE && op == APPND))
147785fee539SLionel Sambuc act = APPND;
147885fee539SLionel Sambuc else if (act == EXTRACT && op == LIST)
147985fee539SLionel Sambuc act = op;
148085fee539SLionel Sambuc else if (act != ERROR && act != op)
148185fee539SLionel Sambuc cpio_usage();
148285fee539SLionel Sambuc else
148385fee539SLionel Sambuc act = op;
148485fee539SLionel Sambuc }
148585fee539SLionel Sambuc
148685fee539SLionel Sambuc /*
148785fee539SLionel Sambuc * cpio_options()
148885fee539SLionel Sambuc * look at the user specified flags. set globals as required and check if
148985fee539SLionel Sambuc * the user specified a legal set of flags. If not, complain and exit
149085fee539SLionel Sambuc */
149185fee539SLionel Sambuc
149285fee539SLionel Sambuc static void
cpio_options(int argc,char ** argv)149385fee539SLionel Sambuc cpio_options(int argc, char **argv)
149485fee539SLionel Sambuc {
149585fee539SLionel Sambuc FSUB tmp;
149685fee539SLionel Sambuc u_int64_t flg = 0;
149785fee539SLionel Sambuc u_int64_t bflg = 0;
149885fee539SLionel Sambuc int c;
149985fee539SLionel Sambuc size_t i;
150085fee539SLionel Sambuc FILE *fp;
150185fee539SLionel Sambuc char *str;
150285fee539SLionel Sambuc
150385fee539SLionel Sambuc uflag = 1;
150485fee539SLionel Sambuc kflag = 1;
150585fee539SLionel Sambuc pids = 1;
150685fee539SLionel Sambuc pmode = 1;
150785fee539SLionel Sambuc pmtime = 0;
150885fee539SLionel Sambuc arcname = NULL;
150985fee539SLionel Sambuc dflag = 1;
151085fee539SLionel Sambuc nodirs = 1;
151185fee539SLionel Sambuc /*
151285fee539SLionel Sambuc * process option flags
151385fee539SLionel Sambuc */
151485fee539SLionel Sambuc while ((c = getoldopt(argc, argv,
151585fee539SLionel Sambuc "+abcdfiklmoprstuvzABC:E:F:H:I:LM:O:R:SVZ6",
151685fee539SLionel Sambuc cpio_longopts, NULL)) != -1) {
151785fee539SLionel Sambuc switch(c) {
151885fee539SLionel Sambuc case 'a':
151985fee539SLionel Sambuc /*
152085fee539SLionel Sambuc * preserve access time on filesystem nodes we read
152185fee539SLionel Sambuc */
152285fee539SLionel Sambuc tflag = 1;
152385fee539SLionel Sambuc flg |= TF;
152485fee539SLionel Sambuc break;
152585fee539SLionel Sambuc #ifdef notyet
152685fee539SLionel Sambuc case 'b':
152785fee539SLionel Sambuc /*
152885fee539SLionel Sambuc * swap bytes and half-words when reading data
152985fee539SLionel Sambuc */
153085fee539SLionel Sambuc break;
153185fee539SLionel Sambuc #endif
153285fee539SLionel Sambuc case 'c':
153385fee539SLionel Sambuc /*
153485fee539SLionel Sambuc * ASCII cpio header
153585fee539SLionel Sambuc */
153685fee539SLionel Sambuc frmt = &fsub[F_SV4CPIO];
153785fee539SLionel Sambuc break;
153885fee539SLionel Sambuc case 'd':
153985fee539SLionel Sambuc /*
154085fee539SLionel Sambuc * create directories as needed
154185fee539SLionel Sambuc * pax does this by default ..
154285fee539SLionel Sambuc */
154385fee539SLionel Sambuc nodirs = 0;
154485fee539SLionel Sambuc break;
154585fee539SLionel Sambuc case 'f':
154685fee539SLionel Sambuc /*
154785fee539SLionel Sambuc * inverse match on patterns
154885fee539SLionel Sambuc */
154985fee539SLionel Sambuc cflag = 1;
155085fee539SLionel Sambuc flg |= CF;
155185fee539SLionel Sambuc break;
155285fee539SLionel Sambuc case 'i':
155385fee539SLionel Sambuc /*
155485fee539SLionel Sambuc * read the archive
155585fee539SLionel Sambuc */
155685fee539SLionel Sambuc cpio_set_action(EXTRACT);
155785fee539SLionel Sambuc flg |= RF;
155885fee539SLionel Sambuc break;
155985fee539SLionel Sambuc #ifdef notyet
156085fee539SLionel Sambuc case 'k':
156185fee539SLionel Sambuc break;
156285fee539SLionel Sambuc #endif
156385fee539SLionel Sambuc case 'l':
156485fee539SLionel Sambuc /*
156585fee539SLionel Sambuc * try to link src to dest with copy (-rw)
156685fee539SLionel Sambuc */
156785fee539SLionel Sambuc lflag = 1;
156885fee539SLionel Sambuc flg |= LF;
156985fee539SLionel Sambuc break;
157085fee539SLionel Sambuc case 'm':
157185fee539SLionel Sambuc /*
157285fee539SLionel Sambuc * preserve mtime
157385fee539SLionel Sambuc */
157485fee539SLionel Sambuc flg |= PF;
157585fee539SLionel Sambuc pmtime = 1;
157685fee539SLionel Sambuc break;
157785fee539SLionel Sambuc case 'o':
157885fee539SLionel Sambuc /*
157985fee539SLionel Sambuc * write an archive
158085fee539SLionel Sambuc */
158185fee539SLionel Sambuc cpio_set_action(ARCHIVE);
158285fee539SLionel Sambuc frmt = &(fsub[F_SV4CRC]);
158385fee539SLionel Sambuc flg |= WF;
158485fee539SLionel Sambuc break;
158585fee539SLionel Sambuc case 'p':
158685fee539SLionel Sambuc /*
158785fee539SLionel Sambuc * cpio -p is like pax -rw
158885fee539SLionel Sambuc */
158985fee539SLionel Sambuc cpio_set_action(COPY);
159085fee539SLionel Sambuc flg |= RF | WF;
159185fee539SLionel Sambuc break;
159285fee539SLionel Sambuc case 'r':
159385fee539SLionel Sambuc /*
159485fee539SLionel Sambuc * interactive file rename
159585fee539SLionel Sambuc */
159685fee539SLionel Sambuc iflag = 1;
159785fee539SLionel Sambuc flg |= IF;
159885fee539SLionel Sambuc break;
159985fee539SLionel Sambuc #ifdef notyet
160085fee539SLionel Sambuc case 's':
160185fee539SLionel Sambuc /*
160285fee539SLionel Sambuc * swap bytes after reading data
160385fee539SLionel Sambuc */
160485fee539SLionel Sambuc break;
160585fee539SLionel Sambuc #endif
160685fee539SLionel Sambuc case 't':
160785fee539SLionel Sambuc /*
160885fee539SLionel Sambuc * list contents of archive
160985fee539SLionel Sambuc */
161085fee539SLionel Sambuc cpio_set_action(LIST);
161185fee539SLionel Sambuc listf = stdout;
161285fee539SLionel Sambuc flg &= ~RF;
161385fee539SLionel Sambuc break;
161485fee539SLionel Sambuc case 'u':
161585fee539SLionel Sambuc /*
161685fee539SLionel Sambuc * don't ignore those older files
161785fee539SLionel Sambuc */
161885fee539SLionel Sambuc uflag = 0;
161985fee539SLionel Sambuc kflag = 0;
162085fee539SLionel Sambuc flg |= UF;
162185fee539SLionel Sambuc break;
162285fee539SLionel Sambuc case 'v':
162385fee539SLionel Sambuc /*
162485fee539SLionel Sambuc * verbose operation mode
162585fee539SLionel Sambuc */
162685fee539SLionel Sambuc vflag = 1;
162785fee539SLionel Sambuc flg |= VF;
162885fee539SLionel Sambuc break;
162985fee539SLionel Sambuc case 'z':
163085fee539SLionel Sambuc /*
163185fee539SLionel Sambuc * use gzip. Non standard option.
163285fee539SLionel Sambuc */
163385fee539SLionel Sambuc gzip_program = GZIP_CMD;
163485fee539SLionel Sambuc break;
163585fee539SLionel Sambuc case 'A':
163685fee539SLionel Sambuc /*
163785fee539SLionel Sambuc * append to an archive
163885fee539SLionel Sambuc */
163985fee539SLionel Sambuc cpio_set_action(APPND);
164085fee539SLionel Sambuc flg |= AF;
164185fee539SLionel Sambuc break;
164285fee539SLionel Sambuc case 'B':
164385fee539SLionel Sambuc /*
164485fee539SLionel Sambuc * set blocksize to 5120
164585fee539SLionel Sambuc */
164685fee539SLionel Sambuc blksz = 5120;
164785fee539SLionel Sambuc break;
164885fee539SLionel Sambuc case 'C':
164985fee539SLionel Sambuc /*
165085fee539SLionel Sambuc * specify blocksize
165185fee539SLionel Sambuc */
165285fee539SLionel Sambuc if ((blksz = (int)str_offt(optarg)) <= 0) {
165385fee539SLionel Sambuc tty_warn(1, "Invalid block size %s", optarg);
165485fee539SLionel Sambuc cpio_usage();
165585fee539SLionel Sambuc }
165685fee539SLionel Sambuc break;
165785fee539SLionel Sambuc case 'E':
165885fee539SLionel Sambuc /*
165985fee539SLionel Sambuc * file with patterns to extract or list
166085fee539SLionel Sambuc */
166185fee539SLionel Sambuc if ((fp = fopen(optarg, "r")) == NULL) {
166285fee539SLionel Sambuc tty_warn(1, "Unable to open file '%s' for read",
166385fee539SLionel Sambuc optarg);
166485fee539SLionel Sambuc cpio_usage();
166585fee539SLionel Sambuc }
166685fee539SLionel Sambuc while ((str = get_line(fp)) != NULL) {
166785fee539SLionel Sambuc pat_add(str, NULL, 0);
166885fee539SLionel Sambuc }
166985fee539SLionel Sambuc fclose(fp);
167085fee539SLionel Sambuc if (get_line_error) {
167185fee539SLionel Sambuc tty_warn(1, "Problem with file '%s'", optarg);
167285fee539SLionel Sambuc cpio_usage();
167385fee539SLionel Sambuc }
167485fee539SLionel Sambuc break;
167585fee539SLionel Sambuc case 'H':
167685fee539SLionel Sambuc /*
167785fee539SLionel Sambuc * specify an archive format on write
167885fee539SLionel Sambuc */
167985fee539SLionel Sambuc tmp.name = optarg;
168085fee539SLionel Sambuc frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
168185fee539SLionel Sambuc sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt);
168285fee539SLionel Sambuc if (frmt != NULL) {
168385fee539SLionel Sambuc flg |= XF;
168485fee539SLionel Sambuc break;
168585fee539SLionel Sambuc }
168685fee539SLionel Sambuc tty_warn(1, "Unknown -H format: %s", optarg);
168785fee539SLionel Sambuc (void)fputs("cpio: Known -H formats are:", stderr);
168885fee539SLionel Sambuc for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
168985fee539SLionel Sambuc (void)fprintf(stderr, " %s", fsub[i].name);
169085fee539SLionel Sambuc (void)fputs("\n\n", stderr);
169185fee539SLionel Sambuc cpio_usage();
169285fee539SLionel Sambuc break;
169385fee539SLionel Sambuc case 'F':
169485fee539SLionel Sambuc case 'I':
169585fee539SLionel Sambuc case 'O':
169685fee539SLionel Sambuc /*
169785fee539SLionel Sambuc * filename where the archive is stored
169885fee539SLionel Sambuc */
169985fee539SLionel Sambuc if ((optarg[0] == '-') && (optarg[1]== '\0')) {
170085fee539SLionel Sambuc /*
170185fee539SLionel Sambuc * treat a - as stdin
170285fee539SLionel Sambuc */
170385fee539SLionel Sambuc arcname = NULL;
170485fee539SLionel Sambuc break;
170585fee539SLionel Sambuc }
170685fee539SLionel Sambuc arcname = optarg;
170785fee539SLionel Sambuc break;
170885fee539SLionel Sambuc case 'L':
170985fee539SLionel Sambuc /*
171085fee539SLionel Sambuc * follow symlinks
171185fee539SLionel Sambuc */
171285fee539SLionel Sambuc Lflag = 1;
171385fee539SLionel Sambuc flg |= CLF;
171485fee539SLionel Sambuc break;
171585fee539SLionel Sambuc #ifdef notyet
171685fee539SLionel Sambuc case 'M':
171785fee539SLionel Sambuc arg = optarg;
171885fee539SLionel Sambuc break;
171985fee539SLionel Sambuc case 'R':
172085fee539SLionel Sambuc arg = optarg;
172185fee539SLionel Sambuc break;
172285fee539SLionel Sambuc #endif
172385fee539SLionel Sambuc case 'S':
172485fee539SLionel Sambuc /*
172585fee539SLionel Sambuc * swap halfwords after reading data
172685fee539SLionel Sambuc */
172785fee539SLionel Sambuc cpio_swp_head = 1;
172885fee539SLionel Sambuc break;
172985fee539SLionel Sambuc #ifdef notyet
173085fee539SLionel Sambuc case 'V': /* print a '.' for each file processed */
173185fee539SLionel Sambuc break;
173285fee539SLionel Sambuc #endif
173385fee539SLionel Sambuc case 'V':
173485fee539SLionel Sambuc /*
173585fee539SLionel Sambuc * semi-verbose operation mode (no listing)
173685fee539SLionel Sambuc */
173785fee539SLionel Sambuc Vflag = 1;
173885fee539SLionel Sambuc flg |= VF;
173985fee539SLionel Sambuc break;
174085fee539SLionel Sambuc case 'Z':
174185fee539SLionel Sambuc /*
174285fee539SLionel Sambuc * use compress. Non standard option.
174385fee539SLionel Sambuc */
174485fee539SLionel Sambuc gzip_program = COMPRESS_CMD;
174585fee539SLionel Sambuc break;
174685fee539SLionel Sambuc case '6':
174785fee539SLionel Sambuc /*
174885fee539SLionel Sambuc * process Version 6 cpio format
174985fee539SLionel Sambuc */
175085fee539SLionel Sambuc frmt = &(fsub[F_BCPIO]);
175185fee539SLionel Sambuc break;
175285fee539SLionel Sambuc case OPT_FORCE_LOCAL:
175385fee539SLionel Sambuc forcelocal = 1;
175485fee539SLionel Sambuc break;
175585fee539SLionel Sambuc case OPT_INSECURE:
175685fee539SLionel Sambuc secure = 0;
175785fee539SLionel Sambuc break;
175885fee539SLionel Sambuc case OPT_SPARSE:
175985fee539SLionel Sambuc /* do nothing; we already generate sparse files */
176085fee539SLionel Sambuc break;
176185fee539SLionel Sambuc case OPT_XZ:
176285fee539SLionel Sambuc gzip_program = XZ_CMD;
176385fee539SLionel Sambuc break;
176485fee539SLionel Sambuc default:
176585fee539SLionel Sambuc cpio_usage();
176685fee539SLionel Sambuc break;
176785fee539SLionel Sambuc }
176885fee539SLionel Sambuc }
176985fee539SLionel Sambuc
177085fee539SLionel Sambuc /*
177185fee539SLionel Sambuc * figure out the operation mode of cpio. check that we have not been
177285fee539SLionel Sambuc * given a bogus set of flags for the operation mode.
177385fee539SLionel Sambuc */
177485fee539SLionel Sambuc if (ISLIST(flg)) {
177585fee539SLionel Sambuc act = LIST;
177685fee539SLionel Sambuc bflg = flg & BDLIST;
177785fee539SLionel Sambuc } else if (ISEXTRACT(flg)) {
177885fee539SLionel Sambuc act = EXTRACT;
177985fee539SLionel Sambuc bflg = flg & BDEXTR;
178085fee539SLionel Sambuc } else if (ISARCHIVE(flg)) {
178185fee539SLionel Sambuc act = ARCHIVE;
178285fee539SLionel Sambuc bflg = flg & BDARCH;
178385fee539SLionel Sambuc } else if (ISAPPND(flg)) {
178485fee539SLionel Sambuc act = APPND;
178585fee539SLionel Sambuc bflg = flg & BDARCH;
178685fee539SLionel Sambuc } else if (ISCOPY(flg)) {
178785fee539SLionel Sambuc act = COPY;
178885fee539SLionel Sambuc bflg = flg & BDCOPY;
178985fee539SLionel Sambuc } else
179085fee539SLionel Sambuc cpio_usage();
179185fee539SLionel Sambuc if (bflg) {
179285fee539SLionel Sambuc cpio_usage();
179385fee539SLionel Sambuc }
179485fee539SLionel Sambuc
179585fee539SLionel Sambuc /*
179685fee539SLionel Sambuc * if we are writing (ARCHIVE) we use the default format if the user
179785fee539SLionel Sambuc * did not specify a format. when we write during an APPEND, we will
179885fee539SLionel Sambuc * adopt the format of the existing archive if none was supplied.
179985fee539SLionel Sambuc */
180085fee539SLionel Sambuc if (!(flg & XF) && (act == ARCHIVE))
180185fee539SLionel Sambuc frmt = &(fsub[F_BCPIO]);
180285fee539SLionel Sambuc
180385fee539SLionel Sambuc /*
180485fee539SLionel Sambuc * process the args as they are interpreted by the operation mode
180585fee539SLionel Sambuc */
180685fee539SLionel Sambuc switch (act) {
180785fee539SLionel Sambuc case LIST:
180885fee539SLionel Sambuc case EXTRACT:
180985fee539SLionel Sambuc for (; optind < argc; optind++)
181085fee539SLionel Sambuc if (pat_add(argv[optind], NULL, 0) < 0)
181185fee539SLionel Sambuc cpio_usage();
181285fee539SLionel Sambuc break;
181385fee539SLionel Sambuc case COPY:
181485fee539SLionel Sambuc if (optind >= argc) {
181585fee539SLionel Sambuc tty_warn(0, "Destination directory was not supplied");
181685fee539SLionel Sambuc cpio_usage();
181785fee539SLionel Sambuc }
181885fee539SLionel Sambuc --argc;
181985fee539SLionel Sambuc dirptr = argv[argc];
182085fee539SLionel Sambuc /* FALLTHROUGH */
182185fee539SLionel Sambuc case ARCHIVE:
182285fee539SLionel Sambuc case APPND:
182385fee539SLionel Sambuc if (argc != optind) {
182485fee539SLionel Sambuc for (; optind < argc; optind++)
182585fee539SLionel Sambuc if (ftree_add(argv[optind], 0) < 0)
182685fee539SLionel Sambuc cpio_usage();
182785fee539SLionel Sambuc break;
182885fee539SLionel Sambuc }
182985fee539SLionel Sambuc /*
183085fee539SLionel Sambuc * no read errors allowed on updates/append operation!
183185fee539SLionel Sambuc */
183285fee539SLionel Sambuc maxflt = 0;
183385fee539SLionel Sambuc while ((str = get_line(stdin)) != NULL) {
183485fee539SLionel Sambuc ftree_add(str, 0);
183585fee539SLionel Sambuc }
183685fee539SLionel Sambuc if (get_line_error) {
183785fee539SLionel Sambuc tty_warn(1, "Problem while reading stdin");
183885fee539SLionel Sambuc cpio_usage();
183985fee539SLionel Sambuc }
184085fee539SLionel Sambuc break;
184185fee539SLionel Sambuc default:
184285fee539SLionel Sambuc cpio_usage();
184385fee539SLionel Sambuc break;
184485fee539SLionel Sambuc }
184585fee539SLionel Sambuc }
184685fee539SLionel Sambuc #endif
184785fee539SLionel Sambuc
184885fee539SLionel Sambuc /*
184985fee539SLionel Sambuc * printflg()
185085fee539SLionel Sambuc * print out those invalid flag sets found to the user
185185fee539SLionel Sambuc */
185285fee539SLionel Sambuc
185385fee539SLionel Sambuc static void
printflg(unsigned int flg)185485fee539SLionel Sambuc printflg(unsigned int flg)
185585fee539SLionel Sambuc {
185685fee539SLionel Sambuc int nxt;
185785fee539SLionel Sambuc
185885fee539SLionel Sambuc (void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
185985fee539SLionel Sambuc while ((nxt = ffs(flg)) != 0) {
186085fee539SLionel Sambuc flg &= ~(1 << (nxt - 1));
186185fee539SLionel Sambuc (void)fprintf(stderr, " -%c", flgch[nxt - 1]);
186285fee539SLionel Sambuc }
186385fee539SLionel Sambuc (void)putc('\n', stderr);
186485fee539SLionel Sambuc }
186585fee539SLionel Sambuc
186685fee539SLionel Sambuc /*
186785fee539SLionel Sambuc * c_frmt()
186885fee539SLionel Sambuc * comparison routine used by bsearch to find the format specified
186985fee539SLionel Sambuc * by the user
187085fee539SLionel Sambuc */
187185fee539SLionel Sambuc
187285fee539SLionel Sambuc static int
c_frmt(const void * a,const void * b)187385fee539SLionel Sambuc c_frmt(const void *a, const void *b)
187485fee539SLionel Sambuc {
187585fee539SLionel Sambuc return strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name);
187685fee539SLionel Sambuc }
187785fee539SLionel Sambuc
187885fee539SLionel Sambuc /*
187985fee539SLionel Sambuc * opt_next()
188085fee539SLionel Sambuc * called by format specific options routines to get each format specific
188185fee539SLionel Sambuc * flag and value specified with -o
188285fee539SLionel Sambuc * Return:
188385fee539SLionel Sambuc * pointer to next OPLIST entry or NULL (end of list).
188485fee539SLionel Sambuc */
188585fee539SLionel Sambuc
188685fee539SLionel Sambuc OPLIST *
opt_next(void)188785fee539SLionel Sambuc opt_next(void)
188885fee539SLionel Sambuc {
188985fee539SLionel Sambuc OPLIST *opt;
189085fee539SLionel Sambuc
189185fee539SLionel Sambuc if ((opt = ophead) != NULL)
189285fee539SLionel Sambuc ophead = ophead->fow;
189385fee539SLionel Sambuc return opt;
189485fee539SLionel Sambuc }
189585fee539SLionel Sambuc
189685fee539SLionel Sambuc /*
189785fee539SLionel Sambuc * bad_opt()
189885fee539SLionel Sambuc * generic routine used to complain about a format specific options
189985fee539SLionel Sambuc * when the format does not support options.
190085fee539SLionel Sambuc */
190185fee539SLionel Sambuc
190285fee539SLionel Sambuc int
bad_opt(void)190385fee539SLionel Sambuc bad_opt(void)
190485fee539SLionel Sambuc {
190585fee539SLionel Sambuc OPLIST *opt;
190685fee539SLionel Sambuc
190785fee539SLionel Sambuc if (ophead == NULL)
190885fee539SLionel Sambuc return 0;
190985fee539SLionel Sambuc /*
191085fee539SLionel Sambuc * print all we were given
191185fee539SLionel Sambuc */
191285fee539SLionel Sambuc tty_warn(1," These format options are not supported for %s",
191385fee539SLionel Sambuc frmt->name);
191485fee539SLionel Sambuc while ((opt = opt_next()) != NULL)
191585fee539SLionel Sambuc (void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);
191685fee539SLionel Sambuc if (strcmp(NM_TAR, argv0) == 0)
191785fee539SLionel Sambuc tar_usage();
191885fee539SLionel Sambuc #ifndef NO_CPIO
191985fee539SLionel Sambuc else if (strcmp(NM_CPIO, argv0) == 0)
192085fee539SLionel Sambuc cpio_usage();
192185fee539SLionel Sambuc #endif
192285fee539SLionel Sambuc else
192385fee539SLionel Sambuc pax_usage();
192485fee539SLionel Sambuc return 0;
192585fee539SLionel Sambuc }
192685fee539SLionel Sambuc
192785fee539SLionel Sambuc /*
192885fee539SLionel Sambuc * opt_add()
192985fee539SLionel Sambuc * breaks the value supplied to -o into a option name and value. options
193085fee539SLionel Sambuc * are given to -o in the form -o name-value,name=value
193185fee539SLionel Sambuc * multiple -o may be specified.
193285fee539SLionel Sambuc * Return:
193385fee539SLionel Sambuc * 0 if format in name=value format, -1 if -o is passed junk
193485fee539SLionel Sambuc */
193585fee539SLionel Sambuc
193685fee539SLionel Sambuc int
opt_add(const char * str)193785fee539SLionel Sambuc opt_add(const char *str)
193885fee539SLionel Sambuc {
193985fee539SLionel Sambuc OPLIST *opt;
194085fee539SLionel Sambuc char *frpt;
194185fee539SLionel Sambuc char *pt;
194285fee539SLionel Sambuc char *endpt;
194385fee539SLionel Sambuc char *dstr;
194485fee539SLionel Sambuc
194585fee539SLionel Sambuc if ((str == NULL) || (*str == '\0')) {
194685fee539SLionel Sambuc tty_warn(0, "Invalid option name");
194785fee539SLionel Sambuc return -1;
194885fee539SLionel Sambuc }
194985fee539SLionel Sambuc if ((dstr = strdup(str)) == NULL) {
195085fee539SLionel Sambuc tty_warn(0, "Unable to allocate space for option list");
195185fee539SLionel Sambuc return -1;
195285fee539SLionel Sambuc }
195385fee539SLionel Sambuc frpt = endpt = dstr;
195485fee539SLionel Sambuc
195585fee539SLionel Sambuc /*
195685fee539SLionel Sambuc * break into name and values pieces and stuff each one into a
195785fee539SLionel Sambuc * OPLIST structure. When we know the format, the format specific
195885fee539SLionel Sambuc * option function will go through this list
195985fee539SLionel Sambuc */
196085fee539SLionel Sambuc while ((frpt != NULL) && (*frpt != '\0')) {
196185fee539SLionel Sambuc if ((endpt = strchr(frpt, ',')) != NULL)
196285fee539SLionel Sambuc *endpt = '\0';
196385fee539SLionel Sambuc if ((pt = strchr(frpt, '=')) == NULL) {
196485fee539SLionel Sambuc tty_warn(0, "Invalid options format");
196585fee539SLionel Sambuc free(dstr);
196685fee539SLionel Sambuc return -1;
196785fee539SLionel Sambuc }
196885fee539SLionel Sambuc if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
196985fee539SLionel Sambuc tty_warn(0, "Unable to allocate space for option list");
197085fee539SLionel Sambuc free(dstr);
197185fee539SLionel Sambuc return -1;
197285fee539SLionel Sambuc }
197385fee539SLionel Sambuc *pt++ = '\0';
197485fee539SLionel Sambuc opt->name = frpt;
197585fee539SLionel Sambuc opt->value = pt;
197685fee539SLionel Sambuc opt->fow = NULL;
197785fee539SLionel Sambuc if (endpt != NULL)
197885fee539SLionel Sambuc frpt = endpt + 1;
197985fee539SLionel Sambuc else
198085fee539SLionel Sambuc frpt = NULL;
198185fee539SLionel Sambuc if (ophead == NULL) {
198285fee539SLionel Sambuc optail = ophead = opt;
198385fee539SLionel Sambuc continue;
198485fee539SLionel Sambuc }
198585fee539SLionel Sambuc optail->fow = opt;
198685fee539SLionel Sambuc optail = opt;
198785fee539SLionel Sambuc }
198885fee539SLionel Sambuc return 0;
198985fee539SLionel Sambuc }
199085fee539SLionel Sambuc
199185fee539SLionel Sambuc /*
199285fee539SLionel Sambuc * str_offt()
199385fee539SLionel Sambuc * Convert an expression of the following forms to an off_t > 0.
199485fee539SLionel Sambuc * 1) A positive decimal number.
199585fee539SLionel Sambuc * 2) A positive decimal number followed by a b (mult by 512).
199685fee539SLionel Sambuc * 3) A positive decimal number followed by a k (mult by 1024).
199785fee539SLionel Sambuc * 4) A positive decimal number followed by a m (mult by 512).
199885fee539SLionel Sambuc * 5) A positive decimal number followed by a w (mult by sizeof int)
199985fee539SLionel Sambuc * 6) Two or more positive decimal numbers (with/without k,b or w).
200085fee539SLionel Sambuc * separated by x (also * for backwards compatibility), specifying
200185fee539SLionel Sambuc * the product of the indicated values.
200285fee539SLionel Sambuc * Return:
200385fee539SLionel Sambuc * 0 for an error, a positive value o.w.
200485fee539SLionel Sambuc */
200585fee539SLionel Sambuc
200685fee539SLionel Sambuc static off_t
str_offt(char * val)200785fee539SLionel Sambuc str_offt(char *val)
200885fee539SLionel Sambuc {
200985fee539SLionel Sambuc char *expr;
201085fee539SLionel Sambuc off_t num, t;
201185fee539SLionel Sambuc
201285fee539SLionel Sambuc num = STRTOOFFT(val, &expr, 0);
201385fee539SLionel Sambuc if ((num == OFFT_MAX) || (num <= 0) || (expr == val))
201485fee539SLionel Sambuc return 0;
201585fee539SLionel Sambuc
201685fee539SLionel Sambuc switch(*expr) {
201785fee539SLionel Sambuc case 'b':
201885fee539SLionel Sambuc t = num;
201985fee539SLionel Sambuc num *= 512;
202085fee539SLionel Sambuc if (t > num)
202185fee539SLionel Sambuc return 0;
202285fee539SLionel Sambuc ++expr;
202385fee539SLionel Sambuc break;
202485fee539SLionel Sambuc case 'k':
202585fee539SLionel Sambuc t = num;
202685fee539SLionel Sambuc num *= 1024;
202785fee539SLionel Sambuc if (t > num)
202885fee539SLionel Sambuc return 0;
202985fee539SLionel Sambuc ++expr;
203085fee539SLionel Sambuc break;
203185fee539SLionel Sambuc case 'm':
203285fee539SLionel Sambuc t = num;
203385fee539SLionel Sambuc num *= 1048576;
203485fee539SLionel Sambuc if (t > num)
203585fee539SLionel Sambuc return 0;
203685fee539SLionel Sambuc ++expr;
203785fee539SLionel Sambuc break;
203885fee539SLionel Sambuc case 'w':
203985fee539SLionel Sambuc t = num;
204085fee539SLionel Sambuc num *= sizeof(int);
204185fee539SLionel Sambuc if (t > num)
204285fee539SLionel Sambuc return 0;
204385fee539SLionel Sambuc ++expr;
204485fee539SLionel Sambuc break;
204585fee539SLionel Sambuc }
204685fee539SLionel Sambuc
204785fee539SLionel Sambuc switch(*expr) {
204885fee539SLionel Sambuc case '\0':
204985fee539SLionel Sambuc break;
205085fee539SLionel Sambuc case '*':
205185fee539SLionel Sambuc case 'x':
205285fee539SLionel Sambuc t = num;
205385fee539SLionel Sambuc num *= str_offt(expr + 1);
205485fee539SLionel Sambuc if (t > num)
205585fee539SLionel Sambuc return 0;
205685fee539SLionel Sambuc break;
205785fee539SLionel Sambuc default:
205885fee539SLionel Sambuc return 0;
205985fee539SLionel Sambuc }
206085fee539SLionel Sambuc return num;
206185fee539SLionel Sambuc }
206285fee539SLionel Sambuc
206385fee539SLionel Sambuc static char *
get_line(FILE * f)206485fee539SLionel Sambuc get_line(FILE *f)
206585fee539SLionel Sambuc {
206685fee539SLionel Sambuc char *name, *temp;
206785fee539SLionel Sambuc size_t len;
206885fee539SLionel Sambuc
206985fee539SLionel Sambuc name = fgetln(f, &len);
207085fee539SLionel Sambuc if (!name) {
207185fee539SLionel Sambuc get_line_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0;
207285fee539SLionel Sambuc return 0;
207385fee539SLionel Sambuc }
207485fee539SLionel Sambuc if (name[len-1] != '\n')
207585fee539SLionel Sambuc len++;
207685fee539SLionel Sambuc temp = malloc(len);
207785fee539SLionel Sambuc if (!temp) {
207885fee539SLionel Sambuc get_line_error = GETLINE_OUT_OF_MEM;
207985fee539SLionel Sambuc return 0;
208085fee539SLionel Sambuc }
208185fee539SLionel Sambuc memcpy(temp, name, len-1);
208285fee539SLionel Sambuc temp[len-1] = 0;
208385fee539SLionel Sambuc return temp;
208485fee539SLionel Sambuc }
208585fee539SLionel Sambuc
208685fee539SLionel Sambuc /*
208785fee539SLionel Sambuc * no_op()
208885fee539SLionel Sambuc * for those option functions where the archive format has nothing to do.
208985fee539SLionel Sambuc * Return:
209085fee539SLionel Sambuc * 0
209185fee539SLionel Sambuc */
209285fee539SLionel Sambuc
209385fee539SLionel Sambuc static int
no_op(void)209485fee539SLionel Sambuc no_op(void)
209585fee539SLionel Sambuc {
209685fee539SLionel Sambuc return 0;
209785fee539SLionel Sambuc }
209885fee539SLionel Sambuc
209985fee539SLionel Sambuc /*
210085fee539SLionel Sambuc * pax_usage()
210185fee539SLionel Sambuc * print the usage summary to the user
210285fee539SLionel Sambuc */
210385fee539SLionel Sambuc
210485fee539SLionel Sambuc static void
pax_usage(void)210585fee539SLionel Sambuc pax_usage(void)
210685fee539SLionel Sambuc {
210785fee539SLionel Sambuc fprintf(stderr,
210885fee539SLionel Sambuc "usage: pax [-0cdjnvzVO] [-E limit] [-f archive] [-N dbdir] [-s replstr] ...\n"
210985fee539SLionel Sambuc " [-U user] ... [-G group] ... [-T [from_date][,to_date]] ...\n"
211085fee539SLionel Sambuc " [pattern ...]\n");
211185fee539SLionel Sambuc fprintf(stderr,
211285fee539SLionel Sambuc " pax -r [-cdijknuvzADOVYZ] [-E limit] [-f archive] [-N dbdir]\n"
211385fee539SLionel Sambuc " [-o options] ... [-p string] ... [-s replstr] ... [-U user] ...\n"
211485fee539SLionel Sambuc " [-G group] ... [-T [from_date][,to_date]] ... [pattern ...]\n");
211585fee539SLionel Sambuc fprintf(stderr,
211685fee539SLionel Sambuc " pax -w [-dijtuvzAHLMOPVX] [-b blocksize] [[-a] [-f archive]] [-x format]\n"
211785fee539SLionel Sambuc " [-B bytes] [-N dbdir] [-o options] ... [-s replstr] ...\n"
211885fee539SLionel Sambuc " [-U user] ... [-G group] ...\n"
211985fee539SLionel Sambuc " [-T [from_date][,to_date][/[c][m]]] ... [file ...]\n");
212085fee539SLionel Sambuc fprintf(stderr,
212185fee539SLionel Sambuc " pax -r -w [-dijklntuvzADHLMOPVXYZ] [-N dbdir] [-p string] ...\n"
212285fee539SLionel Sambuc " [-s replstr] ... [-U user] ... [-G group] ...\n"
212385fee539SLionel Sambuc " [-T [from_date][,to_date][/[c][m]]] ... [file ...] directory\n");
212485fee539SLionel Sambuc exit(1);
212585fee539SLionel Sambuc /* NOTREACHED */
212685fee539SLionel Sambuc }
212785fee539SLionel Sambuc
212885fee539SLionel Sambuc /*
212985fee539SLionel Sambuc * tar_usage()
213085fee539SLionel Sambuc * print the usage summary to the user
213185fee539SLionel Sambuc */
213285fee539SLionel Sambuc
213385fee539SLionel Sambuc static void
tar_usage(void)213485fee539SLionel Sambuc tar_usage(void)
213585fee539SLionel Sambuc {
2136*0a6a1f1dSLionel Sambuc (void)fputs("usage: tar [-]{crtux}[-befhjklmopqvwzHJOPSXZ014578] "
2137*0a6a1f1dSLionel Sambuc "[archive] [blocksize]\n"
213885fee539SLionel Sambuc " [-C directory] [-T file] [-s replstr] "
213985fee539SLionel Sambuc "[file ...]\n", stderr);
214085fee539SLionel Sambuc exit(1);
214185fee539SLionel Sambuc /* NOTREACHED */
214285fee539SLionel Sambuc }
214385fee539SLionel Sambuc
214485fee539SLionel Sambuc #ifndef NO_CPIO
214585fee539SLionel Sambuc /*
214685fee539SLionel Sambuc * cpio_usage()
214785fee539SLionel Sambuc * print the usage summary to the user
214885fee539SLionel Sambuc */
214985fee539SLionel Sambuc
215085fee539SLionel Sambuc static void
cpio_usage(void)215185fee539SLionel Sambuc cpio_usage(void)
215285fee539SLionel Sambuc {
215385fee539SLionel Sambuc
215485fee539SLionel Sambuc (void)fputs("usage: cpio -o [-aABcLvzZ] [-C bytes] [-F archive] "
215585fee539SLionel Sambuc "[-H format] [-O archive]\n"
215685fee539SLionel Sambuc " < name-list [> archive]\n"
215785fee539SLionel Sambuc " cpio -i [-bBcdfmrsStuvzZ6] [-C bytes] [-E file] "
215885fee539SLionel Sambuc "[-F archive] [-H format] \n"
215985fee539SLionel Sambuc " [-I archive] "
216085fee539SLionel Sambuc "[pattern ...] [< archive]\n"
216185fee539SLionel Sambuc " cpio -p [-adlLmuv] destination-directory "
216285fee539SLionel Sambuc "< name-list\n", stderr);
216385fee539SLionel Sambuc exit(1);
216485fee539SLionel Sambuc /* NOTREACHED */
216585fee539SLionel Sambuc }
216685fee539SLionel Sambuc #endif
2167