-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.c
2113 lines (2019 loc) · 44 KB
/
options.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* $NetBSD: options.c,v 1.11 2010/03/21 16:35:01 joerg Exp $ */
/*-
* Copyright (c) 1992 Keith Muller.
* Copyright (c) 1992, 1993
* The Regents of the University of California. All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Keith Muller of the University of California, San Diego.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#if HAVE_CONFIG_H
#include "config.h"
#endif
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
#include <nbcompat.h>
#if HAVE_SYS_CDEFS_H
#include <sys/cdefs.h>
#endif
#if !defined(lint)
#if 0
static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94";
#else
__RCSID("$NetBSD: options.c,v 1.11 2010/03/21 16:35:01 joerg Exp $");
#endif
#endif /* not lint */
#if HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#if HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#if HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#if HAVE_SYS_MTIO_H
#include <sys/mtio.h>
#endif
#if HAVE_SYS_PARAM_H
#include <sys/param.h>
#endif
#if HAVE_CTYPE_H
#include <ctype.h>
#endif
#if HAVE_ERRNO_H
#include <errno.h>
#endif
#if HAVE_NBTOOL_CONFIG_H
#include "compat_getopt.h"
#else
#if HAVE_GETOPT_H
#include <getopt.h>
#endif
#endif
#if HAVE_LIMITS_H
#include <limits.h>
#endif
#if HAVE_STDIO_H
#include <stdio.h>
#endif
#if HAVE_STDLIB_H
#include <stdlib.h>
#endif
#if HAVE_STRING_H
#include <string.h>
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#endif
#if HAVE_PATHS_H
#include <paths.h>
#endif
#include "pax.h"
#include "options.h"
#include "cpio.h"
#include "tar.h"
#include "extern.h"
#ifndef SMALL
#include "mtree.h"
#endif /* SMALL */
/*
* Routines which handle command line options
*/
static int nopids; /* tar mode: suppress "pids" for -p option */
static char flgch[] = FLGCH; /* list of all possible flags (pax) */
static OPLIST *ophead = NULL; /* head for format specific options -x */
static OPLIST *optail = NULL; /* option tail */
static int no_op(void);
static void printflg(unsigned int);
static int c_frmt(const void *, const void *);
static off_t str_offt(char *);
static char *get_line(FILE *fp);
static void pax_options(int, char **);
static void pax_usage(void);
static void tar_options(int, char **);
static void tar_usage(void);
#ifndef NO_CPIO
static void cpio_options(int, char **);
static void cpio_usage(void);
#endif
/* errors from get_line */
#define GETLINE_FILE_CORRUPT 1
#define GETLINE_OUT_OF_MEM 2
static int getline_error;
#define BZIP2_CMD "bzip2" /* command to run as bzip2 */
#define GZIP_CMD "gzip" /* command to run as gzip */
#define COMPRESS_CMD "compress" /* command to run as compress */
/*
* Long options.
*/
#define OPT_USE_COMPRESS_PROGRAM 0
#define OPT_CHECKPOINT 1
#define OPT_UNLINK 2
#define OPT_HELP 3
#define OPT_ATIME_PRESERVE 4
#define OPT_IGNORE_FAILED_READ 5
#define OPT_REMOVE_FILES 6
#define OPT_NULL 7
#define OPT_TOTALS 8
#define OPT_VERSION 9
#define OPT_EXCLUDE 10
#define OPT_BLOCK_COMPRESS 11
#define OPT_NORECURSE 12
#define OPT_FORCE_LOCAL 13
#define OPT_INSECURE 14
#define OPT_STRICT 15
#define OPT_SPARSE 16
#if !HAVE_NBTOOL_CONFIG_H
#ifdef HAVE_FCHROOT
#define OPT_CHROOT 17
#endif /* HAVE_FCHROOT */
#endif
/*
* Format specific routine table - MUST BE IN SORTED ORDER BY NAME
* (see pax.h for description of each function)
*
* name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
* read, end_read, st_write, write, end_write, trail,
* subtrail, rd_data, wr_data, options
*/
FSUB fsub[] = {
#ifndef NO_CPIO
/* 0: OLD BINARY CPIO */
{ "bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, NULL,
cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
/* 1: OLD OCTAL CHARACTER CPIO */
{ "cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, NULL,
cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
/* 2: SVR4 HEX CPIO */
{ "sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, NULL,
cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
/* 3: SVR4 HEX CPIO WITH CRC */
{ "sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, NULL,
cpio_subtrail, rd_wrfile, wr_rdfile, bad_opt },
#endif
/* 4: OLD TAR */
{ "tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
NULL, rd_wrfile, wr_rdfile, tar_opt },
/* 5: POSIX USTAR */
{ "ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
NULL, rd_wrfile, wr_rdfile, bad_opt }
};
#ifndef NO_CPIO
#define F_BCPIO 0 /* old binary cpio format */
#define F_CPIO 1 /* old octal character cpio format */
#define F_SV4CPIO 2 /* SVR4 hex cpio format */
#define F_SV4CRC 3 /* SVR4 hex with crc cpio format */
#define F_TAR 4 /* old V7 UNIX tar format */
#define F_USTAR 5 /* ustar format */
#else
#define F_TAR 0 /* old V7 UNIX tar format */
#define F_USTAR 1 /* ustar format */
#endif
#define DEFLT F_USTAR /* default write format from list above */
/*
* ford is the archive search order used by get_arc() to determine what kind
* of archive we are dealing with. This helps to properly id archive formats
* some formats may be subsets of others....
*/
int ford[] = {F_USTAR, F_TAR,
#ifndef NO_CPIO
F_SV4CRC, F_SV4CPIO, F_CPIO, F_BCPIO,
#endif
-1};
/*
* filename record separator
*/
int sep = '\n';
/*
* options()
* figure out if we are pax, tar or cpio. Call the appropriate options
* parser
*/
void
options(int argc, char **argv)
{
/*
* Are we acting like pax, tar or cpio (based on argv[0])
*/
if ((argv0 = strrchr(argv[0], '/')) != NULL)
argv0++;
else
argv0 = argv[0];
if (strstr(argv0, NM_TAR)) {
argv0 = NM_TAR;
tar_options(argc, argv);
#ifndef NO_CPIO
} else if (strstr(argv0, NM_CPIO)) {
argv0 = NM_CPIO;
cpio_options(argc, argv);
#endif
} else {
argv0 = NM_PAX;
pax_options(argc, argv);
}
}
struct option pax_longopts[] = {
{ "insecure", no_argument, 0,
OPT_INSECURE },
{ "force-local", no_argument, 0,
OPT_FORCE_LOCAL },
{ 0, 0, 0 },
};
/*
* pax_options()
* look at the user specified flags. set globals as required and check if
* the user specified a legal set of flags. If not, complain and exit
*/
static void
pax_options(int argc, char **argv)
{
int c;
int i;
unsigned int flg = 0;
unsigned int bflg = 0;
char *pt;
FSUB tmp;
/*
* process option flags
*/
while ((c = getopt_long(argc, argv,
"0ab:cdf:ijklno:p:rs:tuvwx:zAB:DE:G:HLMN:OPT:U:XYZ",
pax_longopts, NULL)) != -1) {
switch (c) {
case '0':
sep = '\0';
break;
case 'a':
/*
* append
*/
flg |= AF;
break;
case 'b':
/*
* specify blocksize
*/
flg |= BF;
if ((wrblksz = (int)str_offt(optarg)) <= 0) {
tty_warn(1, "Invalid block size %s", optarg);
pax_usage();
}
break;
case 'c':
/*
* inverse match on patterns
*/
cflag = 1;
flg |= CF;
break;
case 'd':
/*
* match only dir on extract, not the subtree at dir
*/
dflag = 1;
flg |= DF;
break;
case 'f':
/*
* filename where the archive is stored
*/
arcname = optarg;
flg |= FF;
break;
case 'i':
/*
* interactive file rename
*/
iflag = 1;
flg |= IF;
break;
case 'j':
/*
* pass through bzip2
*/
jflag = 1;
gzip_program = BZIP2_CMD;
break;
case 'k':
/*
* do not clobber files that exist
*/
kflag = 1;
flg |= KF;
break;
case 'l':
/*
* try to link src to dest with copy (-rw)
*/
lflag = 1;
flg |= LF;
break;
case 'n':
/*
* select first match for a pattern only
*/
nflag = 1;
flg |= NF;
break;
case 'o':
/*
* pass format specific options
*/
flg |= OF;
if (opt_add(optarg) < 0)
pax_usage();
break;
case 'p':
/*
* specify file characteristic options
*/
for (pt = optarg; *pt != '\0'; ++pt) {
switch(*pt) {
case 'a':
/*
* do not preserve access time
*/
patime = 0;
break;
case 'e':
/*
* preserve user id, group id, file
* mode, access/modification times
* and file flags.
*/
pids = 1;
pmode = 1;
patime = 1;
pmtime = 1;
pfflags = 1;
break;
#if 0
case 'f':
/*
* do not preserve file flags
*/
pfflags = 0;
break;
#endif
case 'm':
/*
* do not preserve modification time
*/
pmtime = 0;
break;
case 'o':
/*
* preserve uid/gid
*/
pids = 1;
break;
case 'p':
/*
* preserve file mode bits
*/
pmode = 1;
break;
default:
tty_warn(1, "Invalid -p string: %c",
*pt);
pax_usage();
break;
}
}
flg |= PF;
break;
case 'r':
/*
* read the archive
*/
flg |= RF;
break;
case 's':
/*
* file name substitution name pattern
*/
if (rep_add(optarg) < 0) {
pax_usage();
break;
}
flg |= SF;
break;
case 't':
/*
* preserve access time on filesystem nodes we read
*/
tflag = 1;
flg |= TF;
break;
case 'u':
/*
* ignore those older files
*/
uflag = 1;
flg |= UF;
break;
case 'v':
/*
* verbose operation mode
*/
vflag = 1;
flg |= VF;
break;
case 'w':
/*
* write an archive
*/
flg |= WF;
break;
case 'x':
/*
* specify an archive format on write
*/
tmp.name = optarg;
frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt);
if (frmt != NULL) {
flg |= XF;
break;
}
tty_warn(1, "Unknown -x format: %s", optarg);
(void)fputs("pax: Known -x formats are:", stderr);
for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
(void)fprintf(stderr, " %s", fsub[i].name);
(void)fputs("\n\n", stderr);
pax_usage();
break;
case 'z':
/*
* use gzip. Non standard option.
*/
gzip_program = GZIP_CMD;
break;
case 'A':
Aflag = 1;
flg |= CAF;
break;
case 'B':
/*
* non-standard option on number of bytes written on a
* single archive volume.
*/
if ((wrlimit = str_offt(optarg)) <= 0) {
tty_warn(1, "Invalid write limit %s", optarg);
pax_usage();
}
if (wrlimit % BLKMULT) {
tty_warn(1,
"Write limit is not a %d byte multiple",
BLKMULT);
pax_usage();
}
flg |= CBF;
break;
case 'D':
/*
* On extraction check file inode change time before the
* modification of the file name. Non standard option.
*/
Dflag = 1;
flg |= CDF;
break;
case 'E':
/*
* non-standard limit on read faults
* 0 indicates stop after first error, values
* indicate a limit, "none" try forever
*/
flg |= CEF;
if (strcmp(none, optarg) == 0)
maxflt = -1;
else if ((maxflt = atoi(optarg)) < 0) {
tty_warn(1,
"Error count value must be positive");
pax_usage();
}
break;
case 'G':
/*
* non-standard option for selecting files within an
* archive by group (gid or name)
*/
if (grp_add(optarg) < 0) {
pax_usage();
break;
}
flg |= CGF;
break;
case 'H':
/*
* follow command line symlinks only
*/
Hflag = 1;
flg |= CHF;
break;
case 'L':
/*
* follow symlinks
*/
Lflag = 1;
flg |= CLF;
break;
#ifdef SMALL
case 'M':
case 'N':
tty_warn(1, "Support for -%c is not compiled in", c);
exit(1);
#else /* !SMALL */
case 'M':
/*
* Treat list of filenames on stdin as an
* mtree(8) specfile. Non standard option.
*/
Mflag = 1;
flg |= CMF;
break;
case 'N':
/*
* Use alternative directory for user db lookups.
*/
if (!setup_getid(optarg)) {
tty_warn(1,
"Unable to use user and group databases in `%s'",
optarg);
pax_usage();
}
break;
#endif /* !SMALL */
case 'O':
/*
* Force one volume. Non standard option.
*/
force_one_volume = 1;
break;
case 'P':
/*
* do NOT follow symlinks (default)
*/
Lflag = 0;
flg |= CPF;
break;
case 'T':
/*
* non-standard option for selecting files within an
* archive by modification time range (lower,upper)
*/
if (trng_add(optarg) < 0) {
pax_usage();
break;
}
flg |= CTF;
break;
case 'U':
/*
* non-standard option for selecting files within an
* archive by user (uid or name)
*/
if (usr_add(optarg) < 0) {
pax_usage();
break;
}
flg |= CUF;
break;
case 'X':
/*
* do not pass over mount points in the file system
*/
Xflag = 1;
flg |= CXF;
break;
case 'Y':
/*
* On extraction check file inode change time after the
* modification of the file name. Non standard option.
*/
Yflag = 1;
flg |= CYF;
break;
case 'Z':
/*
* On extraction check modification time after the
* modification of the file name. Non standard option.
*/
Zflag = 1;
flg |= CZF;
break;
case OPT_INSECURE:
secure = 0;
break;
case OPT_FORCE_LOCAL:
forcelocal = 0;
break;
case '?':
default:
pax_usage();
break;
}
}
/*
* figure out the operation mode of pax read,write,extract,copy,append
* or list. check that we have not been given a bogus set of flags
* for the operation mode.
*/
if (ISLIST(flg)) {
act = LIST;
listf = stdout;
bflg = flg & BDLIST;
} else if (ISEXTRACT(flg)) {
act = EXTRACT;
bflg = flg & BDEXTR;
} else if (ISARCHIVE(flg)) {
act = ARCHIVE;
bflg = flg & BDARCH;
} else if (ISAPPND(flg)) {
act = APPND;
bflg = flg & BDARCH;
} else if (ISCOPY(flg)) {
act = COPY;
bflg = flg & BDCOPY;
} else
pax_usage();
if (bflg) {
printflg(flg);
pax_usage();
}
/*
* if we are writing (ARCHIVE) we use the default format if the user
* did not specify a format. when we write during an APPEND, we will
* adopt the format of the existing archive if none was supplied.
*/
if (!(flg & XF) && (act == ARCHIVE))
frmt = &(fsub[DEFLT]);
/*
* process the args as they are interpreted by the operation mode
*/
switch (act) {
case LIST:
case EXTRACT:
for (; optind < argc; optind++)
if (pat_add(argv[optind], NULL) < 0)
pax_usage();
break;
case COPY:
if (optind >= argc) {
tty_warn(0, "Destination directory was not supplied");
pax_usage();
}
--argc;
dirptr = argv[argc];
if (mkpath(dirptr) < 0)
exit(1);
/* FALLTHROUGH */
case ARCHIVE:
case APPND:
for (; optind < argc; optind++)
if (ftree_add(argv[optind], 0) < 0)
pax_usage();
/*
* no read errors allowed on updates/append operation!
*/
maxflt = 0;
break;
}
}
/*
* tar_options()
* look at the user specified flags. set globals as required and check if
* the user specified a legal set of flags. If not, complain and exit
*/
struct option tar_longopts[] = {
{ "block-size", required_argument, 0, 'b' },
{ "bunzip2", no_argument, 0, 'j' },
{ "bzip2", no_argument, 0, 'j' },
{ "create", no_argument, 0, 'c' }, /* F */
/* -e -- no corresponding long option */
{ "file", required_argument, 0, 'f' },
{ "dereference", no_argument, 0, 'h' },
{ "keep-old-files", no_argument, 0, 'k' },
{ "one-file-system", no_argument, 0, 'l' },
{ "modification-time", no_argument, 0, 'm' },
{ "old-archive", no_argument, 0, 'o' },
{ "portability", no_argument, 0, 'o' },
{ "same-permissions", no_argument, 0, 'p' },
{ "preserve-permissions", no_argument, 0, 'p' },
{ "preserve", no_argument, 0, 'p' },
{ "fast-read", no_argument, 0, 'q' },
{ "append", no_argument, 0, 'r' }, /* F */
{ "update", no_argument, 0, 'u' }, /* F */
{ "list", no_argument, 0, 't' }, /* F */
{ "verbose", no_argument, 0, 'v' },
{ "interactive", no_argument, 0, 'w' },
{ "confirmation", no_argument, 0, 'w' },
{ "extract", no_argument, 0, 'x' }, /* F */
{ "get", no_argument, 0, 'x' }, /* F */
{ "gzip", no_argument, 0, 'z' },
{ "gunzip", no_argument, 0, 'z' },
{ "read-full-blocks", no_argument, 0, 'B' },
{ "directory", required_argument, 0, 'C' },
{ "to-stdout", no_argument, 0, 'O' },
{ "absolute-paths", no_argument, 0, 'P' },
{ "sparse", no_argument, 0, 'S' },
{ "files-from", required_argument, 0, 'T' },
{ "exclude-from", required_argument, 0, 'X' },
{ "compress", no_argument, 0, 'Z' },
{ "uncompress", no_argument, 0, 'Z' },
{ "strict", no_argument, 0,
OPT_STRICT },
{ "atime-preserve", no_argument, 0,
OPT_ATIME_PRESERVE },
{ "unlink", no_argument, 0,
OPT_UNLINK },
{ "use-compress-program", required_argument, 0,
OPT_USE_COMPRESS_PROGRAM },
{ "force-local", no_argument, 0,
OPT_FORCE_LOCAL },
{ "insecure", no_argument, 0,
OPT_INSECURE },
{ "exclude", required_argument, 0,
OPT_EXCLUDE },
{ "no-recursion", no_argument, 0,
OPT_NORECURSE },
#if !HAVE_NBTOOL_CONFIG_H
#ifdef HAVE_FCHROOT
{ "chroot", no_argument, 0,
OPT_CHROOT },
#endif /* HAVE_FCHROOT */
#endif
#if 0 /* Not implemented */
{ "catenate", no_argument, 0, 'A' }, /* F */
{ "concatenate", no_argument, 0, 'A' }, /* F */
{ "diff", no_argument, 0, 'd' }, /* F */
{ "compare", no_argument, 0, 'd' }, /* F */
{ "checkpoint", no_argument, 0,
OPT_CHECKPOINT },
{ "help", no_argument, 0,
OPT_HELP },
{ "info-script", required_argument, 0, 'F' },
{ "new-volume-script", required_argument, 0, 'F' },
{ "incremental", no_argument, 0, 'G' },
{ "listed-incremental", required_argument, 0, 'g' },
{ "ignore-zeros", no_argument, 0, 'i' },
{ "ignore-failed-read", no_argument, 0,
OPT_IGNORE_FAILED_READ },
{ "starting-file", no_argument, 0, 'K' },
{ "tape-length", required_argument, 0, 'L' },
{ "multi-volume", no_argument, 0, 'M' },
{ "after-date", required_argument, 0, 'N' },
{ "newer", required_argument, 0, 'N' },
{ "record-number", no_argument, 0, 'R' },
{ "remove-files", no_argument, 0,
OPT_REMOVE_FILES },
{ "same-order", no_argument, 0, 's' },
{ "preserve-order", no_argument, 0, 's' },
{ "null", no_argument, 0,
OPT_NULL },
{ "totals", no_argument, 0,
OPT_TOTALS },
{ "volume-name", required_argument, 0, 'V' },
{ "label", required_argument, 0, 'V' },
{ "version", no_argument, 0,
OPT_VERSION },
{ "verify", no_argument, 0, 'W' },
{ "block-compress", no_argument, 0,
OPT_BLOCK_COMPRESS },
#endif
{ 0, 0, 0, 0 },
};
static void
tar_options(int argc, char **argv)
{
int c;
int fstdin = 0;
int Oflag = 0;
int nincfiles = 0;
int incfiles_max = 0;
struct incfile {
char *file;
char *dir;
};
struct incfile *incfiles = NULL;
/*
* Set default values.
*/
rmleadslash = 1;
is_gnutar = 1;
/*
* process option flags
*/
while ((c = getoldopt(argc, argv,
"+b:cef:hjklmopqrs:tuvwxzBC:HI:OPST:X:Z014578",
tar_longopts, NULL))
!= -1) {
switch(c) {
case 'b':
/*
* specify blocksize in 512-byte blocks
*/
if ((wrblksz = (int)str_offt(optarg)) <= 0) {
tty_warn(1, "Invalid block size %s", optarg);
tar_usage();
}
wrblksz *= 512; /* XXX - check for int oflow */
break;
case 'c':
/*
* create an archive
*/
act = ARCHIVE;
break;
case 'e':
/*
* stop after first error
*/
maxflt = 0;
break;
case 'f':
/*
* filename where the archive is stored
*/
if ((optarg[0] == '-') && (optarg[1]== '\0')) {
/*
* treat a - as stdin
*/
fstdin = 1;
arcname = NULL;
break;
}
fstdin = 0;
arcname = optarg;
break;
case 'h':
/*
* follow symlinks
*/
Lflag = 1;
break;
case 'j':
/*
* pass through bzip2. not a standard option
*/
jflag = 1;
gzip_program = BZIP2_CMD;
break;
case 'k':
/*
* do not clobber files that exist
*/
kflag = 1;
break;
case 'l':
/*
* do not pass over mount points in the file system
*/
Xflag = 1;
break;
case 'm':
/*
* do not preserve modification time
*/
pmtime = 0;
break;
case 'o':
/*
* This option does several things based on whether
* this is a create or extract operation.
*/
if (act == ARCHIVE) {
/* GNU tar: write V7 format archives. */
Oflag = 1;
/* 4.2BSD: don't add directory entries. */
if (opt_add("write_opt=nodir") < 0)
tar_usage();
} else {
/* SUS: don't preserve owner/group. */
pids = 0;
nopids = 1;
}
break;
case 'O':
Oflag = 1;
break;
case 'p':
/*
* preserve user id, group id, file
* mode, access/modification times
*/
if (!nopids)
pids = 1;
pmode = 1;
patime = 1;
pmtime = 1;
break;
case 'q':
/*
* select first match for a pattern only
*/
nflag = 1;
break;
case 'r':
case 'u':
/*
* append to the archive
*/
act = APPND;
break;
case 's':
/*
* file name substitution name pattern
*/
if (rep_add(optarg) < 0) {
tar_usage();
break;
}
break;