Annotation of coherent/d/usr/bin/pax/shipping/cpio.c, revision 1.1.1.1

1.1       root        1: /* $Source: /newbits/usr/bin/pax/shipping/RCS/cpio.c,v $
                      2:  *
                      3:  * $Revision: 1.3 $
                      4:  *
                      5:  * cpio.c - Cpio specific functions for archive handling
                      6:  *
                      7:  * DESCRIPTION
                      8:  *
                      9:  *     These function provide a cpio conformant interface to the pax
                     10:  *     program.
                     11:  *
                     12:  * AUTHOR
                     13:  *
                     14:  *     Mark H. Colburn, NAPS International ([email protected])
                     15:  *
                     16:  * Sponsored by The USENIX Association for public distribution. 
                     17:  *
                     18:  * Copyright (c) 1989 Mark H. Colburn.
                     19:  * All rights reserved.
                     20:  *
                     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 
                     26:  * USENIX Association. 
                     27:  *
                     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.
                     31:  *
                     32:  * $Log:       cpio.c,v $
                     33:  * Revision 1.3  92/05/12  07:29:10  bin
                     34:  * Vlad fix to fix bug preserving ownership of files
                     35:  * 
                     36:  * Revision 1.2  91/06/19  09:55:20  bin
                     37:  * udated by vlad for restoring ownership/permissions 
                     38:  * 
                     39:  * Revision 1.1        91/02/05  11:55:26      bin
                     40:  * Initial revision
                     41:  * 
                     42:  * Revision 1.2  89/02/12  10:04:13  mark
                     43:  * 1.2 release fixes
                     44:  * 
                     45:  * Revision 1.1  88/12/23  18:02:05  mark
                     46:  * Initial revision
                     47:  * 
                     48:  */
                     49: 
                     50: #ifndef lint
                     51: static char *ident = "$Id: cpio.c,v 1.3 92/05/12 07:29:10 bin Exp Locker: bin $";
                     52: static char *copyright = "Copyright (c) 1989 Mark H. Colburn.\nAll rights reserved.\n";
                     53: #endif /* ! lint */
                     54: 
                     55: 
                     56: /* Headers */
                     57: 
                     58: #include "pax.h"
                     59: 
                     60: 
                     61: /* Function Prototypes */
                     62: 
                     63: #if __STDC__
                     64: static void    usage(void);
                     65: #else /* !__STDC__ */
                     66: static void    usage();
                     67: #endif /* __STDC__ */
                     68: 
                     69: 
                     70: /* do_cpio - handle cpio format archives
                     71:  *
                     72:  * DESCRIPTION
                     73:  *
                     74:  *     Do_cpio provides a standard CPIO interface to the PAX program.  All
                     75:  *     of the standard cpio flags are available, and the behavior of the
                     76:  *     program mimics traditonal cpio.
                     77:  *
                     78:  * PARAMETERS
                     79:  *
                     80:  *     int     argc    - command line argument count
                     81:  *     char    **argv  - pointer to command line arguments
                     82:  *
                     83:  * RETURNS
                     84:  *
                     85:  *     Nothing.
                     86:  */
                     87: 
                     88: #if __STDC__
                     89: 
                     90: int do_cpio(int argc, char **argv)
                     91: 
                     92: #else
                     93: 
                     94: int do_cpio(argc, argv)
                     95: int             argc;
                     96: char          **argv;
                     97: 
                     98: #endif
                     99: {
                    100:     int             c;
                    101:     char           *dirname;
                    102:     Stat            st;
                    103: 
                    104:     /* default input/output file for CPIO is STDIN/STDOUT */
                    105:     ar_file = "-";
                    106:     names_from_stdin = 1;
                    107: 
                    108:     /* set up the flags to reflect the default CPIO inteface. */
                    109:     blocksize = BLOCKSIZE;
                    110:     ar_interface = CPIO;
                    111:     ar_format = CPIO;
                    112:     msgfile=stderr;
                    113: 
                    114:     while ((c = getopt(argc, argv, "D:BVacdfilmoprtuv")) != EOF) {
                    115:        switch (c) {
                    116:        case 'i':
                    117:            f_extract = 1;
                    118:            f_owner = 1;
                    119:            break;
                    120:        case 'o':
                    121:            f_create = 1;
                    122:            break;
                    123:        case 'p':
                    124:            f_pass = 1;
                    125:            f_owner = 1;
                    126:            dirname = argv[--argc];
                    127: 
                    128:            /* check to make sure that the argument is a directory */
                    129:            if (LSTAT(dirname, &st) < 0) {
                    130:                fatal(strerror());
                    131:            }
                    132:            if ((st.sb_mode & S_IFMT) != S_IFDIR) {
                    133:                fatal("Not a directory");
                    134:            }
                    135:            break;
                    136:        case 'B':
                    137:            blocksize = BLOCK;
                    138:            break;
                    139:        case 'a':
                    140:            f_access_time = 1;
                    141:            break;
                    142:        case 'c':
                    143:            break;
                    144:        case 'D':
                    145:            ar_file = optarg;
                    146:            break;
                    147:        case 'd':
                    148:            f_dir_create = 1;
                    149:            break;
                    150:        case 'f':
                    151:            f_reverse_match = 1;
                    152:            break;
                    153:        case 'l':
                    154:            f_link = 1;
                    155:            break;
                    156:        case 'm':
                    157:            f_mtime = 1;
                    158:            break;
                    159:        case 'r':
                    160:            f_interactive = 1;
                    161:            break;
                    162:        case 't':
                    163:            f_list = 1;
                    164:            break;
                    165:        case 'u':
                    166:            f_unconditional = 1;
                    167:            break;
                    168:        case 'v':
                    169:            f_verbose = 1;
                    170:            break;
                    171:        default:
                    172:            usage();
                    173:        }
                    174:     }
                    175: 
                    176:     if (f_create + f_pass + f_extract != 1) {
                    177:        usage();
                    178:     }
                    179:     if (!f_pass) {
                    180:        buf_allocate((OFFSET) blocksize);
                    181:     }
                    182:     if (f_extract) {
                    183:        open_archive(AR_READ);  /* Open for reading */
                    184:        read_archive();
                    185:     } else if (f_create) {
                    186:        open_archive(AR_WRITE);
                    187:        create_archive();
                    188:     } else if (f_pass) {
                    189:        pass(dirname);
                    190:     }
                    191: 
                    192:     /* print out the total block count transfered */
                    193:     fprintf(stderr, "%ld Blocks\n", ROUNDUP(total, BLOCKSIZE) / BLOCKSIZE);
                    194:     
                    195:     exit(0);
                    196:     /* NOTREACHED */
                    197: }
                    198: 
                    199: 
                    200: /* usage - print a helpful message and exit
                    201:  *
                    202:  * DESCRIPTION
                    203:  *
                    204:  *     Usage prints out the usage message for the CPIO interface and then
                    205:  *     exits with a non-zero termination status.  This is used when a user
                    206:  *     has provided non-existant or incompatible command line arguments.
                    207:  *
                    208:  * RETURNS
                    209:  *
                    210:  *     Returns an exit status of 1 to the parent process.
                    211:  *
                    212:  */
                    213: 
                    214: #if __STDC__
                    215: 
                    216: static void usage(void)
                    217: 
                    218: #else
                    219: 
                    220: static void usage()
                    221: 
                    222: #endif
                    223: {
                    224:     fprintf(stderr, "Usage: %s -o[Bacv]\n", myname);
                    225:     fprintf(stderr, "       %s -i[Bcdmrtuvf] [pattern...]\n", myname);
                    226:     fprintf(stderr, "       %s -p[adlmruv] directory\n", myname);
                    227:     exit(1);
                    228: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.