1 /* $Source: /u/mark/src/pax/RCS/cpio.c,v $
5 * cpio.c - Cpio specific functions for archive handling
9 * These function provide a cpio conformant interface to the pax
14 * Mark H. Colburn, NAPS International (mark@jhereg.mn.org)
16 * Sponsored by The USENIX Association for public distribution.
18 * Copyright (c) 1989 Mark H. Colburn.
19 * All rights reserved.
21 * Redistribution and use in source and binary forms are permitted
22 * provided that the above copyright notice is duplicated in all such
23 * forms and that any documentation, advertising materials, and other
24 * materials related to such distribution and use acknowledge that the
25 * software was developed * by Mark H. Colburn and sponsored by The
28 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
29 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
30 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
33 * Revision 1.2 89/02/12 10:04:13 mark
36 * Revision 1.1 88/12/23 18:02:05 mark
42 static char *ident = "$Id: cpio.c,v 1.2 89/02/12 10:04:13 mark Exp $";
43 static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
52 /* Function Prototypes */
55 static void usage(void);
61 /* do_cpio - handle cpio format archives
65 * Do_cpio provides a standard CPIO interface to the PAX program. All
66 * of the standard cpio flags are available, and the behavior of the
67 * program mimics traditonal cpio.
71 * int argc - command line argument count
72 * char **argv - pointer to command line arguments
81 int do_cpio(int argc, char **argv)
85 int do_cpio(argc, argv)
95 /* default input/output file for CPIO is STDIN/STDOUT */
99 /* set up the flags to reflect the default CPIO inteface. */
100 blocksize = BLOCKSIZE;
105 while ((c = getopt(argc, argv, "D:Bacdfilmoprtuv")) != EOF) {
115 dirname = argv[--argc];
117 /* check to make sure that the argument is a directory */
118 if (LSTAT(dirname, &st) < 0) {
121 if ((st.sb_mode & S_IFMT) != S_IFDIR) {
122 fatal("Not a directory");
165 if (f_create + f_pass + f_extract != 1) {
169 buf_allocate((OFFSET) blocksize);
172 open_archive(AR_READ); /* Open for reading */
174 } else if (f_create) {
175 open_archive(AR_WRITE);
181 /* print out the total block count transfered */
182 fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
189 /* usage - print a helpful message and exit
193 * Usage prints out the usage message for the CPIO interface and then
194 * exits with a non-zero termination status. This is used when a user
195 * has provided non-existant or incompatible command line arguments.
199 * Returns an exit status of 1 to the parent process.
205 static void usage(void)
213 fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
214 fprintf(stderr, " %s -i[Bcdmrtuvf] [pattern...]\n", myname);
215 fprintf(stderr, " %s -p[adlmruv] directory\n", myname);