]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/mtree/mtree.c
This commit was generated by cvs2svn to compensate for changes in r3902,
[FreeBSD/FreeBSD.git] / usr.sbin / mtree / mtree.c
1 /*-
2  * Copyright (c) 1989, 1990, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  */
33
34 #ifndef lint
35 static char copyright[] =
36 "@(#) Copyright (c) 1989, 1990, 1993\n\
37         The Regents of the University of California.  All rights reserved.\n";
38 #endif /* not lint */
39
40 #ifndef lint
41 static char sccsid[] = "@(#)mtree.c     8.1 (Berkeley) 6/6/93";
42 #endif /* not lint */
43
44 #include <sys/param.h>
45 #include <sys/stat.h>
46 #include <errno.h>
47 #include <unistd.h>
48 #include <stdio.h>
49 #include <fts.h>
50 #include "mtree.h"
51 #include "extern.h"
52
53 extern long int crc_total;
54
55 int ftsoptions = FTS_PHYSICAL;
56 int cflag, dflag, eflag, iflag, nflag, rflag, sflag, uflag, Uflag;
57 u_short keys;
58 char fullpath[MAXPATHLEN];
59
60 static void usage __P((void));
61
62 int
63 main(argc, argv)
64         int argc;
65         char *argv[];
66 {
67         extern int optind;
68         extern char *optarg;
69         int ch;
70         char *dir, *p;
71         int status;
72
73         dir = NULL;
74         keys = KEYDEFAULT;
75         while ((ch = getopt(argc, argv, "cdef:iK:k:np:rs:Uux")) != EOF)
76                 switch((char)ch) {
77                 case 'c':
78                         cflag = 1;
79                         break;
80                 case 'd':
81                         dflag = 1;
82                         break;
83                 case 'e':
84                         eflag = 1;
85                         break;
86                 case 'f':
87                         if (!(freopen(optarg, "r", stdin)))
88                                 err("%s: %s", optarg, strerror(errno));
89                         break;
90                 case 'i':
91                         iflag = 1;
92                         break;
93                 case 'K':
94                         while ((p = strsep(&optarg, " \t,")) != NULL)
95                                 if (*p != '\0')
96                                         keys |= parsekey(p, NULL);
97                         break;
98                 case 'k':
99                         keys = F_TYPE;
100                         while ((p = strsep(&optarg, " \t,")) != NULL)
101                                 if (*p != '\0')
102                                         keys |= parsekey(p, NULL);
103                         break;
104                 case 'n':
105                         nflag = 1;
106                         break;
107                 case 'p':
108                         dir = optarg;
109                         break;
110                 case 'r':
111                         rflag = 1;
112                         break;
113                 case 's':
114                         sflag = 1;
115                         crc_total = ~strtol(optarg, &p, 0);
116                         if (*p)
117                                 err("illegal seed value -- %s", optarg);
118                 case 'U':
119                         Uflag = 1;
120                         uflag = 1;
121                         break;
122                 case 'u':
123                         uflag = 1;
124                         break;
125                 case 'x':
126                         ftsoptions |= FTS_XDEV;
127                         break;
128                 case '?':
129                 default:
130                         usage();
131                 }
132         argc -= optind;
133         argv += optind;
134
135         if (argc)
136                 usage();
137
138         if (dir && chdir(dir))
139                 err("%s: %s", dir, strerror(errno));
140
141         if ((cflag || sflag) && !getwd(fullpath))
142                 err("%s", fullpath);
143
144         if (cflag) {
145                 cwalk();
146                 exit(0);
147         }
148         status = verify();
149         if (Uflag & (status == MISMATCHEXIT))
150                 status = 0;
151         exit(status);
152 }
153
154 static void
155 usage()
156 {
157         (void)fprintf(stderr,
158 "usage: mtree [-cdeinrUux] [-f spec] [-K key] [-k key] [-p path] [-s seed]\n");
159         exit(1);
160 }