Annotation of coherent/e/bin/pax/cpio.c, revision 1.1

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

unix.superglobalmegacorp.com

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