[Midnightbsd-cvs] src [10801] trunk/contrib/mtree: update mtree

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Sat Jun 9 23:12:52 EDT 2018


Revision: 10801
          http://svnweb.midnightbsd.org/src/?rev=10801
Author:   laffer1
Date:     2018-06-09 23:12:51 -0400 (Sat, 09 Jun 2018)
Log Message:
-----------
update mtree

Modified Paths:
--------------
    trunk/contrib/mtree/Makefile
    trunk/contrib/mtree/compare.c
    trunk/contrib/mtree/crc.c
    trunk/contrib/mtree/create.c
    trunk/contrib/mtree/excludes.c
    trunk/contrib/mtree/extern.h
    trunk/contrib/mtree/getid.c
    trunk/contrib/mtree/misc.c
    trunk/contrib/mtree/mtree.8
    trunk/contrib/mtree/mtree.c
    trunk/contrib/mtree/mtree.h
    trunk/contrib/mtree/spec.c
    trunk/contrib/mtree/specspec.c
    trunk/contrib/mtree/verify.c

Added Paths:
-----------
    trunk/contrib/mtree/only.c

Modified: trunk/contrib/mtree/Makefile
===================================================================
--- trunk/contrib/mtree/Makefile	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/Makefile	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-#	$NetBSD: Makefile,v 1.33 2012/10/05 01:26:56 christos Exp $
+# $MidnightBSD$
+#	$NetBSD: Makefile,v 1.34 2013/02/03 19:15:16 christos Exp $
 #	from: @(#)Makefile	8.2 (Berkeley) 4/27/95
 
 .include <bsd.own.mk>
@@ -8,7 +9,7 @@
 CPPFLAGS+= -DMTREE
 MAN=	mtree.8
 SRCS=	compare.c crc.c create.c excludes.c misc.c mtree.c spec.c specspec.c \
-	verify.c getid.c pack_dev.c
+	verify.c getid.c pack_dev.c only.c
 .if (${HOSTPROG:U} == "")
 DPADD+= ${LIBUTIL}
 LDADD+= -lutil

