1 /* @(#)mtree.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: mtree.c,v 1.50 2015/01/23 02:27:01 christos Exp $ */
5 * Copyright (c) 1989, 1990, 1993
6 * The Regents of the University of California. All rights reserved.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. Neither the name of the University nor the names of its contributors
17 * may be used to endorse or promote products derived from this software
18 * without specific prior written permission.
20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 #if HAVE_NBTOOL_CONFIG_H
34 #include "nbtool_config.h"
37 #include <sys/param.h>
48 int ftsoptions = FTS_PHYSICAL;
49 int bflag, dflag, eflag, iflag, jflag, lflag, mflag, nflag, qflag, rflag,
51 char fullpath[MAXPATHLEN];
58 {F_FREEBSD9, "freebsd9"},
59 {F_NETBSD6, "netbsd6"},
62 __dead2 static void usage(void);
65 main(int argc, char **argv)
69 int cflag, Cflag, Dflag, Uflag, wflag;
75 cflag = Cflag = Dflag = Uflag = wflag = 0;
81 while ((ch = getopt(argc, argv,
82 "bcCdDeE:f:F:I:ijk:K:lLmMnN:O:p:PqrR:s:StuUwWxX:"))
101 parsetags(&excludetags, optarg);
107 if (spec1 == stdin) {
108 spec1 = fopen(optarg, "r");
110 mtree_err("%s: %s", optarg,
112 } else if (spec2 == NULL) {
113 spec2 = fopen(optarg, "r");
115 mtree_err("%s: %s", optarg,
121 for (i = 0; i < NELEM(flavors); i++)
122 if (strcmp(optarg, flavors[i].name) == 0) {
123 flavor = flavors[i].flavor;
126 if (i == NELEM(flavors))
133 parsetags(&includetags, optarg);
140 while ((p = strsep(&optarg, " \t,")) != NULL)
142 keys |= parsekey(p, NULL);
145 while ((p = strsep(&optarg, " \t,")) != NULL)
147 keys |= parsekey(p, NULL);
153 ftsoptions &= ~FTS_PHYSICAL;
154 ftsoptions |= FTS_LOGICAL;
166 if (! setup_getid(optarg))
168 "Unable to use user and group databases in `%s'",
178 ftsoptions &= ~FTS_LOGICAL;
179 ftsoptions |= FTS_PHYSICAL;
188 while ((p = strsep(&optarg, " \t,")) != NULL)
190 keys &= ~parsekey(p, NULL);
194 crc_total = ~strtol(optarg, &p, 0);
196 mtree_err("illegal seed value -- %s", optarg);
217 ftsoptions |= FTS_XDEV;
220 read_excludes_file(optarg);
235 if (cflag && iflag) {
236 warnx("-c and -i passed, replacing -i with -j for "
237 "FreeBSD compatibility");
241 if (dflag && !bflag) {
242 warnx("Adding -b to -d for FreeBSD compatibility");
245 if (uflag && !iflag) {
246 warnx("Adding -i to -%c for FreeBSD compatibility",
250 if (uflag && !tflag) {
251 warnx("Adding -t to -%c for FreeBSD compatibility",
256 warnx("The -w flag is a no-op");
263 if (spec2 && (cflag || Cflag || Dflag))
264 mtree_err("Double -f, -c, -C and -D flags are mutually "
268 mtree_err("Double -f and -p flags are mutually exclusive");
270 if (dir && chdir(dir))
271 mtree_err("%s: %s", dir, strerror(errno));
273 if ((cflag || sflag) && !getcwd(fullpath, sizeof(fullpath)))
274 mtree_err("%s", strerror(errno));
276 if ((cflag && Cflag) || (cflag && Dflag) || (Cflag && Dflag))
277 mtree_err("-c, -C and -D flags are mutually exclusive");
280 mtree_err("-i and -m flags are mutually exclusive");
283 mtree_err("-l and -u flags are mutually exclusive");
289 if (Cflag || Dflag) {
290 dump_nodes(stdout, "", spec(spec1), Dflag);
294 status = mtree_specspec(spec1, spec2);
296 status = verify(spec1);
297 if (Uflag && (status == MISMATCHEXIT))
308 "usage: %s [-bCcDdejLlMnPqrStUuWx] [-i|-m] [-E tags]\n"
309 "\t\t[-f spec] [-f spec]\n"
310 "\t\t[-I tags] [-K keywords] [-k keywords] [-N dbdir] [-p path]\n"
311 "\t\t[-R keywords] [-s seed] [-X exclude-file]\n"
314 fprintf(stderr, "\nflavors:");
315 for (i = 0; i < NELEM(flavors); i++)
316 fprintf(stderr, " %s", flavors[i].name);
317 fprintf(stderr, "\n");