NetBSD/usr.sbin/mtree/mtree.c

333 lines
7.5 KiB
C
Raw Normal View History

/* $NetBSD: mtree.c,v 1.49 2014/04/24 17:22:41 christos Exp $ */
1995-03-08 00:12:04 +03:00
1993-03-21 12:45:37 +03:00
/*-
1995-03-07 18:28:32 +03:00
* Copyright (c) 1989, 1990, 1993
* The Regents of the University of California. All rights reserved.
1993-03-21 12:45:37 +03:00
*
* 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. Neither the name of the University nor the names of its contributors
1993-03-21 12:45:37 +03:00
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 THE REGENTS OR CONTRIBUTORS 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.
*/
#if HAVE_NBTOOL_CONFIG_H
#include "nbtool_config.h"
#endif
1997-10-17 15:46:30 +04:00
#include <sys/cdefs.h>
#if defined(__COPYRIGHT) && !defined(lint)
__COPYRIGHT("@(#) Copyright (c) 1989, 1990, 1993\
The Regents of the University of California. All rights reserved.");
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#if defined(__RCSID) && !defined(lint)
1995-03-08 00:12:04 +03:00
#if 0
1995-03-07 18:28:32 +03:00
static char sccsid[] = "@(#)mtree.c 8.1 (Berkeley) 6/6/93";
1995-03-08 00:12:04 +03:00
#else
__RCSID("$NetBSD: mtree.c,v 1.49 2014/04/24 17:22:41 christos Exp $");
1995-03-08 00:12:04 +03:00
#endif
1993-03-21 12:45:37 +03:00
#endif /* not lint */
#include <sys/param.h>
#include <sys/stat.h>
1993-03-21 12:45:37 +03:00
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "extern.h"
1993-03-21 12:45:37 +03:00
int ftsoptions = FTS_PHYSICAL;
int bflag, dflag, eflag, iflag, jflag, lflag, mflag, nflag, qflag, rflag,
sflag, tflag, uflag;
char fullpath[MAXPATHLEN];
static struct {
enum flavor flavor;
const char name[9];
} flavors[] = {
{F_MTREE, "mtree"},
{F_FREEBSD9, "freebsd9"},
{F_NETBSD6, "netbsd6"},
};
2011-08-30 00:37:43 +04:00
__dead static void usage(void);
int
main(int argc, char **argv)
1993-03-21 12:45:37 +03:00
{
int ch, status;
2012-12-20 22:58:37 +04:00
unsigned int i;
int cflag, Cflag, Dflag, Uflag, wflag;
char *dir, *p;
FILE *spec1, *spec2;
1993-03-21 12:45:37 +03:00
2001-03-22 02:56:35 +03:00
setprogname(argv[0]);
cflag = Cflag = Dflag = Uflag = wflag = 0;
dir = NULL;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
init_excludes();
spec1 = stdin;
spec2 = NULL;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
while ((ch = getopt(argc, argv,
"bcCdDeE:f:F:I:ijk:K:lLmMnN:O:p:PqrR:s:StuUwWxX:"))
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
!= -1) {
1993-03-21 12:45:37 +03:00
switch((char)ch) {
case 'b':
bflag = 1;
break;
1993-03-21 12:45:37 +03:00
case 'c':
cflag = 1;
break;
case 'C':
Cflag = 1;
break;
1993-03-21 12:45:37 +03:00
case 'd':
dflag = 1;
break;
case 'D':
Dflag = 1;
break;
case 'E':
parsetags(&excludetags, optarg);
break;
1993-03-21 12:45:37 +03:00
case 'e':
eflag = 1;
break;
case 'f':
if (spec1 == stdin) {
spec1 = fopen(optarg, "r");
if (spec1 == NULL)
mtree_err("%s: %s", optarg,
strerror(errno));
} else if (spec2 == NULL) {
spec2 = fopen(optarg, "r");
if (spec2 == NULL)
mtree_err("%s: %s", optarg,
strerror(errno));
} else
usage();
break;
case 'F':
for (i = 0; i < __arraycount(flavors); i++)
if (strcmp(optarg, flavors[i].name) == 0) {
flavor = flavors[i].flavor;
break;
}
if (i == __arraycount(flavors))
usage();
break;
case 'i':
iflag = 1;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'I':
parsetags(&includetags, optarg);
break;
case 'j':
jflag = 1;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'k':
keys = F_TYPE;
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'K':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys |= parsekey(p, NULL);
1993-03-21 12:45:37 +03:00
break;
case 'l':
lflag = 1;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'L':
ftsoptions &= ~FTS_PHYSICAL;
ftsoptions |= FTS_LOGICAL;
break;
case 'm':
mflag = 1;
break;
case 'M':
mtree_Mflag = 1;
break;
case 'n':
nflag = 1;
break;
case 'N':
if (! setup_getid(optarg))
mtree_err(
"Unable to use user and group databases in `%s'",
optarg);
break;
case 'O':
load_only(optarg);
break;
1993-03-21 12:45:37 +03:00
case 'p':
dir = optarg;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'P':
ftsoptions &= ~FTS_LOGICAL;
ftsoptions |= FTS_PHYSICAL;
break;
case 'q':
qflag = 1;
break;
1993-03-21 12:45:37 +03:00
case 'r':
rflag = 1;
break;
case 'R':
while ((p = strsep(&optarg, " \t,")) != NULL)
if (*p != '\0')
keys &= ~parsekey(p, NULL);
break;
case 's':
sflag = 1;
crc_total = ~strtol(optarg, &p, 0);
if (*p)
mtree_err("illegal seed value -- %s", optarg);
break;
case 'S':
mtree_Sflag = 1;
break;
case 't':
tflag = 1;
break;
1993-03-21 12:45:37 +03:00
case 'u':
uflag = 1;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'U':
Uflag = uflag = 1;
break;
case 'w':
wflag = 1;
break;
case 'W':
mtree_Wflag = 1;
break;
1993-03-21 12:45:37 +03:00
case 'x':
ftsoptions |= FTS_XDEV;
break;
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
case 'X':
read_excludes_file(optarg);
break;
1993-03-21 12:45:37 +03:00
case '?':
default:
usage();
}
User interface changes from (or inspired by) FreeBSD: - Add -L to walk the tree `logically', by following symbolic links in the heirarchy. - Add -P to walk the tree `physically'. This is the current behaviour, and the default. - Add "-X excludes-file" to give mtree the ability to exclude files and directories from its traversal. excludes-file contains fnmatch(3) patterns to exclude from the walk. - Add "md5digest" synonym for "md5". - Add "rmd160" keyword for RMD-160 message digest, and "rmd160digest" synonym. - Add "sha1" keyword for SHA-1 message digest, and "sha1digest" synonym. - Don't try to compare() other attributes if the type doesn't match; it's nothing but trouble, and no use anyway. - In -c, only emit "/set" records if something has changed since the previous one. User interface changes by me: - Check a device's parameters before checking uid/gid/mode. - If updating (-u), modify the following to match the specification: - Device type (retaining existing ownership). - Symlink target. Fixes from (or inspired by) FreeBSD: - Use p->ftslevel instead of own code to keep track of the level ourself. The previous code got majorly confused if fts(3) couldn't descend into a subdir, resulting in leaf nodes getting attached to the wrong directory. XXX: This new method is much much more robust, even though it's not 100% perfect; it might result in a couple of following entries in the spec to be incorrectly tagged as missing. - Pass a useful pathname to rlink(), so that logical (-L) traversal doesn't confuse symlink checking. - Consistently use MAXPATHLEN+1 sized buffers for pathnames, so that there's room for the NUL. - Use mtree_err() and strerror(p->fts_errno) to report errors during the fts(3) walk. Fixes by me: - Remove now-unused `const char *name' argument from compare(). - Change crc_total from an int to a u_int32_t, to match usr.bin/cksum/crc.c. - Remove trailing whitespace. - Remove unnecessary (void) casts on functions. - Reorder entries in the getopt() switch. - Replace strtoq() with strtoll(), and use strtoul() appropriately. - Renumber F_ flags to be in alphabetical order.
2001-11-07 11:01:51 +03:00
}
1993-03-21 12:45:37 +03:00
argc -= optind;
argv += optind;
1993-03-21 12:45:37 +03:00
if (argc)
usage();
switch (flavor) {
case F_FREEBSD9:
if (cflag && iflag) {
warnx("-c and -i passed, replacing -i with -j for "
"FreeBSD compatibility");
iflag = 0;
jflag = 1;
}
if (dflag && !bflag) {
warnx("Adding -b to -d for FreeBSD compatibility");
bflag = 1;
}
if (uflag && !iflag) {
warnx("Adding -i to -%c for FreeBSD compatibility",
Uflag ? 'U' : 'u');
iflag = 1;
}
if (uflag && !tflag) {
warnx("Adding -t to -%c for FreeBSD compatibility",
Uflag ? 'U' : 'u');
tflag = 1;
}
if (wflag)
warnx("The -w flag is a no-op");
break;
default:
if (wflag)
usage();
}
if (spec2 && (cflag || Cflag || Dflag))
mtree_err("Double -f, -c, -C and -D flags are mutually "
"exclusive");
if (dir && spec2)
mtree_err("Double -f and -p flags are mutually exclusive");
if (dir && chdir(dir))
mtree_err("%s: %s", dir, strerror(errno));
1993-03-21 12:45:37 +03:00
if ((cflag || sflag) && !getcwd(fullpath, sizeof(fullpath)))
mtree_err("%s", strerror(errno));
1993-03-21 12:45:37 +03:00
if ((cflag && Cflag) || (cflag && Dflag) || (Cflag && Dflag))
mtree_err("-c, -C and -D flags are mutually exclusive");
if (iflag && mflag)
mtree_err("-i and -m flags are mutually exclusive");
if (lflag && uflag)
mtree_err("-l and -u flags are mutually exclusive");
if (cflag) {
cwalk(stdout);
exit(0);
}
if (Cflag || Dflag) {
dump_nodes(stdout, "", spec(spec1), Dflag);
exit(0);
}
if (spec2 != NULL)
status = mtree_specspec(spec1, spec2);
else
status = verify(spec1);
if (Uflag && (status == MISMATCHEXIT))
status = 0;
exit(status);
1993-03-21 12:45:37 +03:00
}
static void
usage(void)
1993-03-21 12:45:37 +03:00
{
2012-12-20 22:58:37 +04:00
unsigned int i;
fprintf(stderr,
"usage: %s [-bCcDdejLlMnPqrStUuWx] [-i|-m] [-E tags]\n"
"\t\t[-f spec] [-f spec]\n"
2009-04-08 23:43:05 +04:00
"\t\t[-I tags] [-K keywords] [-k keywords] [-N dbdir] [-p path]\n"
"\t\t[-R keywords] [-s seed] [-X exclude-file]\n"
"\t\t[-F flavor]\n",
getprogname());
fprintf(stderr, "\nflavors:");
for (i = 0; i < __arraycount(flavors); i++)
fprintf(stderr, " %s", flavors[i].name);
fprintf(stderr, "\n");
1993-03-21 12:45:37 +03:00
exit(1);
}