Modified: trunk/contrib/mtree/compare.c
===================================================================
--- trunk/contrib/mtree/compare.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/compare.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: compare.c,v 1.55 2012/10/05 00:59:35 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: compare.c,v 1.58 2013/11/21 18:39:50 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)compare.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: compare.c,v 1.55 2012/10/05 00:59:35 christos Exp $");
+__RCSID("$NetBSD: compare.c,v 1.58 2013/11/21 18:39:50 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -48,6 +49,7 @@
 #include <errno.h>
 #include <fcntl.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -71,13 +73,18 @@
 #define	INDENTNAMELEN	8
 #define MARK								\
 do {									\
-	len = printf("%s: ", RP(p));					\
-	if (len > INDENTNAMELEN) {					\
+	if (flavor == F_FREEBSD9) {					\
+		len = printf("%s changed\n", RP(p));			\
 		tab = "\t";						\
-		printf("\n");						\
 	} else {							\
-		tab = "";						\
-		printf("%*s", INDENTNAMELEN - (int)len, "");		\
+		len = printf("%s: ", RP(p));				\
+		if (len > INDENTNAMELEN) {				\
+			tab = "\t";					\
+			printf("\n");					\
+		} else {						\
+			tab = "";					\
+			printf("%*s", INDENTNAMELEN - (int)len, "");	\
+		}							\
 	}								\
 } while (0)
 #define	LABEL if (!label++) MARK
@@ -170,7 +177,8 @@
 		break;
 #endif
 typeerr:		LABEL;
-		printf("\ttype (%s, %s)\n",
+		printf(flavor == F_FREEBSD9 ?
+		    "\ttype expected %s found %s\n" : "\ttype (%s, %s)\n",
 		    nodetype(s->type), inotype(p->fts_statp->st_mode));
 		return (label);
 	}
@@ -192,9 +200,11 @@
 	    (s->type == F_BLOCK || s->type == F_CHAR) &&
 	    s->st_rdev != p->fts_statp->st_rdev) {
 		LABEL;
-		printf("%sdevice (%#llx, %#llx",
-		    tab, (long long)s->st_rdev,
-		    (long long)p->fts_statp->st_rdev);
+		printf(flavor == F_FREEBSD9 ?
+		    "%sdevice expected %#jx found %#jx" :
+		    "%sdevice (%#jx, %#jx",
+		    tab, (uintmax_t)s->st_rdev,
+		    (uintmax_t)p->fts_statp->st_rdev);
 		if (uflag) {
 			if ((unlink(p->fts_accpath) == -1) ||
 			    (mknod(p->fts_accpath,
@@ -202,10 +212,12 @@
 			      s->st_rdev) == -1) ||
 			    (lchown(p->fts_accpath, p->fts_statp->st_uid,
 			      p->fts_statp->st_gid) == -1) )
-				printf(", not modified: %s)\n",
-				    strerror(errno));
+				printf(", not modified: %s%s\n",
+				    strerror(errno),
+				    flavor == F_FREEBSD9 ? "" : ")");
 			 else
-				printf(", modified)\n");
+				printf(", modified%s\n",
+				    flavor == F_FREEBSD9 ? "" : ")");
 		} else
 			printf(")\n");
 		tab = "\t";
@@ -213,14 +225,17 @@
 	/* Set the uid/gid first, then set the mode. */
 	if (s->flags & (F_UID | F_UNAME) && s->st_uid != p->fts_statp->st_uid) {
 		LABEL;
-		printf("%suser (%lu, %lu",
+		printf(flavor == F_FREEBSD9 ?
+		    "%suser expected %lu found %lu" : "%suser (%lu, %lu",
 		    tab, (u_long)s->st_uid, (u_long)p->fts_statp->st_uid);
 		if (uflag) {
 			if (lchown(p->fts_accpath, s->st_uid, -1))
-				printf(", not modified: %s)\n",
-				    strerror(errno));
+				printf(", not modified: %s%s\n",
+				    strerror(errno),
+				    flavor == F_FREEBSD9 ? "" : ")");
 			else
-				printf(", modified)\n");
+				printf(", modified%s\n",
+				    flavor == F_FREEBSD9 ? "" : ")");
 		} else
 			printf(")\n");
 		tab = "\t";
@@ -227,14 +242,17 @@
 	}
 	if (s->flags & (F_GID | F_GNAME) && s->st_gid != p->fts_statp->st_gid) {
 		LABEL;
-		printf("%sgid (%lu, %lu",
+		printf(flavor == F_FREEBSD9 ?
+		    "%sgid expected %lu found %lu" : "%sgid (%lu, %lu",
 		    tab, (u_long)s->st_gid, (u_long)p->fts_statp->st_gid);
 		if (uflag) {
 			if (lchown(p->fts_accpath, -1, s->st_gid))
-				printf(", not modified: %s)\n",
-				    strerror(errno));
+				printf(", not modified: %s%s\n",
+				    strerror(errno),
+				    flavor == F_FREEBSD9 ? "" : ")");
 			else
-				printf(", modified)\n");
+				printf(", modified%s\n",
+				    flavor == F_FREEBSD9 ? "" : ")");
 		}
 		else
 			printf(")\n");
@@ -259,15 +277,19 @@
 		}
 
 		LABEL;
-		printf("%spermissions (%#lo, %#lo",
+		printf(flavor == F_FREEBSD9 ?
+		    "%spermissions expcted %#lo found %#lo" :
+		    "%spermissions (%#lo, %#lo",
 		    tab, (u_long)s->st_mode,
 		    (u_long)p->fts_statp->st_mode & MBITS);
 		if (uflag) {
 			if (lchmod(p->fts_accpath, s->st_mode))
-				printf(", not modified: %s)\n",
-				    strerror(errno));
+				printf(", not modified: %s%s\n",
+				    strerror(errno),
+				    flavor == F_FREEBSD9 ? "" : ")");
 			else
-				printf(", modified)\n");
+				printf(", modified%s\n",
+				    flavor == F_FREEBSD9 ? "" : ")");
 		}
 		else
 			printf(")\n");
@@ -277,15 +299,18 @@
 	if (s->flags & F_NLINK && s->type != F_DIR &&
 	    s->st_nlink != p->fts_statp->st_nlink) {
 		LABEL;
-		printf("%slink count (%lu, %lu)\n",
+		printf(flavor == F_FREEBSD9 ?
+		    "%slink count expected %lu found %lu\n" :
+		    "%slink count (%lu, %lu)\n",
 		    tab, (u_long)s->st_nlink, (u_long)p->fts_statp->st_nlink);
 		tab = "\t";
 	}
 	if (s->flags & F_SIZE && s->st_size != p->fts_statp->st_size) {
 		LABEL;
-		printf("%ssize (%lld, %lld)\n",
-		    tab, (long long)s->st_size,
-		    (long long)p->fts_statp->st_size);
+		printf(flavor == F_FREEBSD9 ?
+		    "%ssize expected %ju found %ju\n" : "%ssize (%ju, %ju)\n",
+		    tab, (uintmax_t)s->st_size,
+		    (uintmax_t)p->fts_statp->st_size);
 		tab = "\t";
 	}
 	/*
@@ -318,18 +343,22 @@
 		if (tv[0].tv_sec != tv[1].tv_sec ||
 		    tv[0].tv_usec != tv[1].tv_usec) {
 			LABEL;
-			printf("%smodification time (%.24s, ",
+			printf(flavor == F_FREEBSD9 ?
+			    "%smodification time expected %.24s found " :
+			    "%smodification time (%.24s, ",
 			    tab, ctime(&smtime));
 			printf("%.24s", ctime(&pmtime));
 			if (tflag) {
 				tv[1] = tv[0];
 				if (utimes(p->fts_accpath, tv))
-					printf(", not modified: %s)\n",
-					    strerror(errno));
+					printf(", not modified: %s%s\n",
+					    strerror(errno),
+					    flavor == F_FREEBSD9 ? "" : ")");
 				else
-					printf(", modified)\n");
+					printf(", modified%s\n",
+					    flavor == F_FREEBSD9 ? "" : ")");
 			} else
-				printf(")\n");
+				printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
 			tab = "\t";
 		}
 	}
@@ -346,7 +375,9 @@
 			char *f_s;
 			LABEL;
 			f_s = flags_to_string(s->st_flags, "none");
-			printf("%sflags (\"%s\" is not ", tab, f_s);
+			printf(flavor == F_FREEBSD9 ?
+			    "%sflags expected \"%s\" found " :
+			    "%sflags (\"%s\" is not ", tab, f_s);
 			free(f_s);
 			f_s = flags_to_string(p->fts_statp->st_flags, "none");
 			printf("\"%s\"", f_s);
@@ -360,7 +391,7 @@
 			else
 				SETFLAGS(0, (~SP_FLGS & CH_MASK));
 		} else
-			printf(")\n");
+			printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
 		tab = "\t";
 	}
 #endif	/* HAVE_STRUCT_STAT_ST_FLAGS */
@@ -386,7 +417,9 @@
 			close(fd);
 			if (s->cksum != val) {
 				LABEL;
-				printf("%scksum (%lu, %lu)\n",
+				printf(flavor == F_FREEBSD9 ?
+				    "%scksum expected %lu found %lu\n" :
+				    "%scksum (%lu, %lu)\n",
 				    tab, s->cksum, (unsigned long)val);
 			}
 			tab = "\t";
@@ -402,7 +435,9 @@
 		} else {
 			if (strcmp(s->md5digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ?
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, MD5KEY, s->md5digest, digestbuf);
 			}
 			tab = "\t";
@@ -420,7 +455,9 @@
 		} else {
 			if (strcmp(s->rmd160digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ?
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, RMD160KEY, s->rmd160digest, digestbuf);
 			}
 			tab = "\t";
@@ -438,7 +475,9 @@
 		} else {
 			if (strcmp(s->sha1digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ? 
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, SHA1KEY, s->sha1digest, digestbuf);
 			}
 			tab = "\t";
@@ -456,7 +495,9 @@
 		} else {
 			if (strcmp(s->sha256digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ? 
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, SHA256KEY, s->sha256digest, digestbuf);
 			}
 			tab = "\t";
@@ -473,7 +514,9 @@
 		} else {
 			if (strcmp(s->sha384digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ? 
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, SHA384KEY, s->sha384digest, digestbuf);
 			}
 			tab = "\t";
@@ -490,7 +533,9 @@
 		} else {
 			if (strcmp(s->sha512digest, digestbuf)) {
 				LABEL;
-				printf("%s%s (0x%s, 0x%s)\n",
+				printf(flavor == F_FREEBSD9 ? 
+				    "%s%s expected %s found %s\n" :
+				    "%s%s (0x%s, 0x%s)\n",
 				    tab, SHA512KEY, s->sha512digest, digestbuf);
 			}
 			tab = "\t";
@@ -501,16 +546,20 @@
 	if (s->flags & F_SLINK &&
 	    strcmp(cp = rlink(p->fts_accpath), s->slink)) {
 		LABEL;
-		printf("%slink ref (%s, %s", tab, cp, s->slink);
+		printf(flavor == F_FREEBSD9 ? 
+		    "%slink ref expected %s found %s" :
+		    "%slink ref (%s, %s", tab, cp, s->slink);
 		if (uflag) {
 			if ((unlink(p->fts_accpath) == -1) ||
 			    (symlink(s->slink, p->fts_accpath) == -1) )
-				printf(", not modified: %s)\n",
-				    strerror(errno));
+				printf(", not modified: %s%s\n",
+				    strerror(errno),
+				    flavor == F_FREEBSD9 ? "" : ")");
 			else
-				printf(", modified)\n");
+				printf(", modified%s\n",
+				    flavor == F_FREEBSD9 ? "" : ")");
 		} else
-			printf(")\n");
+			printf("%s\n", flavor == F_FREEBSD9 ? "" : ")");
 	}
 	return (label);
 }

Modified: trunk/contrib/mtree/crc.c
===================================================================
--- trunk/contrib/mtree/crc.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/crc.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: crc.c,v 1.9 2012/10/05 00:40:51 christos Exp $	*/
 
 /*-

Modified: trunk/contrib/mtree/create.c
===================================================================
--- trunk/contrib/mtree/create.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/create.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: create.c,v 1.68 2012/12/20 16:43:16 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: create.c,v 1.73 2014/04/24 17:22:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -38,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)create.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: create.c,v 1.68 2012/12/20 16:43:16 christos Exp $");
+__RCSID("$NetBSD: create.c,v 1.73 2014/04/24 17:22:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -55,6 +56,7 @@
 #include <pwd.h>
 #include <stdio.h>
 #include <stdarg.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <time.h>
@@ -90,13 +92,14 @@
 #endif
 
 static int	dcmp(const FTSENT *FTS_CONST *, const FTSENT *FTS_CONST *);
-static void	output(int, int *, const char *, ...)
-	__attribute__((__format__(__printf__, 3, 4)));
-static int	statd(FTS *, FTSENT *, uid_t *, gid_t *, mode_t *, u_long *);
-static void	statf(int, FTSENT *);
+static void	output(FILE *, int, int *, const char *, ...)
+    __printflike(4, 5);
+static int	statd(FILE *, FTS *, FTSENT *, uid_t *, gid_t *, mode_t *,
+    u_long *);
+static void	statf(FILE *, int, FTSENT *);
 
 void
-cwalk(void)
+cwalk(FILE *fp)
 {
 	FTS *t;
 	FTSENT *p;
@@ -120,7 +123,7 @@
 	}
 
 	if (!nflag)
-		printf(
+		fprintf(fp,
 	    	    "#\t   user: %s\n#\tmachine: %s\n#\t   tree: %s\n"
 		    "#\t   date: %s",
 		    user, host, fullpath, ctime(&clocktime));
@@ -134,24 +137,28 @@
 			fts_set(t, p, FTS_SKIP);
 			continue;
 		}
+		if (!find_only(p->fts_path)) {
+			fts_set(t, p, FTS_SKIP);
+			continue;
+		}
 		switch(p->fts_info) {
 		case FTS_D:
 			if (!bflag)
-				printf("\n");
+				fprintf(fp, "\n");
 			if (!nflag)
-				printf("# %s\n", p->fts_path);
-			statd(t, p, &uid, &gid, &mode, &flags);
-			statf(indent, p);
+				fprintf(fp, "# %s\n", p->fts_path);
+			statd(fp, t, p, &uid, &gid, &mode, &flags);
+			statf(fp, indent, p);
 			break;
 		case FTS_DP:
 			if (p->fts_level > 0)
 				if (!nflag)
-					printf("%*s# %s\n", indent, "",
+					fprintf(fp, "%*s# %s\n", indent, "",
 					    p->fts_path);
 			if (p->fts_level > 0 || flavor == F_FREEBSD9) {
-				printf("%*s..\n", indent, "");
+				fprintf(fp, "%*s..\n", indent, "");
 				if (!bflag)
-					printf("\n");
+					fprintf(fp, "\n");
 			}
 			break;
 		case FTS_DNR:
@@ -162,7 +169,7 @@
 			break;
 		default:
 			if (!dflag)
-				statf(indent, p);
+				statf(fp, indent, p);
 			break;
 
 		}
@@ -173,7 +180,7 @@
 }
 
 static void
-statf(int indent, FTSENT *p)
+statf(FILE *fp, int indent, FTSENT *p)
 {
 	u_int32_t len, val;
 	int fd, offset;
@@ -182,52 +189,55 @@
 	char *digestbuf;
 #endif
 
-	offset = printf("%*s%s%s", indent, "",
+	offset = fprintf(fp, "%*s%s%s", indent, "",
 	    S_ISDIR(p->fts_statp->st_mode) ? "" : "    ", vispath(p->fts_name));
 
 	if (offset > (INDENTNAMELEN + indent))
 		offset = MAXLINELEN;
 	else
-		offset += printf("%*s", (INDENTNAMELEN + indent) - offset, "");
+		offset += fprintf(fp, "%*s",
+		    (INDENTNAMELEN + indent) - offset, "");
 
 	if (!S_ISREG(p->fts_statp->st_mode) && (flavor == F_NETBSD6 || !dflag))
-		output(indent, &offset, "type=%s",
+		output(fp, indent, &offset, "type=%s",
 		    inotype(p->fts_statp->st_mode));
 	if (keys & (F_UID | F_UNAME) && p->fts_statp->st_uid != uid) {
 		if (keys & F_UNAME &&
 		    (name = user_from_uid(p->fts_statp->st_uid, 1)) != NULL)
-			output(indent, &offset, "uname=%s", name);
+			output(fp, indent, &offset, "uname=%s", name);
 		if (keys & F_UID || (keys & F_UNAME && name == NULL))
-			output(indent, &offset, "uid=%u", p->fts_statp->st_uid);
+			output(fp, indent, &offset, "uid=%u",
+			    p->fts_statp->st_uid);
 	}
 	if (keys & (F_GID | F_GNAME) && p->fts_statp->st_gid != gid) {
 		if (keys & F_GNAME &&
 		    (name = group_from_gid(p->fts_statp->st_gid, 1)) != NULL)
-			output(indent, &offset, "gname=%s", name);
+			output(fp, indent, &offset, "gname=%s", name);
 		if (keys & F_GID || (keys & F_GNAME && name == NULL))
-			output(indent, &offset, "gid=%u", p->fts_statp->st_gid);
+			output(fp, indent, &offset, "gid=%u",
+			    p->fts_statp->st_gid);
 	}
 	if (keys & F_MODE && (p->fts_statp->st_mode & MBITS) != mode)
-		output(indent, &offset, "mode=%#o",
+		output(fp, indent, &offset, "mode=%#o",
 		    p->fts_statp->st_mode & MBITS);
 	if (keys & F_DEV &&
 	    (S_ISBLK(p->fts_statp->st_mode) || S_ISCHR(p->fts_statp->st_mode)))
-		output(indent, &offset, "device=%#llx",
-		    (long long)p->fts_statp->st_rdev);
+		output(fp, indent, &offset, "device=%#jx",
+		    (uintmax_t)p->fts_statp->st_rdev);
 	if (keys & F_NLINK && p->fts_statp->st_nlink != 1)
-		output(indent, &offset, "nlink=%u", p->fts_statp->st_nlink);
+		output(fp, indent, &offset, "nlink=%u", p->fts_statp->st_nlink);
 	if (keys & F_SIZE &&
-	    (flavor != F_NETBSD6 || S_ISREG(p->fts_statp->st_mode)))
-		output(indent, &offset, "size=%lld",
-		    (long long)p->fts_statp->st_size);
+	    (flavor == F_FREEBSD9 || S_ISREG(p->fts_statp->st_mode)))
+		output(fp, indent, &offset, "size=%ju",
+		    (uintmax_t)p->fts_statp->st_size);
 	if (keys & F_TIME)
 #if defined(BSD4_4) && !defined(HAVE_NBTOOL_CONFIG_H)
-		output(indent, &offset, "time=%ld.%09ld",
-		    (long)p->fts_statp->st_mtimespec.tv_sec,
+		output(fp, indent, &offset, "time=%jd.%09ld",
+		    (intmax_t)p->fts_statp->st_mtimespec.tv_sec,
 		    p->fts_statp->st_mtimespec.tv_nsec);
 #else
-		output(indent, &offset, "time=%ld.%09ld",
-		    (long)p->fts_statp->st_mtime, (long)0);
+		output(fp, indent, &offset, "time=%jd.%09ld",
+		    (intmax_t)p->fts_statp->st_mtime, (long)0);
 #endif
 	if (keys & F_CKSUM && S_ISREG(p->fts_statp->st_mode)) {
 		if ((fd = open(p->fts_accpath, O_RDONLY, 0)) < 0 ||
@@ -234,7 +244,7 @@
 		    crc(fd, &val, &len))
 			mtree_err("%s: %s", p->fts_accpath, strerror(errno));
 		close(fd);
-		output(indent, &offset, "cksum=%lu", (long)val);
+		output(fp, indent, &offset, "cksum=%lu", (long)val);
 	}
 #ifndef NO_MD5
 	if (keys & F_MD5 && S_ISREG(p->fts_statp->st_mode)) {
@@ -241,7 +251,7 @@
 		if ((digestbuf = MD5File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: MD5File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", MD5KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", MD5KEY, digestbuf);
 		free(digestbuf);
 	}
 #endif	/* ! NO_MD5 */
@@ -250,7 +260,7 @@
 		if ((digestbuf = RMD160File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: RMD160File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", RMD160KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", RMD160KEY, digestbuf);
 		free(digestbuf);
 	}
 #endif	/* ! NO_RMD160 */
@@ -259,7 +269,7 @@
 		if ((digestbuf = SHA1File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: SHA1File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", SHA1KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", SHA1KEY, digestbuf);
 		free(digestbuf);
 	}
 #endif	/* ! NO_SHA1 */
@@ -268,7 +278,7 @@
 		if ((digestbuf = SHA256_File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: SHA256_File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", SHA256KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", SHA256KEY, digestbuf);
 		free(digestbuf);
 	}
 #ifdef SHA384_BLOCK_LENGTH
@@ -276,7 +286,7 @@
 		if ((digestbuf = SHA384_File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: SHA384_File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", SHA384KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", SHA384KEY, digestbuf);
 		free(digestbuf);
 	}
 #endif
@@ -284,18 +294,18 @@
 		if ((digestbuf = SHA512_File(p->fts_accpath, NULL)) == NULL)
 			mtree_err("%s: SHA512_File failed: %s", p->fts_accpath,
 			    strerror(errno));
-		output(indent, &offset, "%s=%s", SHA512KEY, digestbuf);
+		output(fp, indent, &offset, "%s=%s", SHA512KEY, digestbuf);
 		free(digestbuf);
 	}
 #endif	/* ! NO_SHA2 */
 	if (keys & F_SLINK &&
 	    (p->fts_info == FTS_SL || p->fts_info == FTS_SLNONE))
-		output(indent, &offset, "link=%s",
+		output(fp, indent, &offset, "link=%s",
 		    vispath(rlink(p->fts_accpath)));
 #if HAVE_STRUCT_STAT_ST_FLAGS
 	if (keys & F_FLAGS && p->fts_statp->st_flags != flags) {
 		char *str = flags_to_string(p->fts_statp->st_flags, "none");
-		output(indent, &offset, "flags=%s", str);
+		output(fp, indent, &offset, "flags=%s", str);
 		free(str);
 	}
 #endif
@@ -319,8 +329,8 @@
 #define	MTREE_MAXS 16
 
 static int
-statd(FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode,
-      u_long *pflags)
+statd(FILE *fp, FTS *t, FTSENT *parent, uid_t *puid, gid_t *pgid, mode_t *pmode,
+    u_long *pflags)
 {
 	FTSENT *p;
 	gid_t sgid;
@@ -393,33 +403,33 @@
 	    first) {
 		first = 0;
 		if (flavor != F_NETBSD6 && dflag)
-			printf("/set type=dir");
+			fprintf(fp, "/set type=dir");
 		else
-			printf("/set type=file");
+			fprintf(fp, "/set type=file");
 		if (keys & (F_UID | F_UNAME)) {
 			if (keys & F_UNAME &&
 			    (name = user_from_uid(saveuid, 1)) != NULL)
-				printf(" uname=%s", name);
+				fprintf(fp, " uname=%s", name);
 			if (keys & F_UID || (keys & F_UNAME && name == NULL))
-				printf(" uid=%lu", (u_long)saveuid);
+				fprintf(fp, " uid=%lu", (u_long)saveuid);
 		}
 		if (keys & (F_GID | F_GNAME)) {
 			if (keys & F_GNAME &&
 			    (name = group_from_gid(savegid, 1)) != NULL)
-				printf(" gname=%s", name);
+				fprintf(fp, " gname=%s", name);
 			if (keys & F_GID || (keys & F_GNAME && name == NULL))
-				printf(" gid=%lu", (u_long)savegid);
+				fprintf(fp, " gid=%lu", (u_long)savegid);
 		}
 		if (keys & F_MODE)
-			printf(" mode=%#lo", (u_long)savemode);
+			fprintf(fp, " mode=%#lo", (u_long)savemode);
 		if (keys & F_NLINK)
-			printf(" nlink=1");
+			fprintf(fp, " nlink=1");
 		if (keys & F_FLAGS) {
 			char *str = flags_to_string(saveflags, "none");
-			printf(" flags=%s", str);
+			fprintf(fp, " flags=%s", str);
 			free(str);
 		}
-		printf("\n");
+		fprintf(fp, "\n");
 		*puid = saveuid;
 		*pgid = savegid;
 		*pmode = savemode;
@@ -450,7 +460,7 @@
 }
 
 void
-output(int indent, int *offset, const char *fmt, ...)
+output(FILE *fp, int indent, int *offset, const char *fmt, ...)
 {
 	va_list ap;
 	char buf[1024];
@@ -460,8 +470,8 @@
 	va_end(ap);
 
 	if (*offset + strlen(buf) > MAXLINELEN - 3) {
-		printf(" \\\n%*s", INDENTNAMELEN + indent, "");
+		fprintf(fp, " \\\n%*s", INDENTNAMELEN + indent, "");
 		*offset = INDENTNAMELEN + indent;
 	}
-	*offset += printf(" %s", buf) + 1;
+	*offset += fprintf(fp, " %s", buf) + 1;
 }

Modified: trunk/contrib/mtree/excludes.c
===================================================================
--- trunk/contrib/mtree/excludes.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/excludes.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: excludes.c,v 1.13 2004/06/20 22:20:18 jmc Exp $	*/
 
 /*

Modified: trunk/contrib/mtree/extern.h
===================================================================
--- trunk/contrib/mtree/extern.h	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/extern.h	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: extern.h,v 1.37 2012/12/20 16:43:16 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: extern.h,v 1.39 2014/04/24 17:22:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1991, 1993
@@ -42,6 +43,7 @@
 #include <err.h> 
 #include <fts.h>
 #include <util.h>
+#include <stdbool.h>
 
 #if HAVE_NETDB_H
 /* For MAXHOSTNAMELEN on some platforms. */
@@ -62,8 +64,8 @@
 int	 check_excludes(const char *, const char *);
 int	 compare(NODE *, FTSENT *);
 int	 crc(int, u_int32_t *, u_int32_t *);
-void	 cwalk(void);
-void	 dump_nodes(const char *, NODE *, int);
+void	 cwalk(FILE *);
+void	 dump_nodes(FILE *, const char *, NODE *, int);
 void	 init_excludes(void);
 int	 matchtags(NODE *);
 __dead __printflike(1,2) void	 mtree_err(const char *, ...);
@@ -74,6 +76,8 @@
 void	 read_excludes_file(const char *);
 const char *rlink(const char *);
 int	 verify(FILE *);
+void	 load_only(const char *fname);
+bool	 find_only(const char *path);
 
 extern int	bflag, dflag, eflag, iflag, jflag, lflag, mflag,
 		nflag, qflag, rflag, sflag, tflag, uflag;

Modified: trunk/contrib/mtree/getid.c
===================================================================
--- trunk/contrib/mtree/getid.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/getid.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: getid.c,v 1.7 2008/04/28 20:24:17 martin Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: getid.c,v 1.10 2014/10/27 21:46:45 christos Exp $	*/
 /*	from: NetBSD: getpwent.c,v 1.48 2000/10/03 03:22:26 enami Exp */
 /*	from: NetBSD: getgrent.c,v 1.41 2002/01/12 23:51:30 lukem Exp */
 
@@ -65,7 +66,7 @@
 #endif
 
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: getid.c,v 1.7 2008/04/28 20:24:17 martin Exp $");
+__RCSID("$NetBSD: getid.c,v 1.10 2014/10/27 21:46:45 christos Exp $");
 
 #include <sys/param.h>
 
@@ -206,7 +207,12 @@
 	}
 	if (grfile[0] == '\0')			/* sanity check */
 		return 0;
-	return (_gr_fp = fopen(grfile, "r")) ? 1 : 0;
+
+	_gr_fp = fopen(grfile, "r");
+	if (_gr_fp != NULL)
+		return 1;
+	warn("Can't open `%s'", grfile);
+	return 0;
 }
 
 
@@ -230,6 +236,9 @@
 				;
 			continue;
 		}
+		/* skip comments */
+		if (grline[0] == '#')
+			continue;
 		if (grmatchline(search, gid, name))
 			return 1;
 	}
@@ -347,7 +356,11 @@
 	}
 	if (pwfile[0] == '\0')			/* sanity check */
 		return 0;
-	return (_pw_fp = fopen(pwfile, "r")) ? 1 : 0;
+	_pw_fp = fopen(pwfile, "r");
+	if (_pw_fp != NULL)
+		return 1;
+	warn("Can't open `%s'", pwfile);
+	return 0;
 }
 
 
@@ -371,6 +384,9 @@
 				;
 			continue;
 		}
