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