/*
* Copyright (c) 2001-2003 Wasabi Systems, Inc.
* All rights reserved.
*
* Written by Luke Mewburn for Wasabi Systems, Inc.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed for the NetBSD Project by
* Wasabi Systems, Inc.
* 4. The name of Wasabi Systems, Inc. may not be used to endorse
* or promote products derived from this software without specific prior
* written permission.
*
* THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
case 'S':
fsoptions.sectorsize =
(int)strsuftoll("sector size", optarg,
1LL, INT_MAX);
break;
case 't':
/* Check current one and cleanup if necessary. */
if (fstype->cleanup_options)
fstype->cleanup_options(&fsoptions);
fsoptions.fs_specific = NULL;
if ((fstype = get_fstype(optarg)) == NULL)
errx(EXIT_FAILURE,
"Unknown fs type `%s'.", optarg);
fstype->prepare_options(&fsoptions);
break;
case 'T':
if (get_tstamp(optarg, &stampst) == -1)
errx(EXIT_FAILURE,
"Cannot get timestamp from `%s'", optarg);
break;
case 'x':
fsoptions.onlyspec++;
break;
case 'Z':
fsoptions.sparse = 1;
break;
case '?':
default:
usage(fstype, &fsoptions);
/* NOTREACHED */
/* -x must be accompanied by -F */
if (fsoptions.onlyspec != 0 && specfile == NULL)
errx(EXIT_FAILURE, "-x requires -F mtree-specfile.");
/* walk the tree */
TIMER_START(start);
root = walk_dir(argv[1], ".", NULL, NULL, fsoptions.replace,
fsoptions.follow);
TIMER_RESULTS(start, "walk_dir");
/* append extra directory */
for (i = 2; i < argc; i++) {
struct stat sb;
if (stat(argv[i], &sb) == -1)
err(EXIT_FAILURE, "Can't stat `%s'", argv[i]);
if (!S_ISDIR(sb.st_mode))
errx(EXIT_FAILURE, "%s: not a directory", argv[i]);
TIMER_START(start);
root = walk_dir(argv[i], ".", NULL, root, fsoptions.replace,
fsoptions.follow);
TIMER_RESULTS(start, "walk_dir2");
}
if (specfile) { /* apply a specfile */
TIMER_START(start);
apply_specfile(specfile, argv[1], root, fsoptions.onlyspec);
TIMER_RESULTS(start, "apply_specfile");
}
errno = 0;
d = (u_int)strtoul(str, &ep, 0);
if (str != ep && !*ep && errno == 0)
return d;
d = 0;
for (char *a = strtok(str, ","); a != NULL; a = strtok(NULL, ",")) {
for (i = 0; i < __arraycount(nv); i++)
if (strcmp(nv[i].n, a) == 0) {
d |= nv[i].v;
break;
}
if (i == __arraycount(nv))
errx(EXIT_FAILURE, "Unknown debug option `%s'", a);
}
return d;
}