+		/* skip comments */
+		if (pwline[0] == '#')
+			continue;
 		if (pwmatchline(search, uid, name))
 			return 1;
 	}

Modified: trunk/contrib/mtree/misc.c
===================================================================
--- trunk/contrib/mtree/misc.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/misc.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: misc.c,v 1.34 2012/12/20 19:09:25 christos Exp $	*/
 
 /*-

Modified: trunk/contrib/mtree/mtree.8
===================================================================
--- trunk/contrib/mtree/mtree.8	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/mtree.8	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-.\"	$NetBSD: mtree.8,v 1.67 2012/12/20 20:31:01 wiz Exp $
+.\" $MidnightBSD$
+.\"	$NetBSD: mtree.8,v 1.69 2013/02/03 19:16:06 christos Exp $
 .\"
 .\" Copyright (c) 1989, 1990, 1993
 .\"	The Regents of the University of California.  All rights reserved.
@@ -56,7 +57,7 @@
 .\"
 .\"     @(#)mtree.8	8.2 (Berkeley) 12/11/93
 .\"
-.Dd December 20, 2012
+.Dd February 3, 2013
 .Dt MTREE 8
 .Os
 .Sh NAME
@@ -73,6 +74,7 @@
 .Op Fl K Ar keywords
 .Op Fl k Ar keywords
 .Op Fl N Ar dbdir
+.Op Fl O Ar onlyfile
 .Op Fl p Ar path
 .Op Fl R Ar keywords
 .Op Fl s Ar seed
@@ -273,6 +275,8 @@
 and
 .Xr getgrnam 3
 (and related) library calls.
+.It Fl O Ar onlypaths
+Only include files included in this list of pathnames.
 .It Fl P
 Don't follow symbolic links in the file hierarchy, instead consider
 the symbolic link itself in any comparisons.

Modified: trunk/contrib/mtree/mtree.c
===================================================================
--- trunk/contrib/mtree/mtree.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/mtree.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: mtree.c,v 1.46 2012/12/20 19:09:25 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: mtree.c,v 1.49 2014/04/24 17:22:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1990, 1993
@@ -43,7 +44,7 @@
 #if 0
 static char sccsid[] = "@(#)mtree.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: mtree.c,v 1.46 2012/12/20 19:09:25 christos Exp $");
+__RCSID("$NetBSD: mtree.c,v 1.49 2014/04/24 17:22:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -59,8 +60,8 @@
 #include "extern.h"
 
 int	ftsoptions = FTS_PHYSICAL;
-int	bflag, cflag, Cflag, dflag, Dflag, eflag, iflag, jflag, lflag, mflag,
-    	nflag, qflag, rflag, sflag, tflag, uflag, Uflag, wflag;
+int	bflag, dflag, eflag, iflag, jflag, lflag, mflag, nflag, qflag, rflag,
+	sflag, tflag, uflag;
 char	fullpath[MAXPATHLEN];
 
 static struct {
@@ -79,11 +80,13 @@
 {
 	int	ch, status;
 	unsigned int	i;
+	int	cflag, Cflag, Dflag, Uflag, wflag;
 	char	*dir, *p;
 	FILE	*spec1, *spec2;
 
 	setprogname(argv[0]);
 
+	cflag = Cflag = Dflag = Uflag = wflag = 0;
 	dir = NULL;
 	init_excludes();
 	spec1 = stdin;
@@ -90,7 +93,7 @@
 	spec2 = NULL;
 
 	while ((ch = getopt(argc, argv,
-	    "bcCdDeE:f:F:I:ijk:K:lLmMnN:p:PqrR:s:StuUwWxX:"))
+	    "bcCdDeE:f:F:I:ijk:K:lLmMnN:O:p:PqrR:s:StuUwWxX:"))
 	    != -1) {
 		switch((char)ch) {
 		case 'b':
@@ -179,6 +182,9 @@
 			    "Unable to use user and group databases in `%s'",
 				    optarg);
 			break;
+		case 'O':
+			load_only(optarg);
+			break;
 		case 'p':
 			dir = optarg;
 			break;
@@ -291,11 +297,11 @@
 		mtree_err("-l and -u flags are mutually exclusive");
 
 	if (cflag) {
-		cwalk();
+		cwalk(stdout);
 		exit(0);
 	}
 	if (Cflag || Dflag) {
-		dump_nodes("", spec(spec1), Dflag);
+		dump_nodes(stdout, "", spec(spec1), Dflag);
 		exit(0);
 	}
 	if (spec2 != NULL)

Modified: trunk/contrib/mtree/mtree.h
===================================================================
--- trunk/contrib/mtree/mtree.h	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/mtree.h	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: mtree.h,v 1.31 2012/10/05 09:17:29 wiz Exp $	*/
 
 /*-

Added: trunk/contrib/mtree/only.c
===================================================================
--- trunk/contrib/mtree/only.c	                        (rev 0)
+++ trunk/contrib/mtree/only.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -0,0 +1,153 @@
+/* $MidnightBSD$ */
+/*	$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $	*/
+
+/*-
+ * Copyright (c) 2013 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * 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 NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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
+
+#include <sys/cdefs.h>
+
+#if defined(__RCSID) && !defined(lint)
+__RCSID("$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $");
+#endif
+
+#include <sys/param.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stdbool.h>
+#include <time.h>
+#include <err.h>
+#include <util.h>
+
+#include "extern.h"
+
+struct hentry {
+	char *str;
+	uint32_t hash;
+	struct hentry *next;
+};
+
+static struct hentry *table[1024];
+static bool loaded;
+
+static uint32_t
+hash_str(const char *str)
+{
+	const uint8_t *s = (const uint8_t *)str;
+	uint8_t c;
+	uint32_t hash = 0;
+	while ((c = *s++) != '\0') 
+		hash = hash * 33 + c;           /* "perl": k=33, r=r+r/32 */
+	return hash + (hash >> 5);
+}
+
+static bool
+hash_find(const char *str, uint32_t *h)
+{
+	struct hentry *e;
+	*h = hash_str(str) % __arraycount(table);
+
+	for (e = table[*h]; e; e = e->next)
+		if (e->hash == *h && strcmp(e->str, str) == 0)
+			return true;
+	return false;
+}
+
+static void
+hash_insert(char *str, uint32_t h)
+{
+	struct hentry *e;
+
+	if ((e = malloc(sizeof(*e))) == NULL)
+		mtree_err("memory allocation error");
+
+	e->str = str;
+	e->hash = h;
+	e->next = table[h];
+	table[h] = e;
+}
+
+static void
+fill(char *str)
+{
+	uint32_t h;
+	char *ptr = strrchr(str, '/');
+
+	if (ptr == NULL)
+		return;
+
+	*ptr = '\0';
+	if (!hash_find(str, &h)) {
+		char *x = strdup(str);
+		if (x == NULL)
+			mtree_err("memory allocation error");
+		hash_insert(x, h);
+		fill(str);
+	}
+	*ptr = '/';
+}
+
+void
+load_only(const char *fname)
+{
+	FILE *fp;
+	char *line;
+	size_t len, lineno;
+
+	if ((fp = fopen(fname, "r")) == NULL)
+		err(1, "Cannot open `%s'", fname);
+
+	while ((line = fparseln(fp, &len, &lineno, NULL, FPARSELN_UNESCALL))) {
+		uint32_t h;
+		if (hash_find(line, &h))
+			err(1, "Duplicate entry %s", line);
+		hash_insert(line, h);
+		fill(line);
+	}
+
+	fclose(fp);
+	loaded = true;
+}
+
+bool
+find_only(const char *path)
+{
+	uint32_t h;
+
+	if (!loaded)
+		return true;
+	return hash_find(path, &h);
+}


