diff options
author | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-02-20 06:54:36 +0000 |
---|---|---|
committer | Thorsten Lockert <tholo@cvs.openbsd.org> | 1997-02-20 06:54:36 +0000 |
commit | af346233bc1194582bd3befc8b7f439fe021064f (patch) | |
tree | b4c1887fddf5fd7335eca4890f7ade0eb2e9c5d5 | |
parent | 9001cf645fe47840341f507eed55f4b74dc9589e (diff) |
cpio emulation for pax
-rw-r--r-- | bin/pax/ar_io.c | 6 | ||||
-rw-r--r-- | bin/pax/cpio.1 | 273 | ||||
-rw-r--r-- | bin/pax/options.c | 260 | ||||
-rw-r--r-- | bin/pax/pax.1 | 5 |
4 files changed, 530 insertions, 14 deletions
diff --git a/bin/pax/ar_io.c b/bin/pax/ar_io.c index 4a235c50970..5ee70128781 100644 --- a/bin/pax/ar_io.c +++ b/bin/pax/ar_io.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ar_io.c,v 1.9 1997/02/16 07:51:12 tholo Exp $ */ +/* $OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $ */ /* $NetBSD: ar_io.c,v 1.5 1996/03/26 23:54:13 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)ar_io.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: ar_io.c,v 1.9 1997/02/16 07:51:12 tholo Exp $"; +static char rcsid[] = "$OpenBSD: ar_io.c,v 1.10 1997/02/20 06:54:31 tholo Exp $"; #endif #endif /* not lint */ @@ -402,7 +402,7 @@ ar_close() return; } - if (strcmp(NM_TAR, argv0) != 0) + if (strcmp(NM_TAR, argv0) != 0 && strcmp(NM_CPIO, argv0) != 0) (void)fprintf(outf, # ifdef NET2_STAT "%s: %s vol %d, %lu files, %lu bytes read, %lu bytes written.\n", diff --git a/bin/pax/cpio.1 b/bin/pax/cpio.1 new file mode 100644 index 00000000000..f6af9140ece --- /dev/null +++ b/bin/pax/cpio.1 @@ -0,0 +1,273 @@ +.\" +.\" Copyright (c) 1997 SigmaSoft, Th. Lockert +.\" All rights reserved. +.\" +.\" 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. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by SigmaSoft, Th. Lockert. +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. +.\" +.\" $OpenBSD: cpio.1,v 1.1 1997/02/20 06:54:33 tholo Exp $ +.\" +.Dd February 16, 1997 +.Dt CPIO 1 +.Os +.Sh NAME +.Nm cpio +.Nd copy file archives in and out +.Sh SYNOPSIS +.Nm cpio +.Fl o +.Op Fl aABcLvzZ +.Op Fl C Ar bytes +.Op Fl F Ar archive +.Op Fl H Ar format +.Op Fl O Ar archive +.Ar "< name-list" +.Op Ar "> archive" +.Nm cpio +.Fl i +.Op Fl bBcdfmrsStuvzZ6 +.Op Fl C Ar bytes +.Op Fl E Ar file +.Op Fl F Ar archive +.Op Fl H Ar format +.Op Fl I Ar archive +.Op Ar "pattern ..." +.Op Ar "< archive" +.Nm cpio +.Fl p +.Op Fl adlLmuv +.Ar destination-directory +.Ar "< name-list" +.Sh DESCRIPTION +The +.Nm +command copies files to and from a +.Nm +archive. +.Pp +The following options are supported: +.Bl -tag -width Fl +.It Fl o +Create an archive. Reads the list of files to store in the +archive from standard input, and writes the archive on standard +output. +.Bl -tag -width Fl +.It Fl a +Reset the access times on files that has been copied to the +archive. +.It Fl A +Append to the specified archive. +.It Fl B +Set block size of output to 5120 bytes. +.It Fl c +Use ASCII format for +.Nm +header for portability. +.It Fl C Ar bytes +Set the block size of output to +.Ar bytes . +.It Fl F Ar archive +.It Fl O Ar archive +Use the specified file name as the archive to write to. +.It Fl H Ar format +Write the archive in the specified format. Recognized +formats are: +.Bl -tag -width Ds +.It Ar bcpio +Old binary cpio format. +.It Ar cpio +Old octal character cpio format. +.It Ar sv4cpio +SVR4 hex cpio format. +.It Ar tar +Old tar format. +.It Ar ustar +POSIX ustar format. +.El +.It Fl L +Follow symbolic links. +.It Fl v +Be verbose about operations. List filenames as they are +written to the archive. +.It Fl z +Compress archive using +.Xr gzip 1 +format. +.It Fl Z +Compress archive using +.Xr compress 1 +format. +.El +.It Fl i +Restore files from an archive. Reads the archive file from +standard input and extracts files matching the +.Ar patterns +that were specified on the command line. +.Bl -tag -width Fl +.It Fl b +Do byte- and word swapping after reading in data from the +archive, for restoring archives created on systems with +different byte order. +.It Fl B +Set the block size of the archive being read to 5120 bytes. +.It Fl c +Expect the archive headers to be in ASCII format. +.It Fl C Ar bytes +Read archive written with a blocksize of +.Ar bytes . +.It Fl d +Create any intermediate directories as needed during +restore. +.It Fl E Ar file +Read list of file name patters to extract or list from +.Ar file . +.It Fl f +Restore all files except those matching the +.Ar patterns +given on the command line. +.It Fl F Ar archive +.It Fl I Ar archive +Use the specified file as the input for the archive. +.It Fl H Ar format +Read an archive of the specified format. Recognized +formats are: +.Bl -tag -width Ds +.It Ar bcpio +Old binary cpio format. +.It Ar cpio +Old octal character cpio format. +.It Ar sv4cpio +SVR4 hex cpio format. +.It Ar tar +Old tar format. +.It Ar ustar +POSIX ustar format. +.El +.It Fl m +Restore modification times on files. +.It Fl r +Rename restored files interactively. +.It Fl s +Swap bytes after reading data from the archive. +.It Fl S +Swap words after reading data from the archive. +.It Fl t +Only list the contents of the archive, no files or +directories will be created. +.It Fl u +Overwrite files even when the file in the archive is +older than the one that will be overwritten. +.It Fl v +Be verbose about operations. List filenames as they are +copied in from the archive. +.It Fl z +Uncompress archive using +.Xr gzip 1 +format. +.It Fl Z +Uncompress archive using +.Xr compress 1 +format. +.It Fl 6 +Process old-style \*Qcpio\*U format archives. +.El +.It Fl p +Copy files from one location to another in a single pass. +The list of files to copy are read from standard in and +written out to a directory relative to the specified +.Ar directory +argument. +.Bl -tag -width Fl +.It Fl a +Reset the access times on files that has been copied. +.It Fl d +Create any intermediate directories as needed to write +the files at the new location. +.It Fl l +When possible, link files rather than creating an +extra copy. +.It Fl L +Follow symbolic links. +.It Fl m +Restore modification times on files. +.It Fl u +Overwrite files even when the original file being copied is +older than the one that will be overwritten. +.It Fl v +Be verbose about operations. List filenames as they are +copied. +.El +.El +.Sh ERRORS +.Nm +will exit with one of the following values: +.Bl -tag -width 2n +.It 0 +All files were processed successfully. +.It 1 +An error occured. +.El +.Pp +Whenever +.Nm +cannot create a file or a link when extracting an archive or cannot +find a file while writing an archive, or cannot preserve the user +ID, group ID, file mode or access and modification times when the +.Fl p +options is specified, a diagnostic message is written to standard +error and a non-zero exit value will be returned, but processing +will continue. In the case where +.Nm +cannot create a link to a file, +.Nm +will not create a second copy of the file. +.Pp +If the extraction of a file from an archive is prematurely terminated +by a signal or error, +.Nm +may have only partially extracted the file the user wanted. +Additionally, the file modes of extracted files and directories may +have incorrect file bits, and the modification and access times may +be wrong. +.Pp +If the creation of an archive is prematurely terminated by a signal +or error, +.Nm +may have only partially created the archive which may violate the +specific archive format specification. +.Sh SEE ALSO +.Xr pax 1 , +.Xr tar 1 +.Sh BUGS +The +.Fl d +option is the default and cannot be turned off. +The +.Fl s +and +.Fl S +options are currently not implemented. +.Sh AUTHOR +Keith Muller at the University of California, San Diego diff --git a/bin/pax/options.c b/bin/pax/options.c index 953460529b1..a451228903c 100644 --- a/bin/pax/options.c +++ b/bin/pax/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.13 1997/01/24 19:41:23 millert Exp $ */ +/* $OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $ */ /* $NetBSD: options.c,v 1.6 1996/03/26 23:54:18 mrg Exp $ */ /*- @@ -42,7 +42,7 @@ #if 0 static char sccsid[] = "@(#)options.c 8.2 (Berkeley) 4/18/94"; #else -static char rcsid[] = "$OpenBSD: options.c,v 1.13 1997/01/24 19:41:23 millert Exp $"; +static char rcsid[] = "$OpenBSD: options.c,v 1.14 1997/02/20 06:54:34 tholo Exp $"; #endif #endif /* not lint */ @@ -79,10 +79,8 @@ static void pax_options __P((register int, register char **)); static void pax_usage __P((void)); static void tar_options __P((register int, register char **)); static void tar_usage __P((void)); -#ifdef notdef static void cpio_options __P((register int, register char **)); static void cpio_usage __P((void)); -#endif #define GZIP_CMD "gzip" /* command to run as gzip */ #define COMPRESS_CMD "compress" /* command to run as compress */ @@ -127,6 +125,9 @@ FSUB fsub[] = { ustar_rd, tar_endrd, ustar_stwr, ustar_wr, tar_endwr, tar_trail, rd_wrfile, wr_rdfile, bad_opt}, }; +#define F_OCPIO 0 /* format when called as cpio -6 */ +#define F_ACPIO 1 /* format when called as cpio -c */ +#define F_CPIO 3 /* format when called as cpio */ #define F_TAR 5 /* format when called as tar */ #define DEFLT 5 /* default write format from list above */ @@ -164,10 +165,8 @@ options(argc, argv) if (strcmp(NM_TAR, argv0) == 0) return(tar_options(argc, argv)); -# ifdef notdef else if (strcmp(NM_CPIO, argv0) == 0) return(cpio_options(argc, argv)); -# endif /* * assume pax as the default */ @@ -856,7 +855,6 @@ tar_options(argc, argv) } } -#ifdef notdef /* * cpio_options() * look at the user specified flags. set globals as required and check if @@ -873,8 +871,247 @@ cpio_options(argc, argv) register char **argv; #endif { + register int c, i; + size_t len; + char *str; + FSUB tmp; + FILE *fp; + + kflag = 1; + pids = 1; + pmode = 1; + arcname = NULL; + dflag = 1; + act = -1; + while ((c=getopt(argc,argv,"abcdfiklmoprstuvzABC:E:F:H:I:LO:SZ6")) != EOF) + switch (c) { + case 'a': + /* + * preserve access time on files read + */ + tflag = 1; + break; + case 'b': + /* + * swap bytes and half-words when reading data + */ + break; + case 'c': + /* + * ASCII cpio header + */ + frmt = &(fsub[F_ACPIO]); + break; + case 'd': + /* + * create directories as needed + */ + break; + case 'f': + /* + * invert meaning of pattern list + */ + cflag = 1; + break; + case 'i': + /* + * restore an archive + */ + act = EXTRACT; + break; + case 'k': + break; + case 'l': + /* + * use links instead of copies when possible + */ + lflag = 1; + break; + case 'm': + /* + * preserve modification time + */ + pmtime = 1; + break; + case 'o': + /* + * create an archive + */ + act = ARCHIVE; + frmt = &(fsub[F_CPIO]); + break; + case 'p': + /* + * copy-pass mode + */ + act = COPY; + break; + case 'r': + /* + * interactively rename files + */ + iflag = 1; + break; + case 's': + /* + * swap bytes after reading data + */ + break; + case 't': + /* + * list contents of archive + */ + act = LIST; + break; + case 'u': + /* + * replace newer files + */ + kflag = 0; + break; + case 'v': + /* + * verbose operation mode + */ + vflag = 1; + break; + case 'z': + /* + * use gzip. Non standard option. + */ + zflag = 1; + gzip_program = GZIP_CMD; + break; + case 'A': + /* + * append mode + */ + act = APPND; + break; + case 'B': + /* + * Use 5120 byte block size + */ + wrblksz = 5120; + break; + case 'C': + /* + * set block size in bytes + */ + wrblksz = atoi(optarg); + break; + case 'E': + /* + * file with patterns to extract or list + */ + if ((fp = fopen(optarg, "r")) == NULL) { + paxwarn(1, "Unable to open file '%s' for read", optarg); + cpio_usage(); + } + while ((str = fgetln(fp, &len)) != NULL) { + str[len - 1] = '\0'; + pat_add(str, NULL); + } + fclose(fp); + break; + case 'F': + case 'I': + case 'O': + /* + * filename where the archive is stored + */ + if ((optarg[0] == '-') && (optarg[1]== '\0')) { + /* + * treat a - as stdin + */ + arcname = NULL; + break; + } + arcname = optarg; + break; + case 'H': + /* + * specify an archive format on write + */ + tmp.name = optarg; + if ((frmt = (FSUB *)bsearch((void *)&tmp, (void *)fsub, + sizeof(fsub)/sizeof(FSUB), sizeof(FSUB), c_frmt)) != NULL) + break; + paxwarn(1, "Unknown -H format: %s", optarg); + (void)fputs("cpio: Known -H formats are:", stderr); + for (i = 0; i < (sizeof(fsub)/sizeof(FSUB)); ++i) + (void)fprintf(stderr, " %s", fsub[i].name); + (void)fputs("\n\n", stderr); + cpio_usage(); + break; + case 'L': + /* + * follow symbolic links + */ + Lflag = 1; + break; + case 'S': + /* + * swap halfwords after reading data + */ + break; + case 'Z': + /* + * use compress. Non standard option. + */ + zflag = 1; + gzip_program = COMPRESS_CMD; + break; + case '6': + /* + * process Version 6 cpio format + */ + frmt = &(fsub[F_OCPIO]); + break; + case '?': + default: + cpio_usage(); + break; + } + argc -= optind; + argv += optind; + + /* + * process the args as they are interpreted by the operation mode + */ + switch (act) { + case LIST: + case EXTRACT: + while (*argv != (char *)NULL) + if (pat_add(*argv++, NULL) < 0) + cpio_usage(); + break; + case COPY: + if (optind >= argc) { + paxwarn(0, "Destination directory was not supplied"); + cpio_usage(); + } + --argc; + dirptr = argv[argc]; + /* FALL THROUGH */ + case ARCHIVE: + case APPND: + if (*argv != (char *)NULL) + cpio_usage(); + /* + * no read errors allowed on updates/append operation! + */ + maxflt = 0; + while ((str = fgetln(stdin, &len)) != NULL) { + str[len - 1] = '\0'; + ftree_add(str, NULL); + } + break; + default: + cpio_usage(); + break; + } } -#endif /* * printflg() @@ -1195,7 +1432,6 @@ tar_usage() exit(1); } -#ifdef notdef /* * cpio_usage() * print the usage summary to the user @@ -1209,6 +1445,10 @@ void cpio_usage() #endif { + (void)fputs("usage: cpio -o [-aABcLvVzZ] [-C bytes] [-H format] [-O archive]\n", stderr); + (void)fputs(" [-F archive] < name-list [> archive]\n", stderr); + (void)fputs(" cpio -i [-bBcdfmnrsStuvVzZ6] [-C bytes] [-E file] [-H format]\n", stderr); + (void)fputs(" [-I archive] [-F archive] [pattern...] [< archive]\n", stderr); + (void)fputs(" cpio -p [-adlLmuvV] destination-directory < name-list\n", stderr); exit(1); } -#endif diff --git a/bin/pax/pax.1 b/bin/pax/pax.1 index 6e1c96e509b..38fc183f1b2 100644 --- a/bin/pax/pax.1 +++ b/bin/pax/pax.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: pax.1,v 1.3 1996/06/23 14:20:39 deraadt Exp $ +.\" $OpenBSD: pax.1,v 1.4 1997/02/20 06:54:35 tholo Exp $ .\" $NetBSD: pax.1,v 1.3 1995/03/21 09:07:37 cgd Exp $ .\" .\" Copyright (c) 1992 Keith Muller. @@ -1123,6 +1123,9 @@ and operations are extensions to the .Tn POSIX standard. +.Sh SEE ALSO +.Xr tar 1 , +.Xr cpio 1 .Sh AUTHOR Keith Muller at the University of California, San Diego .Sh ERRORS |