English Language flag
// Log In
// CVSweb
Project: FreeWRT
// Summary // Activity // Search // Tracker // Lists // News // SCM // Wiki

SCM Repository

ViewVC logotype

Contents of /trunk/freewrt/tools/paxmirabilis/src/options.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 3816 - (show annotations) (download)
Wed Oct 29 17:58:40 2008 UTC (5 years, 3 months ago) by tg
File MIME type: text/plain
File size: 36833 byte(s)
FreeWRT trunk:

• merge new MirCPIO upstream, changes:
  – allow multiple -v options not only for tar but also for cpio, pax
  – add code to work around broken archives such as the CPIO archive inside
    Fedora Core 4 glibc-common-2.3.6-3.i386.rpm which carry the actual data
    of hardlinks not in the first but a later (here, the last) occurence of
    the file in question: iff hardlinking succeeds (no cross-device!), size
    of the linked files is 0, size of the archive member is greater than 0,
    we are extracting, but not to stdout, proceed writing out the data.
• add mircpio, mirpax, mirtar links in order to prevent interfering with
  native tools when both are in $PATH (this has worked since the last
  update, can be used now)

FreeWRT 1.0-stable:

• merge paxmirabilis complete from trunk

note: untested

1 /* $OpenBSD: options.c,v 1.67 2007/02/24 09:50:55 jmc Exp $ */
2 /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */
3
4 /*-
5 * Copyright (c) 2005, 2006, 2007 Thorsten Glaser <tg@66h.42h.de>
6 * Copyright (c) 1992 Keith Muller.
7 * Copyright (c) 1992, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * This code is derived from software contributed to Berkeley by
11 * Keith Muller of the University of California, San Diego.
12 *
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
15 * are met:
16 * 1. Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
18 * 2. Redistributions in binary form must reproduce the above copyright
19 * notice, this list of conditions and the following disclaimer in the
20 * documentation and/or other materials provided with the distribution.
21 * 3. Neither the name of the University nor the names of its contributors
22 * may be used to endorse or promote products derived from this software
23 * without specific prior written permission.
24 *
25 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * SUCH DAMAGE.
36 */
37
38 #include <sys/param.h>
39 #include <sys/time.h>
40 #include <sys/stat.h>
41 #ifndef __INTERIX
42 #include <sys/mtio.h>
43 #endif
44 #include <stdio.h>
45 #include <string.h>
46 #include <err.h>
47 #include <errno.h>
48 #include <unistd.h>
49 #include <stdlib.h>
50 #include <limits.h>
51 #include <paths.h>
52 #include "pax.h"
53 #include "options.h"
54 #include "cpio.h"
55 #include "tar.h"
56 #include "extern.h"
57
58 __SCCSID("@(#)options.c 8.2 (Berkeley) 4/18/94");
59 __RCSID("$MirOS: src/bin/pax/options.c,v 1.27 2008/10/29 17:00:07 tg Exp $");
60
61 #ifdef __GLIBC__
62 char *fgetln(FILE *, size_t *);
63 #endif
64
65 /*
66 * Routines which handle command line options
67 */
68
69 static char flgch[] = FLGCH; /* list of all possible flags */
70 static OPLIST *ophead = NULL; /* head for format specific options -x */
71 static OPLIST *optail = NULL; /* option tail */
72
73 static int no_op(void);
74 static void printflg(unsigned int);
75 static int c_frmt(const void *, const void *);
76 static off_t str_offt(char *);
77 static char *getline(FILE *fp);
78 static void pax_options(int, char **);
79 static void pax_usage(void) __attribute__((noreturn));
80 static void tar_set_action(int);
81 static void tar_options(int, char **);
82 static void tar_usage(void) __attribute__((noreturn));
83 static void cpio_set_action(int);
84 static void cpio_options(int, char **);
85 static void cpio_usage(void) __attribute__((noreturn));
86 int mkpath(char *);
87
88 static void process_M(const char *, void (*)(void));
89
90 /* errors from getline */
91 #define GETLINE_FILE_CORRUPT 1
92 #define GETLINE_OUT_OF_MEM 2
93 static int getline_error;
94
95
96 #define GZIP_CMD "gzip" /* command to run as gzip */
97 #define COMPRESS_CMD "compress" /* command to run as compress */
98
99 /*
100 * Format specific routine table - MUST BE IN SORTED ORDER BY NAME
101 * (see pax.h for description of each function)
102 *
103 * name, blksz, hdsz, udev, hlk, blkagn, inhead, id, st_read,
104 * read, end_read, st_write, write, end_write, trail,
105 * rd_data, wr_data, options
106 */
107
108 FSUB fsub[] = {
109 /* 0: OLD BINARY CPIO */
110 {"bcpio", 5120, sizeof(HD_BCPIO), 1, 0, 0, 1, bcpio_id, cpio_strd,
111 bcpio_rd, bcpio_endrd, cpio_stwr, bcpio_wr, cpio_endwr, cpio_trail,
112 rd_wrfile, wr_rdfile, bad_opt},
113
114 /* 1: OLD OCTAL CHARACTER CPIO */
115 {"cpio", 5120, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
116 cpio_rd, cpio_endrd, cpio_stwr, cpio_wr, cpio_endwr, cpio_trail,
117 rd_wrfile, wr_rdfile, bad_opt},
118
119 /* 2: OLD OCTAL CHARACTER CPIO, UID/GID CLEARED (ANONYMISED) */
120 {"dist", 512, sizeof(HD_CPIO), 1, 0, 0, 1, cpio_id, cpio_strd,
121 cpio_rd, cpio_endrd, dist_stwr, cpio_wr, cpio_endwr, cpio_trail,
122 rd_wrfile, wr_rdfile, bad_opt},
123
124 /* 3: SVR4 HEX CPIO */
125 {"sv4cpio", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, vcpio_id, cpio_strd,
126 vcpio_rd, vcpio_endrd, cpio_stwr, vcpio_wr, cpio_endwr, cpio_trail,
127 rd_wrfile, wr_rdfile, bad_opt},
128
129 /* 4: SVR4 HEX CPIO WITH CRC */
130 {"sv4crc", 5120, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
131 vcpio_rd, vcpio_endrd, crc_stwr, vcpio_wr, cpio_endwr, cpio_trail,
132 rd_wrfile, wr_rdfile, bad_opt},
133
134 /* 5: OLD TAR */
135 {"tar", 10240, BLKMULT, 0, 1, BLKMULT, 0, tar_id, no_op,
136 tar_rd, tar_endrd, no_op, tar_wr, tar_endwr, tar_trail,
137 rd_wrfile, wr_rdfile, tar_opt},
138
139 /* 6: POSIX USTAR */
140 {"ustar", 10240, BLKMULT, 0, 1, BLKMULT, 0, ustar_id, ustar_strd,
141 ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail,
142 rd_wrfile, wr_rdfile, bad_opt},
143
144 /* 7: SVR4 HEX CPIO WITH CRC, UID/GID/MTIME CLEARED (NORMALISED) */
145 {"v4norm", 512, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
146 vcpio_rd, vcpio_endrd, v4norm_stwr, vcpio_wr, cpio_endwr, cpio_trail,
147 rd_wrfile, wr_rdfile, bad_opt},
148
149 /* 8: SVR4 HEX CPIO WITH CRC, UID/GID CLEARED (ANONYMISED) */
150 {"v4root", 512, sizeof(HD_VCPIO), 1, 0, 0, 1, crc_id, crc_strd,
151 vcpio_rd, vcpio_endrd, v4root_stwr, vcpio_wr, cpio_endwr, cpio_trail,
152 rd_wrfile, wr_rdfile, bad_opt},
153 };
154 #define F_OCPIO 0 /* format when called as cpio -6 */
155 #define F_ACPIO 1 /* format when called as cpio -c */
156 #define F_NCPIO 3 /* format when called as tar -R */
157 #define F_CPIO 4 /* format when called as cpio or tar -S */
158 #define F_OTAR 5 /* format when called as tar -o */
159 #define F_TAR 6 /* format when called as tar */
160 #define DEFLT 6 /* default write format from list above */
161
162 /*
163 * ford is the archive search order used by get_arc() to determine what kind
164 * of archive we are dealing with. This helps to properly id archive formats
165 * some formats may be subsets of others....
166 */
167 int ford[] = {6, 5, 4, 3, 1, 0, -1 };
168
169 /* normalise archives */
170 int anonarch = 0;
171
172 /* extract to standard output */
173 int to_stdout = 0;
174
175 /*
176 * Do we have -C anywhere?
177 */
178 int havechd = 0;
179
180 /*
181 * options()
182 * figure out if we are pax, tar or cpio. Call the appropriate options
183 * parser
184 */
185
186 void
187 options(int argc, char **argv)
188 {
189 size_t n;
190
191 /*
192 * Are we acting like pax, tar or cpio (based on argv[0])
193 */
194 if ((n = strlen(argv[0])) >= 3 && !strcmp(argv[0] + n - 3, NM_TAR)) {
195 argv0 = NM_TAR;
196 tar_options(argc, argv);
197 } else if (n >= 4 && !strcmp(argv[0] + n - 4, NM_CPIO)) {
198 argv0 = NM_CPIO;
199 cpio_options(argc, argv);
200 } else {
201 argv0 = NM_PAX;
202 pax_options(argc, argv);
203 }
204 }
205
206 /*
207 * pax_options()
208 * look at the user specified flags. set globals as required and check if
209 * the user specified a legal set of flags. If not, complain and exit
210 */
211
212 static void
213 pax_options(int argc, char **argv)
214 {
215 int c;
216 size_t i;
217 unsigned int flg = 0;
218 unsigned int bflg = 0;
219 char *pt;
220 FSUB tmp;
221
222 /*
223 * process option flags
224 */
225 while ((c=getopt(argc,argv,"ab:cdf:iklno:p:rs:tuvwx:zB:DE:G:HLM:OPT:U:XYZ0"))
226 != -1) {
227 switch (c) {
228 case 'a':
229 /*
230 * append
231 */
232 flg |= AF;
233 break;
234 case 'b':
235 /*
236 * specify blocksize
237 */
238 flg |= BF;
239 if ((wrblksz = (int)str_offt(optarg)) <= 0) {
240 paxwarn(1, "Invalid block size %s", optarg);
241 pax_usage();
242 }
243 break;
244 case 'c':
245 /*
246 * inverse match on patterns
247 */
248 cflag = 1;
249 flg |= CF;
250 break;
251 case 'd':
252 /*
253 * match only dir on extract, not the subtree at dir
254 */
255 dflag = 1;
256 flg |= DF;
257 break;
258 case 'f':
259 /*
260 * filename where the archive is stored
261 */
262 arcname = optarg;
263 flg |= FF;
264 break;
265 case 'i':
266 /*
267 * interactive file rename
268 */
269 iflag = 1;
270 flg |= IF;
271 break;
272 case 'k':
273 /*
274 * do not clobber files that exist
275 */
276 kflag = 1;
277 flg |= KF;
278 break;
279 case 'l':
280 /*
281 * try to link src to dest with copy (-rw)
282 */
283 lflag = 1;
284 flg |= LF;
285 break;
286 case 'n':
287 /*
288 * select first match for a pattern only
289 */
290 nflag = 1;
291 flg |= NF;
292 break;
293 case 'o':
294 /*
295 * pass format specific options
296 */
297 flg |= OF;
298 if (opt_add(optarg) < 0)
299 pax_usage();
300 break;
301 case 'p':
302 /*
303 * specify file characteristic options
304 */
305 for (pt = optarg; *pt != '\0'; ++pt) {
306 switch (*pt) {
307 case 'a':
308 /*
309 * do not preserve access time
310 */
311 patime = 0;
312 break;
313 case 'e':
314 /*
315 * preserve user id, group id, file
316 * mode, access/modification times
317 */
318 pids = 1;
319 pmode = 1;
320 patime = 1;
321 pmtime = 1;
322 break;
323 case 'm':
324 /*
325 * do not preserve modification time
326 */
327 pmtime = 0;
328 break;
329 case 'o':
330 /*
331 * preserve uid/gid
332 */
333 pids = 1;
334 break;
335 case 'p':
336 /*
337 * preserve file mode bits
338 */
339 pmode = 1;
340 break;
341 default:
342 paxwarn(1, "Invalid -p string: %c", *pt);
343 pax_usage();
344 break;
345 }
346 }
347 flg |= PF;
348 break;
349 case 'r':
350 /*
351 * read the archive
352 */
353 flg |= RF;
354 break;
355 case 's':
356 /*
357 * file name substitution name pattern
358 */
359 if (rep_add(optarg) < 0) {
360 pax_usage();
361 break;
362 }
363 flg |= SF;
364 break;
365 case 't':
366 /*
367 * preserve access time on filesystem nodes we read
368 */
369 tflag = 1;
370 flg |= TF;
371 break;
372 case 'u':
373 /*
374 * ignore those older files
375 */
376 uflag = 1;
377 flg |= UF;
378 break;
379 case 'v':
380 /*
381 * verbose operation mode
382 */
383 vflag++;
384 flg |= VF;
385 break;
386 case 'w':
387 /*
388 * write an archive
389 */
390 flg |= WF;
391 break;
392 case 'x':
393 /*
394 * specify an archive format on write
395 */
396 tmp.name = optarg;
397 if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
398 sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) {
399 flg |= XF;
400 break;
401 }
402 paxwarn(1, "Unknown -x format: %s", optarg);
403 (void)fputs("pax: Known -x formats are:", stderr);
404 for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
405 (void)fprintf(stderr, " %s", fsub[i].name);
406 (void)fputs("\n\n", stderr);
407 pax_usage();
408 break;
409 case 'z':
410 /*
411 * use gzip. Non standard option.
412 */
413 gzip_program = GZIP_CMD;
414 break;
415 case 'B':
416 /*
417 * non-standard option on number of bytes written on a
418 * single archive volume.
419 */
420 if ((wrlimit = str_offt(optarg)) <= 0) {
421 paxwarn(1, "Invalid write limit %s", optarg);
422 pax_usage();
423 }
424 if (wrlimit % BLKMULT) {
425 paxwarn(1, "Write limit is not a %d byte multiple",
426 BLKMULT);
427 pax_usage();
428 }
429 flg |= CBF;
430 break;
431 case 'D':
432 /*
433 * On extraction check file inode change time before the
434 * modification of the file name. Non standard option.
435 */
436 Dflag = 1;
437 flg |= CDF;
438 break;
439 case 'E':
440 /*
441 * non-standard limit on read faults
442 * 0 indicates stop after first error, values
443 * indicate a limit, "NONE" try forever
444 */
445 flg |= CEF;
446 if (strcmp(NONE, optarg) == 0)
447 maxflt = -1;
448 else if ((maxflt = atoi(optarg)) < 0) {
449 paxwarn(1, "Error count value must be positive");
450 pax_usage();
451 }
452 break;
453 case 'G':
454 /*
455 * non-standard option for selecting files within an
456 * archive by group (gid or name)
457 */
458 if (grp_add(optarg) < 0) {
459 pax_usage();
460 break;
461 }
462 flg |= CGF;
463 break;
464 case 'H':
465 /*
466 * follow command line symlinks only
467 */
468 Hflag = 1;
469 flg |= CHF;
470 break;
471 case 'L':
472 /*
473 * follow symlinks
474 */
475 Lflag = 1;
476 flg |= CLF;
477 break;
478 case 'M':
479 /*
480 * MirOS extension: archive normaliser
481 */
482 process_M(optarg, pax_usage);
483 break;
484 case 'O':
485 /*
486 * Force one volume. Non standard option.
487 */
488 force_one_volume = 1;
489 break;
490 case 'P':
491 /*
492 * do NOT follow symlinks (default)
493 */
494 Lflag = 0;
495 flg |= CPF;
496 break;
497 case 'T':
498 /*
499 * non-standard option for selecting files within an
500 * archive by modification time range (lower,upper)
501 */
502 if (trng_add(optarg) < 0) {
503 pax_usage();
504 break;
505 }
506 flg |= CTF;
507 break;
508 case 'U':
509 /*
510 * non-standard option for selecting files within an
511 * archive by user (uid or name)
512 */
513 if (usr_add(optarg) < 0) {
514 pax_usage();
515 break;
516 }
517 flg |= CUF;
518 break;
519 case 'X':
520 /*
521 * do not pass over mount points in the file system
522 */
523 Xflag = 1;
524 flg |= CXF;
525 break;
526 case 'Y':
527 /*
528 * On extraction check file inode change time after the
529 * modification of the file name. Non standard option.
530 */
531 Yflag = 1;
532 flg |= CYF;
533 break;
534 case 'Z':
535 /*
536 * On extraction check modification time after the
537 * modification of the file name. Non standard option.
538 */
539 Zflag = 1;
540 flg |= CZF;
541 break;
542 case '0':
543 /*
544 * Use \0 as pathname terminator.
545 * (For use with the -print0 option of find(1).)
546 */
547 zeroflag = 1;
548 flg |= C0F;
549 break;
550 default:
551 pax_usage();
552 break;
553 }
554 }
555
556 /*
557 * figure out the operation mode of pax read,write,extract,copy,append
558 * or list. check that we have not been given a bogus set of flags
559 * for the operation mode.
560 */
561 if (ISLIST(flg)) {
562 act = LIST;
563 listf = stdout;
564 bflg = flg & BDLIST;
565 } else if (ISEXTRACT(flg)) {
566 act = EXTRACT;
567 bflg = flg & BDEXTR;
568 } else if (ISARCHIVE(flg)) {
569 act = ARCHIVE;
570 bflg = flg & BDARCH;
571 } else if (ISAPPND(flg)) {
572 act = APPND;
573 bflg = flg & BDARCH;
574 } else if (ISCOPY(flg)) {
575 act = COPY;
576 bflg = flg & BDCOPY;
577 } else
578 pax_usage();
579 if (bflg) {
580 printflg(flg);
581 pax_usage();
582 }
583
584 /*
585 * if we are writing (ARCHIVE) we use the default format if the user
586 * did not specify a format. when we write during an APPEND, we will
587 * adopt the format of the existing archive if none was supplied.
588 */
589 if (!(flg & XF) && (act == ARCHIVE))
590 frmt = &(fsub[DEFLT]);
591
592 /*
593 * process the args as they are interpreted by the operation mode
594 */
595 switch (act) {
596 case LIST:
597 case EXTRACT:
598 for (; optind < argc; optind++)
599 if (pat_add(argv[optind], NULL) < 0)
600 pax_usage();
601 break;
602 case COPY:
603 if (optind >= argc) {
604 paxwarn(0, "Destination directory was not supplied");
605 pax_usage();
606 }
607 --argc;
608 dirptr = argv[argc];
609 /* FALL THROUGH */
610 case ARCHIVE:
611 case APPND:
612 for (; optind < argc; optind++)
613 if (ftree_add(argv[optind], 0) < 0)
614 pax_usage();
615 /*
616 * no read errors allowed on updates/append operation!
617 */
618 maxflt = 0;
619 break;
620 }
621 }
622
623
624 /*
625 * tar_options()
626 * look at the user specified flags. set globals as required and check if
627 * the user specified a legal set of flags. If not, complain and exit
628 */
629
630 static void
631 tar_set_action(int op)
632 {
633 if (act != ERROR && act != op)
634 tar_usage();
635 act = op;
636 }
637
638 static void
639 tar_options(int argc, char **argv)
640 {
641 int c;
642 int fstdin = 0;
643 int Oflag = 0;
644 int nincfiles = 0;
645 int incfiles_max = 0;
646 struct incfile {
647 char *file;
648 char *dir;
649 };
650 struct incfile *incfiles = NULL;
651
652 /*
653 * Set default values.
654 */
655 rmleadslash = 1;
656
657 /*
658 * process option flags
659 */
660 while ((c = getoldopt(argc, argv,
661 "b:cef:hmopqruts:vwxzBC:HI:LM:OPRSXZ014578")) != -1) {
662 switch (c) {
663 case 'b':
664 /*
665 * specify blocksize in 512-byte blocks
666 */
667 if ((wrblksz = (int)str_offt(optarg)) <= 0) {
668 paxwarn(1, "Invalid block size %s", optarg);
669 tar_usage();
670 }
671 wrblksz *= 512; /* XXX - check for int oflow */
672 break;
673 case 'c':
674 /*
675 * create an archive
676 */
677 tar_set_action(ARCHIVE);
678 break;
679 case 'e':
680 /*
681 * stop after first error
682 */
683 maxflt = 0;
684 break;
685 case 'f':
686 /*
687 * filename where the archive is stored
688 */
689 if ((optarg[0] == '-') && (optarg[1]== '\0')) {
690 /*
691 * treat a - as stdin
692 */
693 fstdin = 1;
694 arcname = NULL;
695 break;
696 }
697 fstdin = 0;
698 arcname = optarg;
699 break;
700 case 'h':
701 /*
702 * follow symlinks
703 */
704 Lflag = 1;
705 break;
706 case 'm':
707 /*
708 * do not preserve modification time
709 */
710 pmtime = 0;
711 break;
712 case 'O':
713 Oflag = 1;
714 to_stdout = 2;
715 break;
716 case 'o':
717 Oflag = 2;
718 break;
719 case 'p':
720 /*
721 * preserve uid/gid and file mode, regardless of umask
722 */
723 pmode = 1;
724 pids = 1;
725 break;
726 case 'q':
727 /*
728 * select first match for a pattern only
729 */
730 nflag = 1;
731 break;
732 case 'r':
733 case 'u':
734 /*
735 * append to the archive
736 */
737 tar_set_action(APPND);
738 break;
739 case 'R':
740 Oflag = 3;
741 anonarch = ANON_INODES | ANON_HARDLINKS;
742 break;
743 case 'S':
744 Oflag = 4;
745 anonarch = ANON_INODES | ANON_HARDLINKS;
746 break;
747 case 's':
748 /*
749 * file name substitution name pattern
750 */
751 if (rep_add(optarg) < 0) {
752 tar_usage();
753 break;
754 }
755 break;
756 case 't':
757 /*
758 * list contents of the tape
759 */
760 tar_set_action(LIST);
761 break;
762 case 'v':
763 /*
764 * verbose operation mode
765 */
766 vflag++;
767 break;
768 case 'w':
769 /*
770 * interactive file rename
771 */
772 iflag = 1;
773 break;
774 case 'x':
775 /*
776 * extract an archive, preserving mode,
777 * and mtime if possible.
778 */
779 tar_set_action(EXTRACT);
780 pmtime = 1;
781 break;
782 case 'z':
783 /*
784 * use gzip. Non standard option.
785 */
786 gzip_program = GZIP_CMD;
787 break;
788 case 'B':
789 /*
790 * Nothing to do here, this is pax default
791 */
792 break;
793 case 'C':
794 havechd++;
795 chdname = optarg;
796 break;
797 case 'H':
798 /*
799 * follow command line symlinks only
800 */
801 Hflag = 1;
802 break;
803 case 'I':
804 if (++nincfiles > incfiles_max) {
805 incfiles_max = nincfiles + 3;
806 incfiles = realloc(incfiles,
807 sizeof(*incfiles) * incfiles_max);
808 if (incfiles == NULL) {
809 paxwarn(0, "Unable to allocate space "
810 "for option list");
811 exit(1);
812 }
813 }
814 incfiles[nincfiles - 1].file = optarg;
815 incfiles[nincfiles - 1].dir = chdname;
816 break;
817 case 'L':
818 /*
819 * follow symlinks
820 */
821 Lflag = 1;
822 break;
823 case 'M':
824 process_M(optarg, tar_usage);
825 break;
826 case 'P':
827 /*
828 * do not remove leading '/' from pathnames
829 */
830 rmleadslash = 0;
831 break;
832 case 'X':
833 /*
834 * do not pass over mount points in the file system
835 */
836 Xflag = 1;
837 break;
838 case 'Z':
839 /*
840 * use compress.
841 */
842 gzip_program = COMPRESS_CMD;
843 break;
844 case '0':
845 arcname = DEV_0;
846 break;
847 case '1':
848 arcname = DEV_1;
849 break;
850 case '4':
851 arcname = DEV_4;
852 break;
853 case '5':
854 arcname = DEV_5;
855 break;
856 case '7':
857 arcname = DEV_7;
858 break;
859 case '8':
860 arcname = DEV_8;
861 break;
862 default:
863 tar_usage();
864 break;
865 }
866 }
867 argc -= optind;
868 argv += optind;
869
870 /* Tar requires an action. */
871 if (act == ERROR)
872 tar_usage();
873
874 /* Traditional tar behaviour (pax uses stderr unless in list mode) */
875 if (fstdin == 1 && act == ARCHIVE)
876 listf = stderr;
877 else
878 listf = stdout;
879
880 /* Traditional tar behaviour (pax wants to read file list from stdin) */
881 if ((act == ARCHIVE || act == APPND) && argc == 0 && nincfiles == 0)
882 exit(0);
883
884 /*
885 * process the args as they are interpreted by the operation mode
886 */
887 switch (act) {
888 case EXTRACT:
889 if (to_stdout == 2)
890 to_stdout = 1;
891 case LIST:
892 default:
893 {
894 int sawpat = 0;
895 char *file, *dir = NULL;
896
897 while (nincfiles || *argv != NULL) {
898 /*
899 * If we queued up any include files,
900 * pull them in now. Otherwise, check
901 * for -I and -C positional flags.
902 * Anything else must be a file to
903 * extract.
904 */
905 if (nincfiles) {
906 file = incfiles->file;
907 dir = incfiles->dir;
908 incfiles++;
909 nincfiles--;
910 } else if (strcmp(*argv, "-I") == 0) {
911 if (*++argv == NULL)
912 break;
913 file = *argv++;
914 dir = chdname;
915 } else
916 file = NULL;
917 if (file != NULL) {
918 FILE *fp;
919 char *str;
920
921 if (strcmp(file, "-") == 0)
922 fp = stdin;
923 else if ((fp = fopen(file, "r")) == NULL) {
924 paxwarn(1, "Unable to open file '%s' for read", file);
925 tar_usage();
926 }
927 while ((str = getline(fp)) != NULL) {
928 if (pat_add(str, dir) < 0)
929 tar_usage();
930 sawpat = 1;
931 }
932 if (strcmp(file, "-") != 0)
933 fclose(fp);
934 if (getline_error) {
935 paxwarn(1, "Problem with file '%s'", file);
936 tar_usage();
937 }
938 } else if (strcmp(*argv, "-C") == 0) {
939 if (*++argv == NULL)
940 break;
941 chdname = *argv++;
942 havechd++;
943 } else if (pat_add(*argv++, chdname) < 0)
944 tar_usage();
945 else
946 sawpat = 1;
947 }
948 /*
949 * if patterns were added, we are doing chdir()
950 * on a file-by-file basis, else, just one
951 * global chdir (if any) after opening input.
952 */
953 if (sawpat > 0)
954 chdname = NULL;
955 }
956 break;
957 case ARCHIVE:
958 case APPND:
959 switch(Oflag) {
960 case 0:
961 frmt = &(fsub[F_TAR]);
962 break;
963 case 1:
964 frmt = &(fsub[F_OTAR]);
965 break;
966 case 2:
967 frmt = &(fsub[F_OTAR]);
968 if (opt_add("write_opt=nodir") < 0)
969 tar_usage();
970 break;
971 case 3:
972 frmt = &(fsub[F_NCPIO]);
973 break;
974 case 4:
975 frmt = &(fsub[F_CPIO]);
976 break;
977 default:
978 tar_usage();
979 break;
980 }
981
982 if (chdname != NULL) { /* initial chdir() */
983 if (ftree_add(chdname, 1) < 0)
984 tar_usage();
985 }
986
987 while (nincfiles || *argv != NULL) {
988 char *file, *dir = NULL;
989
990 /*
991 * If we queued up any include files, pull them in
992 * now. Otherwise, check for -I and -C positional
993 * flags. Anything else must be a file to include
994 * in the archive.
995 */
996 if (nincfiles) {
997 file = incfiles->file;
998 dir = incfiles->dir;
999 incfiles++;
1000 nincfiles--;
1001 } else if (strcmp(*argv, "-I") == 0) {
1002 if (*++argv == NULL)
1003 break;
1004 file = *argv++;
1005 dir = NULL;
1006 } else
1007 file = NULL;
1008 if (file != NULL) {
1009 FILE *fp;
1010 char *str;
1011
1012 /* Set directory if needed */
1013 if (dir) {
1014 if (ftree_add(dir, 1) < 0)
1015 tar_usage();
1016 }
1017
1018 if (strcmp(file, "-") == 0)
1019 fp = stdin;
1020 else if ((fp = fopen(file, "r")) == NULL) {
1021 paxwarn(1, "Unable to open file '%s' for read", file);
1022 tar_usage();
1023 }
1024 while ((str = getline(fp)) != NULL) {
1025 if (ftree_add(str, 0) < 0)
1026 tar_usage();
1027 }
1028 if (strcmp(file, "-") != 0)
1029 fclose(fp);
1030 if (getline_error) {
1031 paxwarn(1, "Problem with file '%s'",
1032 file);
1033 tar_usage();
1034 }
1035 } else if (strcmp(*argv, "-C") == 0) {
1036 if (*++argv == NULL)
1037 break;
1038 if (ftree_add(*argv++, 1) < 0)
1039 tar_usage();
1040 havechd++;
1041 } else if (ftree_add(*argv++, 0) < 0)
1042 tar_usage();
1043 }
1044 /*
1045 * no read errors allowed on updates/append operation!
1046 */
1047 maxflt = 0;
1048 break;
1049 }
1050 if (to_stdout != 1)
1051 to_stdout = 0;
1052 if (!fstdin && ((arcname == NULL) || (*arcname == '\0'))) {
1053 arcname = getenv("TAPE");
1054 #ifdef _PATH_DEFTAPE
1055 if ((arcname == NULL) || (*arcname == '\0'))
1056 arcname = _PATH_DEFTAPE;
1057 #endif
1058 }
1059 }
1060
1061 int
1062 mkpath(char *path)
1063 {
1064 struct stat sb;
1065 char *slash;
1066 int done = 0;
1067
1068 slash = path;
1069
1070 while (!done) {
1071 slash += strspn(slash, "/");
1072 slash += strcspn(slash, "/");
1073
1074 done = (*slash == '\0');
1075 *slash = '\0';
1076
1077 if (stat(path, &sb)) {
1078 if (errno != ENOENT || mkdir(path, 0777)) {
1079 paxwarn(1, "%s", path);
1080 return (-1);
1081 }
1082 } else if (!S_ISDIR(sb.st_mode)) {
1083 syswarn(1, ENOTDIR, "%s", path);
1084 return (-1);
1085 }
1086
1087 if (!done)
1088 *slash = '/';
1089 }
1090
1091 return (0);
1092 }
1093
1094 static void
1095 cpio_set_action(int op)
1096 {
1097 if ((act == APPND && op == ARCHIVE) || (act == ARCHIVE && op == APPND))
1098 act = APPND;
1099 else if ((act == LIST && op == EXTRACT) || (act == EXTRACT && op == LIST))
1100 act = LIST;
1101 else if (act != ERROR && act != op)
1102 cpio_usage();
1103 else
1104 act = op;
1105 }
1106
1107 /*
1108 * cpio_options()
1109 * look at the user specified flags. set globals as required and check if
1110 * the user specified a legal set of flags. If not, complain and exit
1111 */
1112
1113 static void
1114 cpio_options(int argc, char **argv)
1115 {
1116 int c;
1117 size_t i;
1118 char *str;
1119 FSUB tmp;
1120 FILE *fp;
1121
1122 kflag = 1;
1123 pids = 1;
1124 pmode = 1;
1125 pmtime = 0;
1126 arcname = NULL;
1127 dflag = 1;
1128 nodirs = 1;
1129 while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LM:O:SZ6")) != -1)
1130 switch (c) {
1131 case 'a':
1132 /*
1133 * preserve access time on files read
1134 */
1135 tflag = 1;
1136 break;
1137 case 'b':
1138 /*
1139 * swap bytes and half-words when reading data
1140 */
1141 break;
1142 case 'c':
1143 /*
1144 * ASCII cpio header
1145 */
1146 frmt = &(fsub[F_ACPIO]);
1147 break;
1148 case 'd':
1149 /*
1150 * create directories as needed
1151 */
1152 nodirs = 0;
1153 break;
1154 case 'f':
1155 /*
1156 * invert meaning of pattern list
1157 */
1158 cflag = 1;
1159 break;
1160 case 'i':
1161 /*
1162 * restore an archive
1163 */
1164 cpio_set_action(EXTRACT);
1165 break;
1166 case 'k':
1167 break;
1168 case 'l':
1169 /*
1170 * use links instead of copies when possible
1171 */
1172 lflag = 1;
1173 break;
1174 case 'm':
1175 /*
1176 * preserve modification time
1177 */
1178 pmtime = 1;
1179 break;
1180 case 'o':
1181 /*
1182 * create an archive
1183 */
1184 cpio_set_action(ARCHIVE);
1185 frmt = &(fsub[F_CPIO]);
1186 break;
1187 case 'p':
1188 /*
1189 * copy-pass mode
1190 */
1191 cpio_set_action(COPY);
1192 break;
1193 case 'r':
1194 /*
1195 * interactively rename files
1196 */
1197 iflag = 1;
1198 break;
1199 case 's':
1200 /*
1201 * swap bytes after reading data
1202 */
1203 break;
1204 case 't':
1205 /*
1206 * list contents of archive
1207 */
1208 cpio_set_action(LIST);
1209 listf = stdout;
1210 break;
1211 case 'u':
1212 /*
1213 * replace newer files
1214 */
1215 kflag = 0;
1216 break;
1217 case 'v':
1218 /*
1219 * verbose operation mode
1220 */
1221 vflag++;
1222 break;
1223 case 'z':
1224 /*
1225 * use gzip. Non standard option.
1226 */
1227 gzip_program = GZIP_CMD;
1228 break;
1229 case 'A':
1230 /*
1231 * append mode
1232 */
1233 cpio_set_action(APPND);
1234 break;
1235 case 'B':
1236 /*
1237 * Use 5120 byte block size
1238 */
1239 wrblksz = 5120;
1240 break;
1241 case 'C':
1242 /*
1243 * set block size in bytes
1244 */
1245 wrblksz = atoi(optarg);
1246 break;
1247 case 'E':
1248 /*
1249 * file with patterns to extract or list
1250 */
1251 if ((fp = fopen(optarg, "r")) == NULL) {
1252 paxwarn(1, "Unable to open file '%s' for read", optarg);
1253 cpio_usage();
1254 }
1255 while ((str = getline(fp)) != NULL) {
1256 pat_add(str, NULL);
1257 }
1258 fclose(fp);
1259 if (getline_error) {
1260 paxwarn(1, "Problem with file '%s'", optarg);
1261 cpio_usage();
1262 }
1263 break;
1264 case 'F':
1265 case 'I':
1266 case 'O':
1267 /*
1268 * filename where the archive is stored
1269 */
1270 if ((optarg[0] == '-') && (optarg[1]== '\0')) {
1271 /*
1272 * treat a - as stdin
1273 */
1274 arcname = NULL;
1275 break;
1276 }
1277 arcname = optarg;
1278 break;
1279 case 'H':
1280 /*
1281 * specify an archive format on write
1282 */
1283 if (!strcmp(optarg, "bin")) {
1284 tmp.name = "bcpio";
1285 } else if (!strcmp(optarg, "crc")) {
1286 tmp.name = "sv4crc";
1287 } else if (!strcmp(optarg, "newc")) {
1288 tmp.name = "sv4cpio";
1289 } else if (!strcmp(optarg, "odc")) {
1290 tmp.name = "cpio";
1291 } else {
1292 tmp.name = optarg;
1293 }
1294 if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub,
1295 sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL)
1296 break;
1297 paxwarn(1, "Unknown -H format: %s", optarg);
1298 (void)fputs("cpio: Known -H formats are:", stderr);
1299 for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i)
1300 (void)fprintf(stderr, " %s", fsub[i].name);
1301 (void)fputs("\n\n", stderr);
1302 cpio_usage();
1303 break;
1304 case 'L':
1305 /*
1306 * follow symbolic links
1307 */
1308 Lflag = 1;
1309 break;
1310 case 'M':
1311 process_M(optarg, cpio_usage);
1312 break;
1313 case 'S':
1314 /*
1315 * swap halfwords after reading data
1316 */
1317 break;
1318 case 'Z':
1319 /*
1320 * use compress. Non standard option.
1321 */
1322 gzip_program = COMPRESS_CMD;
1323 break;
1324 case '6':
1325 /*
1326 * process Version 6 cpio format
1327 */
1328 frmt = &(fsub[F_OCPIO]);
1329 break;
1330 case '?':
1331 default:
1332 cpio_usage();
1333 break;
1334 }
1335 argc -= optind;
1336 argv += optind;
1337
1338 /*
1339 * process the args as they are interpreted by the operation mode
1340 */
1341 switch (act) {
1342 case LIST:
1343 case EXTRACT:
1344 while (*argv != NULL)
1345 if (pat_add(*argv++, NULL) < 0)
1346 cpio_usage();
1347 break;
1348 case COPY:
1349 if (*argv == NULL) {
1350 paxwarn(0, "Destination directory was not supplied");
1351 cpio_usage();
1352 }
1353 dirptr = *argv;
1354 if (mkpath(dirptr) < 0)
1355 cpio_usage();
1356 --argc;
1357 ++argv;
1358 /* FALL THROUGH */
1359 case ARCHIVE:
1360 case APPND:
1361 if (*argv != NULL)
1362 cpio_usage();
1363 /*
1364 * no read errors allowed on updates/append operation!
1365 */
1366 maxflt = 0;
1367 while ((str = getline(stdin)) != NULL) {
1368 ftree_add(str, 0);
1369 }
1370 if (getline_error) {
1371 paxwarn(1, "Problem while reading stdin");
1372 cpio_usage();
1373 }
1374 break;
1375 default:
1376 cpio_usage();
1377 break;
1378 }
1379 }
1380
1381 /*
1382 * printflg()
1383 * print out those invalid flag sets found to the user
1384 */
1385
1386 static void
1387 printflg(unsigned int flg)
1388 {
1389 int nxt;
1390 int pos = 0;
1391
1392 (void)fprintf(stderr,"%s: Invalid combination of options:", argv0);
1393 while ((nxt = ffs(flg)) != 0) {
1394 flg = flg >> nxt;
1395 pos += nxt;
1396 (void)fprintf(stderr, " -%c", flgch[pos-1]);
1397 }
1398 (void)putc('\n', stderr);
1399 }
1400
1401 /*
1402 * c_frmt()
1403 * comparison routine used by bsearch to find the format specified
1404 * by the user
1405 */
1406
1407 static int
1408 c_frmt(const void *a, const void *b)
1409 {
1410 return(strcmp(((const FSUB *)a)->name, ((const FSUB *)b)->name));
1411 }
1412
1413 /*
1414 * opt_next()
1415 * called by format specific options routines to get each format specific
1416 * flag and value specified with -o
1417 * Return:
1418 * pointer to next OPLIST entry or NULL (end of list).
1419 */
1420
1421 OPLIST *
1422 opt_next(void)
1423 {
1424 OPLIST *opt;
1425
1426 if ((opt = ophead) != NULL)
1427 ophead = ophead->fow;
1428 return(opt);
1429 }
1430
1431 /*
1432 * bad_opt()
1433 * generic routine used to complain about a format specific options
1434 * when the format does not support options.
1435 */
1436
1437 int
1438 bad_opt(void)
1439 {
1440 OPLIST *opt;
1441
1442 if (ophead == NULL)
1443 return(0);
1444 /*
1445 * print all we were given
1446 */
1447 paxwarn(1,"These format options are not supported");
1448 while ((opt = opt_next()) != NULL)
1449 (void)fprintf(stderr, "\t%s = %s\n", opt->name, opt->value);
1450 pax_usage();
1451 return(0);
1452 }
1453
1454 /*
1455 * opt_add()
1456 * breaks the value supplied to -o into a option name and value. options
1457 * are given to -o in the form -o name-value,name=value
1458 * multiple -o may be specified.
1459 * Return:
1460 * 0 if format in name=value format, -1 if -o is passed junk
1461 */
1462
1463 int
1464 opt_add(const char *str)
1465 {
1466 OPLIST *opt;
1467 char *frpt;
1468 char *pt;
1469 char *endpt;
1470 char *dstr;
1471
1472 if ((str == NULL) || (*str == '\0')) {
1473 paxwarn(0, "Invalid option name");
1474 return(-1);
1475 }
1476 if ((dstr = strdup(str)) == NULL) {
1477 paxwarn(0, "Unable to allocate space for option list");
1478 return(-1);
1479 }
1480 frpt = endpt = dstr;
1481
1482 /*
1483 * break into name and values pieces and stuff each one into a
1484 * OPLIST structure. When we know the format, the format specific
1485 * option function will go through this list
1486 */
1487 while ((frpt != NULL) && (*frpt != '\0')) {
1488 if ((endpt = strchr(frpt, ',')) != NULL)
1489 *endpt = '\0';
1490 if ((pt = strchr(frpt, '=')) == NULL) {
1491 paxwarn(0, "Invalid options format");
1492 free(dstr);
1493 return(-1);
1494 }
1495 if ((opt = (OPLIST *)malloc(sizeof(OPLIST))) == NULL) {
1496 paxwarn(0, "Unable to allocate space for option list");
1497 free(dstr);
1498 return(-1);
1499 }
1500 *pt++ = '\0';
1501 opt->name = frpt;
1502 opt->value = pt;
1503 opt->fow = NULL;
1504 if (endpt != NULL)
1505 frpt = endpt + 1;
1506 else
1507 frpt = NULL;
1508 if (ophead == NULL) {
1509 optail = ophead = opt;
1510 continue;
1511 }
1512 optail->fow = opt;
1513 optail = opt;
1514 }
1515 return(0);
1516 }
1517
1518 /*
1519 * str_offt()
1520 * Convert an expression of the following forms to an off_t > 0.
1521 * 1) A positive decimal number.
1522 * 2) A positive decimal number followed by a b (mult by 512).
1523 * 3) A positive decimal number followed by a k (mult by 1024).
1524 * 4) A positive decimal number followed by a m (mult by 512).
1525 * 5) A positive decimal number followed by a w (mult by sizeof int)
1526 * 6) Two or more positive decimal numbers (with/without k,b or w).
1527 * separated by x (also * for backwards compatibility), specifying
1528 * the product of the indicated values.
1529 * Return:
1530 * 0 for an error, a positive value o.w.
1531 */
1532
1533 static off_t
1534 str_offt(char *val)
1535 {
1536 char *expr;
1537 off_t num, t;
1538
1539 # ifdef LONG_OFF_T
1540 num = strtol(val, &expr, 0);
1541 if ((num == LONG_MAX) || (num <= 0) || (expr == val))
1542 # else
1543 num = strtoq(val, &expr, 0);
1544 if ((num == QUAD_MAX) || (num <= 0) || (expr == val))
1545 # endif
1546 return(0);
1547
1548 switch (*expr) {
1549 case 'b':
1550 t = num;
1551 num *= 512;
1552 if (t > num)
1553 return(0);
1554 ++expr;
1555 break;
1556 case 'k':
1557 t = num;
1558 num *= 1024;
1559 if (t > num)
1560 return(0);
1561 ++expr;
1562 break;
1563 case 'm':
1564 t = num;
1565 num *= 1048576;
1566 if (t > num)
1567 return(0);
1568 ++expr;
1569 break;
1570 case 'w':
1571 t = num;
1572 num *= sizeof(int);
1573 if (t > num)
1574 return(0);
1575 ++expr;
1576 break;
1577 }
1578
1579 switch (*expr) {
1580 case '\0':
1581 break;
1582 case '*':
1583 case 'x':
1584 t = num;
1585 num *= str_offt(expr + 1);
1586 if (t > num)
1587 return(0);
1588 break;
1589 default:
1590 return(0);
1591 }
1592 return(num);
1593 }
1594
1595 char *
1596 getline(FILE *f)
1597 {
1598 char *name, *temp;
1599 size_t len;
1600
1601 name = fgetln(f, &len);
1602 if (!name) {
1603 getline_error = ferror(f) ? GETLINE_FILE_CORRUPT : 0;
1604 return(0);
1605 }
1606 if (name[len-1] != '\n')
1607 len++;
1608 temp = malloc(len);
1609 if (!temp) {
1610 getline_error = GETLINE_OUT_OF_MEM;
1611 return(0);
1612 }
1613 memcpy(temp, name, len-1);
1614 temp[len-1] = 0;
1615 return(temp);
1616 }
1617
1618 /*
1619 * no_op()
1620 * for those option functions where the archive format has nothing to do.
1621 * Return:
1622 * 0
1623 */
1624
1625 static int
1626 no_op(void)
1627 {
1628 return(0);
1629 }
1630
1631 /*
1632 * pax_usage()
1633 * print the usage summary to the user
1634 */
1635
1636 void
1637 pax_usage(void)
1638 {
1639 (void)fputs(
1640 "usage: pax [-0cdnOvz] [-E limit] [-f archive] [-G group] [-s replstr]\n"
1641 "\t [-T range] [-U user] [pattern ...]\n"
1642 " pax -r [-0cDdiknOuvYZz] [-E limit] [-f archive] [-G group]\n"
1643 "\t [-o options] [-p string] [-s replstr] [-T range]\n"
1644 "\t [-U user] [pattern ...]\n"
1645 " pax -w [-0adHiLOPtuvXz] [-B bytes] [-b blocksize] [-f archive]\n"
1646 "\t [-G group] [-M flag] [-o options] [-s replstr]\n"
1647 "\t [-T range] [-U user] [-x format] [file ...]\n"
1648 " pax -rw [-0DdHikLlnOPtuvXYZ] [-G group] [-p string] [-s replstr]\n"
1649 "\t [-T range] [-U user] [file ...] directory\n",
1650 stderr);
1651 exit(1);
1652 }
1653
1654 /*
1655 * tar_usage()
1656 * print the usage summary to the user
1657 */
1658
1659 void
1660 tar_usage(void)
1661 {
1662 (void)fputs(
1663 "usage: tar {crtux}[014578befHhLmOoPpqRSsvwXZz]\n"
1664 "\t [blocking-factor | archive | replstr] [-C directory] [-I file]\n"
1665 "\t [file ...]\n"
1666 " tar {-crtux} [-014578eHhLmOoPpqRSvwXZz] [-b blocking-factor] [-M flag]\n"
1667 "\t [-C directory] [-f archive] [-I file] [-s replstr] [file ...]\n",
1668 stderr);
1669 exit(1);
1670 }
1671
1672 /*
1673 * cpio_usage()
1674 * print the usage summary to the user
1675 */
1676
1677 void
1678 cpio_usage(void)
1679 {
1680 (void)fputs("usage: cpio -o [-AaBcLvZz] [-C bytes] [-F archive] [-H format]\n", stderr);
1681 (void)fputs(" [-M flag] [-O archive] <name-list [>archive]\n", stderr);
1682 (void)fputs(" cpio -i [-6BbcdfmrSstuvZz] [-C bytes] [-E file] [-F archive]\n", stderr);
1683 (void)fputs(" [-H format] [-I archive] [pattern...] [<archive]\n", stderr);
1684 (void)fputs(" cpio -p [-adLlmuv] destination-directory <name-list\n", stderr);
1685 exit(1);
1686 }
1687
1688 void
1689 anonarch_init(void)
1690 {
1691 if (anonarch & ANON_VERBOSE) {
1692 anonarch &= ~ANON_VERBOSE;
1693 paxwarn(0, "debug: -M 0x%08X -x %s", anonarch, frmt->name);
1694 }
1695 }
1696
1697 static void
1698 process_M(const char *arg, void (*call_usage)(void))
1699 {
1700 int j, k = 0;
1701
1702 if ((arg[0] >= '0') && (arg[0] <= '9')) {
1703 #ifdef __OpenBSD__
1704 const char *s;
1705 int64_t i = strtonum(arg, 0,
1706 ANON_MAXVAL, &s);
1707 if (s)
1708 errx(1, "%s M value: %s", s,
1709 arg);
1710 #else
1711 char *ep;
1712 long long i = strtoll(arg, &ep, 0);
1713 if ((ep == arg) || (*ep != '\0') ||
1714 (i < 0) || (i > ANON_MAXVAL))
1715 errx(1, "impossible M value:"
1716 " %s", arg);
1717 #endif
1718 anonarch = i;
1719 return;
1720 }
1721
1722 if (!strncmp(arg, "no-", 3)) {
1723 j = 0;
1724 arg += 3;
1725 } else
1726 j = 1;
1727 if (!strncmp(arg, "uid", 3) ||
1728 !strncmp(arg, "gid", 3)) {
1729 k = ANON_UIDGID;
1730 } else if (!strncmp(arg, "ino", 3)) {
1731 k = ANON_INODES;
1732 } else if (!strncmp(arg, "mtim", 4)) {
1733 k = ANON_MTIME;
1734 } else if (!strncmp(arg, "link", 4)) {
1735 k = ANON_HARDLINKS;
1736 } else if (!strncmp(arg, "norm", 4)) {
1737 k = ANON_UIDGID | ANON_INODES
1738 | ANON_MTIME | ANON_HARDLINKS;
1739 } else if (!strncmp(arg, "root", 4)) {
1740 k = ANON_UIDGID | ANON_INODES;
1741 } else if (!strncmp(arg, "dist", 4)) {
1742 k = ANON_UIDGID | ANON_INODES
1743 | ANON_HARDLINKS;
1744 } else if (!strncmp(arg, "set", 3)) {
1745 k = ANON_INODES | ANON_HARDLINKS;
1746 } else if (!strncmp(arg, "v", 1)) {
1747 k = ANON_VERBOSE;
1748 } else if (!strncmp(arg, "debug", 5)) {
1749 k = ANON_DEBUG;
1750 } else
1751 call_usage();
1752 if (j)
1753 anonarch |= k;
1754 else
1755 anonarch &= ~k;
1756 }

root@freewrt.org:443
ViewVC Help
Powered by ViewVC 1.1.20