Property changes on: trunk/contrib/mtree/only.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+MidnightBSD=%H
\ No newline at end of property
Added: svn:mime-type
## -0,0 +1 ##
+text/plain
\ No newline at end of property
Modified: trunk/contrib/mtree/spec.c
===================================================================
--- trunk/contrib/mtree/spec.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/spec.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: spec.c,v 1.85 2012/12/20 16:43:16 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: spec.c,v 1.89 2014/04/24 17:22:41 christos Exp $	*/
 
 /*-
  * Copyright (c) 1989, 1993
@@ -67,7 +68,7 @@
 #if 0
 static char sccsid[] = "@(#)spec.c	8.2 (Berkeley) 4/28/95";
 #else
-__RCSID("$NetBSD: spec.c,v 1.85 2012/12/20 16:43:16 christos Exp $");
+__RCSID("$NetBSD: spec.c,v 1.89 2014/04/24 17:22:41 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -81,6 +82,7 @@
 #include <pwd.h>
 #include <stdarg.h>
 #include <stdio.h>
+#include <stdint.h>
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
@@ -101,7 +103,7 @@
 static	void	unset(char *, NODE *);
 static	void	addchild(NODE *, NODE *);
 static	int	nodecmp(const NODE *, const NODE *);
-static	int	appendfield(int, const char *, ...) __printflike(2, 3);
+static	int	appendfield(FILE *, int, const char *, ...) __printflike(3, 4);
 
 #define REPLACEPTR(x,v)	do { if ((x)) free((x)); (x) = (v); } while (0)
 
@@ -217,6 +219,12 @@
 				/*
 				 * empty tree
 				 */
