From owner-svn-src-head@FreeBSD.ORG Tue Apr 9 06:50:13 2013 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.FreeBSD.org [8.8.178.115]) by hub.freebsd.org (Postfix) with ESMTP id AF1A51C4; Tue, 9 Apr 2013 06:50:13 +0000 (UTC) (envelope-from ed@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) by mx1.freebsd.org (Postfix) with ESMTP id A02543FB; Tue, 9 Apr 2013 06:50:13 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.6/8.14.6) with ESMTP id r396oDaY094506; Tue, 9 Apr 2013 06:50:13 GMT (envelope-from ed@svn.freebsd.org) Received: (from ed@localhost) by svn.freebsd.org (8.14.6/8.14.5/Submit) id r396oBpw094498; Tue, 9 Apr 2013 06:50:11 GMT (envelope-from ed@svn.freebsd.org) Message-Id: <201304090650.r396oBpw094498@svn.freebsd.org> From: Ed Schouten Date: Tue, 9 Apr 2013 06:50:11 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r249293 - in head: contrib/mtree usr.sbin/nmtree X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 09 Apr 2013 06:50:13 -0000 Author: ed Date: Tue Apr 9 06:50:11 2013 New Revision: 249293 URL: http://svnweb.freebsd.org/changeset/base/249293 Log: Import a new version of NetBSD's mtree. This version of mtree implements a new flag (-O) that can be used to restrict the tool to certain pathnames. Also, it fixes a compiler warning generated by -Wmissing-variable-declarations. Acked by: brooks Added: head/contrib/mtree/only.c - copied unchanged from r249269, vendor/NetBSD/mtree/dist/only.c Modified: head/contrib/mtree/Makefile head/contrib/mtree/create.c head/contrib/mtree/extern.h head/contrib/mtree/mtree.8 head/contrib/mtree/mtree.c head/contrib/mtree/verify.c head/usr.sbin/nmtree/Makefile Directory Properties: head/contrib/mtree/ (props changed) Modified: head/contrib/mtree/Makefile ============================================================================== --- head/contrib/mtree/Makefile Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/Makefile Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.33 2012/10/05 01:26:56 christos Exp $ +# $NetBSD: Makefile,v 1.34 2013/02/03 19:15:16 christos Exp $ # from: @(#)Makefile 8.2 (Berkeley) 4/27/95 .include @@ -8,7 +8,7 @@ PROG= mtree 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: head/contrib/mtree/create.c ============================================================================== --- head/contrib/mtree/create.c Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/create.c Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -/* $NetBSD: create.c,v 1.68 2012/12/20 16:43:16 christos Exp $ */ +/* $NetBSD: create.c,v 1.69 2013/02/03 19:15:17 christos Exp $ */ /*- * Copyright (c) 1989, 1993 @@ -38,7 +38,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.69 2013/02/03 19:15:17 christos Exp $"); #endif #endif /* not lint */ @@ -134,6 +134,10 @@ cwalk(void) 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) Modified: head/contrib/mtree/extern.h ============================================================================== --- head/contrib/mtree/extern.h Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/extern.h Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -/* $NetBSD: extern.h,v 1.37 2012/12/20 16:43:16 christos Exp $ */ +/* $NetBSD: extern.h,v 1.38 2013/02/03 19:15:17 christos Exp $ */ /*- * Copyright (c) 1991, 1993 @@ -42,6 +42,7 @@ #include #include #include +#include #if HAVE_NETDB_H /* For MAXHOSTNAMELEN on some platforms. */ @@ -74,6 +75,8 @@ u_int parsetype(const char *); 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: head/contrib/mtree/mtree.8 ============================================================================== --- head/contrib/mtree/mtree.8 Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/mtree.8 Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -.\" $NetBSD: mtree.8,v 1.67 2012/12/20 20:31:01 wiz Exp $ +.\" $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 +56,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 +73,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 +274,8 @@ rather than using the results from the s 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: head/contrib/mtree/mtree.c ============================================================================== --- head/contrib/mtree/mtree.c Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/mtree.c Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -/* $NetBSD: mtree.c,v 1.46 2012/12/20 19:09:25 christos Exp $ */ +/* $NetBSD: mtree.c,v 1.48 2013/04/08 17:39:11 christos Exp $ */ /*- * Copyright (c) 1989, 1990, 1993 @@ -43,7 +43,7 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 19 #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.48 2013/04/08 17:39:11 christos Exp $"); #endif #endif /* not lint */ @@ -59,8 +59,8 @@ __RCSID("$NetBSD: mtree.c,v 1.46 2012/12 #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,18 +79,20 @@ main(int argc, char **argv) { 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; 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 +181,9 @@ main(int argc, char **argv) "Unable to use user and group databases in `%s'", optarg); break; + case 'O': + load_only(optarg); + break; case 'p': dir = optarg; break; Copied: head/contrib/mtree/only.c (from r249269, vendor/NetBSD/mtree/dist/only.c) ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/contrib/mtree/only.c Tue Apr 9 06:50:11 2013 (r249293, copy of r249269, vendor/NetBSD/mtree/dist/only.c) @@ -0,0 +1,152 @@ +/* $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 + +#if defined(__RCSID) && !defined(lint) +__RCSID("$NetBSD: only.c,v 1.2 2013/02/05 00:59:03 christos Exp $"); +#endif + +#include + +#include +#include +#include +#include +#include +#include +#include + +#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); +} Modified: head/contrib/mtree/verify.c ============================================================================== --- head/contrib/mtree/verify.c Tue Apr 9 06:33:03 2013 (r249292) +++ head/contrib/mtree/verify.c Tue Apr 9 06:50:11 2013 (r249293) @@ -1,4 +1,4 @@ -/* $NetBSD: verify.c,v 1.43 2012/10/05 01:31:05 christos Exp $ */ +/* $NetBSD: verify.c,v 1.44 2013/02/03 19:15:17 christos Exp $ */ /*- * Copyright (c) 1990, 1993 @@ -38,7 +38,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 +95,10 @@ vwalk(void) 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: Modified: head/usr.sbin/nmtree/Makefile ============================================================================== --- head/usr.sbin/nmtree/Makefile Tue Apr 9 06:33:03 2013 (r249292) +++ head/usr.sbin/nmtree/Makefile Tue Apr 9 06:50:11 2013 (r249293) @@ -7,7 +7,7 @@ PROG= nmtree MAN= nmtree.8 SRCS= compare.c crc.c create.c excludes.c getid.c misc.c mtree.c \ - spec.c specspec.c verify.c + only.c spec.c specspec.c verify.c LDADD+= -lmd -lutil CFLAGS+= -I${.CURDIR}/../../contrib/mknod