mtree.c revision 36670
11553Srgrimes/*- 21553Srgrimes * Copyright (c) 1989, 1990, 1993 31553Srgrimes * The Regents of the University of California. All rights reserved. 41553Srgrimes * 51553Srgrimes * Redistribution and use in source and binary forms, with or without 61553Srgrimes * modification, are permitted provided that the following conditions 71553Srgrimes * are met: 81553Srgrimes * 1. Redistributions of source code must retain the above copyright 91553Srgrimes * notice, this list of conditions and the following disclaimer. 101553Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111553Srgrimes * notice, this list of conditions and the following disclaimer in the 121553Srgrimes * documentation and/or other materials provided with the distribution. 131553Srgrimes * 3. All advertising materials mentioning features or use of this software 141553Srgrimes * must display the following acknowledgement: 151553Srgrimes * This product includes software developed by the University of 161553Srgrimes * California, Berkeley and its contributors. 171553Srgrimes * 4. Neither the name of the University nor the names of its contributors 181553Srgrimes * may be used to endorse or promote products derived from this software 191553Srgrimes * without specific prior written permission. 201553Srgrimes * 211553Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221553Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231553Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241553Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251553Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261553Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271553Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281553Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291553Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301553Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311553Srgrimes * SUCH DAMAGE. 321553Srgrimes */ 331553Srgrimes 341553Srgrimes#ifndef lint 3530027Scharnierstatic const char copyright[] = 361553Srgrimes"@(#) Copyright (c) 1989, 1990, 1993\n\ 371553Srgrimes The Regents of the University of California. All rights reserved.\n"; 381553Srgrimes#endif /* not lint */ 391553Srgrimes 401553Srgrimes#ifndef lint 4130027Scharnier#if 0 421553Srgrimesstatic char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; 4330027Scharnier#endif 4430027Scharnierstatic const char rcsid[] = 4536670Speter "$Id: mtree.c,v 1.6 1997/10/01 06:30:02 charnier Exp $"; 461553Srgrimes#endif /* not lint */ 471553Srgrimes 481553Srgrimes#include <sys/param.h> 491553Srgrimes#include <sys/stat.h> 5030027Scharnier#include <err.h> 511553Srgrimes#include <errno.h> 5230027Scharnier#include <fts.h> 5330027Scharnier#include <stdio.h> 541553Srgrimes#include <unistd.h> 551553Srgrimes#include "mtree.h" 561553Srgrimes#include "extern.h" 571553Srgrimes 582860Srgrimesextern long int crc_total; 591553Srgrimes 6025831Sacheint ftsoptions = FTS_LOGICAL; 613468Srgrimesint cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag; 6236670Speteru_int keys; 631553Srgrimeschar fullpath[MAXPATHLEN]; 641553Srgrimes 651553Srgrimesstatic void usage __P((void)); 661553Srgrimes 671553Srgrimesint 681553Srgrimesmain(argc, argv) 691553Srgrimes int argc; 701553Srgrimes char *argv[]; 711553Srgrimes{ 721553Srgrimes int ch; 731553Srgrimes char *dir, *p; 743468Srgrimes int status; 751553Srgrimes 761553Srgrimes dir = NULL; 771553Srgrimes keys = KEYDEFAULT; 7824428Simp while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != -1) 791553Srgrimes switch((char)ch) { 801553Srgrimes case 'c': 811553Srgrimes cflag = 1; 821553Srgrimes break; 831553Srgrimes case 'd': 841553Srgrimes dflag = 1; 851553Srgrimes break; 861553Srgrimes case 'e': 871553Srgrimes eflag = 1; 881553Srgrimes break; 891553Srgrimes case 'f': 901553Srgrimes if (!(freopen(optarg, "r", stdin))) 9130027Scharnier err(1, "%s", optarg); 921553Srgrimes break; 932860Srgrimes case 'i': 942860Srgrimes iflag = 1; 952860Srgrimes break; 961553Srgrimes case 'K': 971553Srgrimes while ((p = strsep(&optarg, " \t,")) != NULL) 981553Srgrimes if (*p != '\0') 991553Srgrimes keys |= parsekey(p, NULL); 1001553Srgrimes break; 1011553Srgrimes case 'k': 1021553Srgrimes keys = F_TYPE; 1031553Srgrimes while ((p = strsep(&optarg, " \t,")) != NULL) 1041553Srgrimes if (*p != '\0') 1051553Srgrimes keys |= parsekey(p, NULL); 1061553Srgrimes break; 1072860Srgrimes case 'n': 1082860Srgrimes nflag = 1; 1092860Srgrimes break; 1101553Srgrimes case 'p': 1111553Srgrimes dir = optarg; 1121553Srgrimes break; 1131553Srgrimes case 'r': 1141553Srgrimes rflag = 1; 1151553Srgrimes break; 1161553Srgrimes case 's': 1171553Srgrimes sflag = 1; 1181553Srgrimes crc_total = ~strtol(optarg, &p, 0); 1191553Srgrimes if (*p) 12030027Scharnier errx(1, "illegal seed value -- %s", optarg); 1213468Srgrimes case 'U': 1223468Srgrimes Uflag = 1; 1233468Srgrimes uflag = 1; 1243468Srgrimes break; 1251553Srgrimes case 'u': 1261553Srgrimes uflag = 1; 1271553Srgrimes break; 1281553Srgrimes case 'x': 1291553Srgrimes ftsoptions |= FTS_XDEV; 1301553Srgrimes break; 1311553Srgrimes case '?': 1321553Srgrimes default: 1331553Srgrimes usage(); 1341553Srgrimes } 1351553Srgrimes argc -= optind; 1361553Srgrimes argv += optind; 1371553Srgrimes 1381553Srgrimes if (argc) 1391553Srgrimes usage(); 1401553Srgrimes 1411553Srgrimes if (dir && chdir(dir)) 14230027Scharnier err(1, "%s", dir); 1431553Srgrimes 1441553Srgrimes if ((cflag || sflag) && !getwd(fullpath)) 14530027Scharnier errx(1, "%s", fullpath); 1461553Srgrimes 1471553Srgrimes if (cflag) { 1481553Srgrimes cwalk(); 1491553Srgrimes exit(0); 1501553Srgrimes } 1513468Srgrimes status = verify(); 1523468Srgrimes if (Uflag & (status == MISMATCHEXIT)) 1533468Srgrimes status = 0; 1543468Srgrimes exit(status); 1551553Srgrimes} 1561553Srgrimes 1571553Srgrimesstatic void 1581553Srgrimesusage() 1591553Srgrimes{ 1601553Srgrimes (void)fprintf(stderr, 1613468Srgrimes"usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n"); 1621553Srgrimes exit(1); 1631553Srgrimes} 164