+			/*
+			 * Allow a bare "." root node by forcing it to
+			 * type=dir for compatibility with FreeBSD.
+			 */
+			if (strcmp(centry->name, ".") == 0 && centry->type == 0)
+				centry->type = F_DIR;
 			if (strcmp(centry->name, ".") != 0 ||
 			    centry->type != F_DIR)
 				mtree_err(
@@ -283,11 +291,11 @@
 
 /*
  * appendfield --
- *	Like printf(), but output a space either before or after
+ *	Like fprintf(), but output a space either before or after
  *	the regular output, according to the pathlast flag.
  */
 static int
-appendfield(int pathlast, const char *fmt, ...)
+appendfield(FILE *fp, int pathlast, const char *fmt, ...)
 {
 	va_list ap;
 	int result;
@@ -294,10 +302,10 @@
 
 	va_start(ap, fmt);
 	if (!pathlast)
-		printf(" ");
+		fprintf(fp, " ");
 	result = vprintf(fmt, ap);
 	if (pathlast)
-		printf(" ");
+		fprintf(fp, " ");
 	va_end(ap);
 	return result;
 }
@@ -309,7 +317,7 @@
  *	it first.
  */
 void
-dump_nodes(const char *dir, NODE *root, int pathlast)
+dump_nodes(FILE *fp, const char *dir, NODE *root, int pathlast)
 {
 	NODE	*cur;
 	char	path[MAXPATHLEN];
@@ -327,68 +335,75 @@
 			mtree_err("Pathname too long.");
 
 		if (!pathlast)
-			printf("%s", vispath(path));
+			fprintf(fp, "%s", vispath(path));
 
 #define MATCHFLAG(f)	((keys & (f)) && (cur->flags & (f)))
 		if (MATCHFLAG(F_TYPE))
-			appendfield(pathlast, "type=%s", nodetype(cur->type));
+			appendfield(fp, pathlast, "type=%s",
+			    nodetype(cur->type));
 		if (MATCHFLAG(F_UID | F_UNAME)) {
 			if (keys & F_UNAME &&
 			    (name = user_from_uid(cur->st_uid, 1)) != NULL)
-				appendfield(pathlast, "uname=%s", name);
+				appendfield(fp, pathlast, "uname=%s", name);
 			else
-				appendfield(pathlast, "uid=%u", cur->st_uid);
+				appendfield(fp, pathlast, "uid=%u",
+				    cur->st_uid);
 		}
 		if (MATCHFLAG(F_GID | F_GNAME)) {
 			if (keys & F_GNAME &&
 			    (name = group_from_gid(cur->st_gid, 1)) != NULL)
-				appendfield(pathlast, "gname=%s", name);
+				appendfield(fp, pathlast, "gname=%s", name);
 			else
-				appendfield(pathlast, "gid=%u", cur->st_gid);
+				appendfield(fp, pathlast, "gid=%u",
+				    cur->st_gid);
 		}
 		if (MATCHFLAG(F_MODE))
-			appendfield(pathlast, "mode=%#o", cur->st_mode);
+			appendfield(fp, pathlast, "mode=%#o", cur->st_mode);
 		if (MATCHFLAG(F_DEV) &&
 		    (cur->type == F_BLOCK || cur->type == F_CHAR))
-			appendfield(pathlast, "device=%#llx", (long long)cur->st_rdev);
+			appendfield(fp, pathlast, "device=%#jx",
+			    (uintmax_t)cur->st_rdev);
 		if (MATCHFLAG(F_NLINK))
-			appendfield(pathlast, "nlink=%d", cur->st_nlink);
+			appendfield(fp, pathlast, "nlink=%d", cur->st_nlink);
 		if (MATCHFLAG(F_SLINK))
-			appendfield(pathlast, "link=%s", vispath(cur->slink));
+			appendfield(fp, pathlast, "link=%s",
+			    vispath(cur->slink));
 		if (MATCHFLAG(F_SIZE))
-			appendfield(pathlast, "size=%lld", (long long)cur->st_size);
+			appendfield(fp, pathlast, "size=%ju",
+			    (uintmax_t)cur->st_size);
 		if (MATCHFLAG(F_TIME))
-			appendfield(pathlast, "time=%lld.%09ld",
-			    (long long)cur->st_mtimespec.tv_sec,
+			appendfield(fp, pathlast, "time=%jd.%09ld",
+			    (intmax_t)cur->st_mtimespec.tv_sec,
 			    cur->st_mtimespec.tv_nsec);
 		if (MATCHFLAG(F_CKSUM))
-			appendfield(pathlast, "cksum=%lu", cur->cksum);
+			appendfield(fp, pathlast, "cksum=%lu", cur->cksum);
 		if (MATCHFLAG(F_MD5))
-			appendfield(pathlast, "%s=%s", MD5KEY, cur->md5digest);
+			appendfield(fp, pathlast, "%s=%s", MD5KEY,
+			    cur->md5digest);
 		if (MATCHFLAG(F_RMD160))
-			appendfield(pathlast, "%s=%s", RMD160KEY,
+			appendfield(fp, pathlast, "%s=%s", RMD160KEY,
 			    cur->rmd160digest);
 		if (MATCHFLAG(F_SHA1))
-			appendfield(pathlast, "%s=%s", SHA1KEY,
+			appendfield(fp, pathlast, "%s=%s", SHA1KEY,
 			    cur->sha1digest);
 		if (MATCHFLAG(F_SHA256))
-			appendfield(pathlast, "%s=%s", SHA256KEY,
+			appendfield(fp, pathlast, "%s=%s", SHA256KEY,
 			    cur->sha256digest);
 		if (MATCHFLAG(F_SHA384))
-			appendfield(pathlast, "%s=%s", SHA384KEY,
+			appendfield(fp, pathlast, "%s=%s", SHA384KEY,
 			    cur->sha384digest);
 		if (MATCHFLAG(F_SHA512))
-			appendfield(pathlast, "%s=%s", SHA512KEY,
+			appendfield(fp, pathlast, "%s=%s", SHA512KEY,
 			    cur->sha512digest);
 		if (MATCHFLAG(F_FLAGS)) {
 			str = flags_to_string(cur->st_flags, "none");
-			appendfield(pathlast, "flags=%s", str);
+			appendfield(fp, pathlast, "flags=%s", str);
 			free(str);
 		}
 		if (MATCHFLAG(F_IGN))
-			appendfield(pathlast, "ignore");
+			appendfield(fp, pathlast, "ignore");
 		if (MATCHFLAG(F_OPT))
-			appendfield(pathlast, "optional");
+			appendfield(fp, pathlast, "optional");
 		if (MATCHFLAG(F_TAGS)) {
 			/* don't output leading or trailing commas */
 			p = cur->tags;
@@ -397,12 +412,12 @@
 			q = p + strlen(p);
 			while(q > p && q[-1] == ',')
 				q--;
-			appendfield(pathlast, "tags=%.*s", (int)(q - p), p);
+			appendfield(fp, pathlast, "tags=%.*s", (int)(q - p), p);
 		}
 		puts(pathlast ? vispath(path) : "");
 
 		if (cur->child)
-			dump_nodes(path, cur->child, pathlast);
+			dump_nodes(fp, path, cur->child, pathlast);
 	}
 }
 

Modified: trunk/contrib/mtree/specspec.c
===================================================================
--- trunk/contrib/mtree/specspec.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/specspec.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,3 +1,4 @@
+/* $MidnightBSD$ */
 /*	$NetBSD: specspec.c,v 1.2 2012/10/05 01:27:29 christos Exp $	*/
 
 /*-

Modified: trunk/contrib/mtree/verify.c
===================================================================
--- trunk/contrib/mtree/verify.c	2018-06-10 03:11:22 UTC (rev 10800)
+++ trunk/contrib/mtree/verify.c	2018-06-10 03:12:51 UTC (rev 10801)
@@ -1,4 +1,5 @@
-/*	$NetBSD: verify.c,v 1.43 2012/10/05 01:31:05 christos Exp $	*/
+/* $MidnightBSD$ */
+/*	$NetBSD: verify.c,v 1.44 2013/02/03 19:15:17 christos Exp $	*/
 
 /*-
  * Copyright (c) 1990, 1993
@@ -38,7 +39,7 @@
 #if 0
 static char sccsid[] = "@(#)verify.c	8.1 (Berkeley) 6/6/93";
 #else
-__RCSID("$NetBSD: verify.c,v 1.43 2012/10/05 01:31:05 christos Exp $");
+__RCSID("$NetBSD: verify.c,v 1.44 2013/02/03 19:15:17 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -95,6 +96,10 @@
 			fts_set(t, p, FTS_SKIP);
 			continue;
 		}
+		if (!find_only(p->fts_path)) {
+			fts_set(t, p, FTS_SKIP);
+			continue;
+		}
 		switch(p->fts_info) {
 		case FTS_D:
 		case FTS_SL:



More information about the Midnightbsd-cvs mailing list