mtree.c revision 63853
11638Srgrimes/*- 21638Srgrimes * Copyright (c) 1989, 1990, 1993 31638Srgrimes * The Regents of the University of California. All rights reserved. 41638Srgrimes * 51638Srgrimes * Redistribution and use in source and binary forms, with or without 61638Srgrimes * modification, are permitted provided that the following conditions 71638Srgrimes * are met: 81638Srgrimes * 1. Redistributions of source code must retain the above copyright 91638Srgrimes * notice, this list of conditions and the following disclaimer. 101638Srgrimes * 2. Redistributions in binary form must reproduce the above copyright 111638Srgrimes * notice, this list of conditions and the following disclaimer in the 121638Srgrimes * documentation and/or other materials provided with the distribution. 131638Srgrimes * 3. All advertising materials mentioning features or use of this software 141638Srgrimes * must display the following acknowledgement: 151638Srgrimes * This product includes software developed by the University of 161638Srgrimes * California, Berkeley and its contributors. 171638Srgrimes * 4. Neither the name of the University nor the names of its contributors 181638Srgrimes * may be used to endorse or promote products derived from this software 191638Srgrimes * without specific prior written permission. 201638Srgrimes * 211638Srgrimes * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 221638Srgrimes * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 231638Srgrimes * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 241638Srgrimes * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 251638Srgrimes * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 261638Srgrimes * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 271638Srgrimes * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 281638Srgrimes * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 291638Srgrimes * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 301638Srgrimes * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 311638Srgrimes * SUCH DAMAGE. 321638Srgrimes */ 3350476Speter 341638Srgrimes#ifndef lint 3543239Swollmanstatic const char copyright[] = 361638Srgrimes"@(#) Copyright (c) 1989, 1990, 1993\n\ 371638Srgrimes The Regents of the University of California. All rights reserved.\n"; 381638Srgrimes#endif /* not lint */ 391638Srgrimes 401638Srgrimes#ifndef lint 411638Srgrimes#if 0 4284306Srustatic char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93"; 431638Srgrimes#endif 441638Srgrimesstatic const char rcsid[] = 451638Srgrimes "$FreeBSD: head/usr.sbin/mtree/mtree.c 63853 2000-07-25 19:05:09Z imp $"; 461638Srgrimes#endif /* not lint */ 471638Srgrimes 481638Srgrimes#include <sys/param.h> 491638Srgrimes#include <sys/stat.h> 501638Srgrimes#include <err.h> 511638Srgrimes#include <errno.h> 5243239Swollman#include <fts.h> 53107619Sru#include <stdio.h> 541638Srgrimes#include <unistd.h> 5516339Salex#include "mtree.h" 5646202Skris#include "extern.h" 571638Srgrimes 581638Srgrimesextern long int crc_total; 591638Srgrimes 601638Srgrimesint ftsoptions = FTS_LOGICAL; 611638Srgrimesint cflag, dflag, eflag, iflag, nflag, qflag, rflag, sflag, uflag, Uflag; 621638Srgrimesu_int keys; 631638Srgrimeschar fullpath[MAXPATHLEN]; 641638Srgrimes 651638Srgrimesstatic void usage __P((void)); 661638Srgrimes 671638Srgrimesint 6843239Swollmanmain(argc, argv) 6943239Swollman int argc; 7043239Swollman char *argv[]; 7143239Swollman{ 7243239Swollman int ch; 7343239Swollman char *dir, *p; 7443239Swollman int status; 7585607Smike 7685607Smike dir = NULL; 7785607Smike keys = KEYDEFAULT; 7886670Sru init_excludes(); 7986670Sru 8085607Smike while ((ch = getopt(argc, argv, "cdef:iK:k:np:Prs:UuxX:")) != -1) 8186670Sru switch((char)ch) { 82105933Stjr case 'c': 8332193Salex cflag = 1; 8432193Salex break; 8585424Sasmodai case 'd': 8685424Sasmodai dflag = 1; 8785424Sasmodai break; 8885607Smike case 'e': 8985424Sasmodai eflag = 1; 901638Srgrimes break; 9146202Skris case 'f': 9268962Sru if (!(freopen(optarg, "r", stdin))) 931638Srgrimes err(1, "%s", optarg); 941638Srgrimes break; 95 case 'i': 96 iflag = 1; 97 break; 98 case 'K': 99 while ((p = strsep(&optarg, " \t,")) != NULL) 100 if (*p != '\0') 101 keys |= parsekey(p, NULL); 102 break; 103 case 'k': 104 keys = F_TYPE; 105 while ((p = strsep(&optarg, " \t,")) != NULL) 106 if (*p != '\0') 107 keys |= parsekey(p, NULL); 108 break; 109 case 'n': 110 nflag = 1; 111 break; 112 case 'p': 113 dir = optarg; 114 break; 115 case 'q': 116 qflag = 1; 117 break; 118 case 'P': 119 ftsoptions ^= FTS_LOGICAL; 120 ftsoptions |= FTS_PHYSICAL; 121 break; 122 case 'r': 123 rflag = 1; 124 break; 125 case 's': 126 sflag = 1; 127 crc_total = ~strtol(optarg, &p, 0); 128 if (*p) 129 errx(1, "illegal seed value -- %s", optarg); 130 case 'U': 131 Uflag = 1; 132 uflag = 1; 133 break; 134 case 'u': 135 uflag = 1; 136 break; 137 case 'x': 138 ftsoptions |= FTS_XDEV; 139 break; 140 case 'X': 141 read_excludes_file(optarg); 142 break; 143 case '?': 144 default: 145 usage(); 146 } 147 argc -= optind; 148 argv += optind; 149 150 if (argc) 151 usage(); 152 153 if (dir && chdir(dir)) 154 err(1, "%s", dir); 155 156 if ((cflag || sflag) && !getwd(fullpath)) 157 errx(1, "%s", fullpath); 158 159 if (cflag) { 160 cwalk(); 161 exit(0); 162 } 163 status = verify(); 164 if (Uflag & (status == MISMATCHEXIT)) 165 status = 0; 166 exit(status); 167} 168 169static void 170usage() 171{ 172 (void)fprintf(stderr, 173"usage: mtree [-PUcdeinqrux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n" 174"\t[-X excludes]\n"); 175 exit(1); 176} 177