svn commit: r185222 - in projects/makefs: . compat compat/machine
compat/mtree ffs sys sys/sys sys/ufs sys/ufs/ffs sys/ufs/ufs
Sam Leffler
sam at FreeBSD.org
Sun Nov 23 11:59:43 PST 2008
Author: sam
Date: Sun Nov 23 19:59:42 2008
New Revision: 185222
URL: http://svn.freebsd.org/changeset/base/185222
Log:
prepare makefs for import to base
Added:
projects/makefs/
projects/makefs/Makefile (contents, props changed)
projects/makefs/compat/
projects/makefs/compat/compat_defs.h (contents, props changed)
projects/makefs/compat/fparseln.c (contents, props changed)
projects/makefs/compat/getmode.c (contents, props changed)
projects/makefs/compat/machine/
projects/makefs/compat/machine/bswap.h (contents, props changed)
projects/makefs/compat/mtree/
projects/makefs/compat/mtree/extern.h (contents, props changed)
projects/makefs/compat/mtree/getid.c (contents, props changed)
projects/makefs/compat/mtree/misc.c (contents, props changed)
projects/makefs/compat/mtree/mtree.h (contents, props changed)
projects/makefs/compat/mtree/spec.c (contents, props changed)
projects/makefs/compat/namespace.h (contents, props changed)
projects/makefs/compat/nbtool_config.h (contents, props changed)
projects/makefs/compat/pack_dev.c (contents, props changed)
projects/makefs/compat/pack_dev.h (contents, props changed)
projects/makefs/compat/pwcache.c (contents, props changed)
projects/makefs/compat/pwcache.h (contents, props changed)
projects/makefs/compat/stat_flags.c (contents, props changed)
projects/makefs/compat/stat_flags.h (contents, props changed)
projects/makefs/compat/strsuftoll.c (contents, props changed)
projects/makefs/compat/util.h (contents, props changed)
projects/makefs/compat/vis.c (contents, props changed)
projects/makefs/compat/vis.h (contents, props changed)
projects/makefs/ffs/
projects/makefs/ffs.c (contents, props changed)
projects/makefs/ffs/buf.c (contents, props changed)
projects/makefs/ffs/buf.h (contents, props changed)
projects/makefs/ffs/ffs_alloc.c (contents, props changed)
projects/makefs/ffs/ffs_balloc.c (contents, props changed)
projects/makefs/ffs/ffs_extern.h (contents, props changed)
projects/makefs/ffs/mkfs.c (contents, props changed)
projects/makefs/ffs/newfs_extern.h (contents, props changed)
projects/makefs/ffs/ufs_bmap.c (contents, props changed)
projects/makefs/ffs/ufs_inode.h (contents, props changed)
projects/makefs/makefs.8 (contents, props changed)
projects/makefs/makefs.c (contents, props changed)
projects/makefs/makefs.h (contents, props changed)
projects/makefs/sys/
projects/makefs/sys/sys/
projects/makefs/sys/sys/queue.h (contents, props changed)
projects/makefs/sys/ufs/
projects/makefs/sys/ufs/ffs/
projects/makefs/sys/ufs/ffs/ffs_bswap.c (contents, props changed)
projects/makefs/sys/ufs/ffs/ffs_extern.h (contents, props changed)
projects/makefs/sys/ufs/ffs/ffs_subr.c (contents, props changed)
projects/makefs/sys/ufs/ffs/ffs_tables.c (contents, props changed)
projects/makefs/sys/ufs/ffs/fs.h (contents, props changed)
projects/makefs/sys/ufs/ufs/
projects/makefs/sys/ufs/ufs/dinode.h (contents, props changed)
projects/makefs/sys/ufs/ufs/dir.h (contents, props changed)
projects/makefs/sys/ufs/ufs/ufs_bswap.h (contents, props changed)
projects/makefs/walk.c (contents, props changed)
Added: projects/makefs/Makefile
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/Makefile Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,22 @@
+# $FreeBSD$
+
+PROG= makefs
+COMPAT_MTREE= getid.c misc.c spec.c
+COMPAT= fparseln.c getmode.c pack_dev.c pwcache.c stat_flags.c \
+ strsuftoll.c vis.c
+SRCS= ffs.c makefs.c walk.c \
+ buf.c ffs_alloc.c ffs_balloc.c mkfs.c ufs_bmap.c \
+ ffs_bswap.c ffs_subr.c ffs_tables.c \
+ ${COMPAT} ${COMPAT_MTREE}
+MAN= makefs.8
+
+CFLAGS+=-DHAVE_NBTOOL_CONFIG_H=1 -D_FILE_OFFSET_BITS=64
+CFLAGS+=-I.
+CFLAGS+=-Icompat -Icompat/mtree
+CFLAGS+=-Iffs -Isys -Isys/ufs
+
+.PATH: compat compat/mtree ffs sys/ufs/ufs sys/ufs/ffs
+
+WARNS?= 2
+
+.include <bsd.prog.mk>
Added: projects/makefs/compat/compat_defs.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/compat/compat_defs.h Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,167 @@
+/* $NetBSD: compat_defs.h,v 1.43 2004/06/23 11:08:01 tron Exp $ */
+
+#ifndef __NETBSD_COMPAT_DEFS_H__
+#define __NETBSD_COMPAT_DEFS_H__
+
+/* Work around some complete brain damage. */
+
+#undef _POSIX_SOURCE
+#undef _POSIX_C_SOURCE
+
+/* System headers needed for (re)definitions below. */
+
+#include <sys/types.h>
+#include <sys/mman.h>
+#include <sys/param.h>
+/* time.h needs to be pulled in first at least on netbsd w/o _NETBSD_SOURCE */
+#include <sys/time.h>
+#include <sys/stat.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <grp.h>
+#include <limits.h>
+#include <paths.h>
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if HAVE_SYS_CDEFS_H
+#include <sys/cdefs.h>
+#endif
+#if HAVE_SYS_SYSLIMITS_H
+#include <sys/syslimits.h>
+#endif
+#if HAVE_SYS_SYSMACROS_H
+/* major(), minor() on SVR4 */
+#include <sys/sysmacros.h>
+#endif
+#if HAVE_INTTYPES_H
+#include <inttypes.h>
+#endif
+#if HAVE_STDDEF_H
+#include <stddef.h>
+#endif
+
+/* We don't include <pwd.h> here, so that "compat_pwd.h" works. */
+struct passwd;
+
+/* Some things usually in BSD <sys/cdefs.h>. */
+#ifndef __RENAME
+#define __RENAME(x)
+#endif
+
+/* Dirent support. */
+#include <dirent.h>
+#define NAMLEN(dirent) (strlen((dirent)->d_name))
+
+#if !HAVE_FPARSELN || defined(__NetBSD__)
+# define FPARSELN_UNESCESC 0x01
+# define FPARSELN_UNESCCONT 0x02
+# define FPARSELN_UNESCCOMM 0x04
+# define FPARSELN_UNESCREST 0x08
+# define FPARSELN_UNESCALL 0x0f
+char *fparseln(FILE *, size_t *, size_t *, const char [3], int);
+#endif
+
+#define __nbcompat_bswap16(x) ((((x) << 8) & 0xff00) | (((x) >> 8) & 0x00ff))
+
+#define __nbcompat_bswap32(x) ((((x) << 24) & 0xff000000) | \
+ (((x) << 8) & 0x00ff0000) | \
+ (((x) >> 8) & 0x0000ff00) | \
+ (((x) >> 24) & 0x000000ff))
+
+#define __nbcompat_bswap64(x) (((u_int64_t)bswap32((x)) << 32) | \
+ ((u_int64_t)bswap32((x) >> 32)))
+
+#if !HAVE_BSWAP16
+#ifdef bswap16
+#undef bswap16
+#endif
+#define bswap16(x) __nbcompat_bswap16(x)
+#endif
+#if !HAVE_BSWAP32
+#ifdef bswap32
+#undef bswap32
+#endif
+#define bswap32(x) __nbcompat_bswap32(x)
+#endif
+#if !HAVE_BSWAP64
+#ifdef bswap64
+#undef bswap64
+#endif
+#define bswap64(x) __nbcompat_bswap64(x)
+#endif
+
+#if !HAVE_PWCACHE_USERDB
+int uid_from_user(const char *, uid_t *);
+int pwcache_userdb(int (*)(int), void (*)(void),
+ struct passwd * (*)(const char *), struct passwd * (*)(uid_t));
+int gid_from_group(const char *, gid_t *);
+int pwcache_groupdb(int (*)(int), void (*)(void),
+ struct group * (*)(const char *), struct group * (*)(gid_t));
+#endif
+/* Make them use our version */
+# define user_from_uid __nbcompat_user_from_uid
+/* Make them use our version */
+# define group_from_gid __nbcompat_group_from_gid
+#if HAVE_GROUP_FROM_GID
+const char *group_from_gid(gid_t, int);
+#endif
+
+#if !HAVE_SETENV
+int setenv(const char *, const char *, int);
+#endif
+
+#if !HAVE_STRSUFTOLL
+long long strsuftoll(const char *, const char *, long long, long long);
+long long strsuftollx(const char *, const char *,
+ long long, long long, char *, size_t);
+#endif
+
+#if !HAVE_USER_FROM_UID
+const char *user_from_uid(uid_t, int);
+#endif
+
+#if !HAVE_GROUP_FROM_GID
+const char *group_from_gid(gid_t, int);
+#endif
+
+/*
+ * getmode() and setmode() are always defined, as these function names
+ * exist but with very different meanings on other OS's. The compat
+ * versions here simply accept an octal mode number; the "u+x,g-w" type
+ * of syntax is not accepted.
+ */
+
+#define getmode __nbcompat_getmode
+#define setmode __nbcompat_setmode
+
+mode_t getmode(const void *, mode_t);
+void *setmode(const char *);
+
+/* Eliminate assertions embedded in binaries. */
+
+#undef _DIAGASSERT
+#define _DIAGASSERT(x)
+
+/* Various sources use this */
+#undef __RCSID
+#define __RCSID(x)
+#undef __SCCSID
+#define __SCCSID(x)
+#undef __COPYRIGHT
+#define __COPYRIGHT(x)
+#undef __KERNEL_RCSID
+#define __KERNEL_RCSID(x,y)
+
+/* Heimdal expects this one. */
+
+#undef RCSID
+#define RCSID(x)
+
+#ifndef MAXFRAG
+#define MAXFRAG 8
+#endif
+
+#endif /* !__NETBSD_COMPAT_DEFS_H__ */
Added: projects/makefs/compat/fparseln.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/compat/fparseln.c Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,248 @@
+/* $NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $ */
+
+/*
+ * Copyright (c) 1997 Christos Zoulas. All rights reserved.
+ *
+ * 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 by Christos Zoulas.
+ * 4. The name of the author may not be used to endorse or promote products
+ * derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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.
+ */
+
+#include <sys/cdefs.h>
+#if defined(LIBC_SCCS) && !defined(lint)
+__RCSID("$NetBSD: fparseln.c,v 1.5 2004/06/20 22:20:15 jmc Exp $");
+#endif /* LIBC_SCCS and not lint */
+
+#include "namespace.h"
+
+#include <assert.h>
+#include <errno.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef __weak_alias
+__weak_alias(fparseln,_fparseln)
+#endif
+
+#if ! HAVE_FPARSELN
+
+#ifndef HAVE_NBTOOL_CONFIG_H
+#include "reentrant.h"
+#include "local.h"
+#else
+#define FLOCKFILE(fp)
+#define FUNLOCKFILE(fp)
+#endif
+
+#if defined(_REENTRANT) && !HAVE_NBTOOL_CONFIG_H
+#define __fgetln(f, l) __fgetstr(f, l, '\n')
+#else
+#define __fgetln(f, l) fgetln(f, l)
+#endif
+
+static int isescaped(const char *, const char *, int);
+
+/* isescaped():
+ * Return true if the character in *p that belongs to a string
+ * that starts in *sp, is escaped by the escape character esc.
+ */
+static int
+isescaped(const char *sp, const char *p, int esc)
+{
+ const char *cp;
+ size_t ne;
+
+ _DIAGASSERT(sp != NULL);
+ _DIAGASSERT(p != NULL);
+
+ /* No escape character */
+ if (esc == '\0')
+ return 1;
+
+ /* Count the number of escape characters that precede ours */
+ for (ne = 0, cp = p; --cp >= sp && *cp == esc; ne++)
+ continue;
+
+ /* Return true if odd number of escape characters */
+ return (ne & 1) != 0;
+}
+
+
+/* fparseln():
+ * Read a line from a file parsing continuations ending in \
+ * and eliminating trailing newlines, or comments starting with
+ * the comment char.
+ */
+char *
+fparseln(FILE *fp, size_t *size, size_t *lineno, const char str[3], int flags)
+{
+ static const char dstr[3] = { '\\', '\\', '#' };
+
+ size_t s, len;
+ char *buf;
+ char *ptr, *cp;
+ int cnt;
+ char esc, con, nl, com;
+
+ _DIAGASSERT(fp != NULL);
+
+ len = 0;
+ buf = NULL;
+ cnt = 1;
+
+ if (str == NULL)
+ str = dstr;
+
+ esc = str[0];
+ con = str[1];
+ com = str[2];
+ /*
+ * XXX: it would be cool to be able to specify the newline character,
+ * but unfortunately, fgetln does not let us
+ */
+ nl = '\n';
+
+ FLOCKFILE(fp);
+
+ while (cnt) {
+ cnt = 0;
+
+ if (lineno)
+ (*lineno)++;
+
+ if ((ptr = __fgetln(fp, &s)) == NULL)
+ break;
+
+ if (s && com) { /* Check and eliminate comments */
+ for (cp = ptr; cp < ptr + s; cp++)
+ if (*cp == com && !isescaped(ptr, cp, esc)) {
+ s = cp - ptr;
+ cnt = s == 0 && buf == NULL;
+ break;
+ }
+ }
+
+ if (s && nl) { /* Check and eliminate newlines */
+ cp = &ptr[s - 1];
+
+ if (*cp == nl)
+ s--; /* forget newline */
+ }
+
+ if (s && con) { /* Check and eliminate continuations */
+ cp = &ptr[s - 1];
+
+ if (*cp == con && !isescaped(ptr, cp, esc)) {
+ s--; /* forget escape */
+ cnt = 1;
+ }
+ }
+
+ if (s == 0 && buf != NULL)
+ continue;
+
+ if ((cp = realloc(buf, len + s + 1)) == NULL) {
+ FUNLOCKFILE(fp);
+ free(buf);
+ return NULL;
+ }
+ buf = cp;
+
+ (void) memcpy(buf + len, ptr, s);
+ len += s;
+ buf[len] = '\0';
+ }
+
+ FUNLOCKFILE(fp);
+
+ if ((flags & FPARSELN_UNESCALL) != 0 && esc && buf != NULL &&
+ strchr(buf, esc) != NULL) {
+ ptr = cp = buf;
+ while (cp[0] != '\0') {
+ int skipesc;
+
+ while (cp[0] != '\0' && cp[0] != esc)
+ *ptr++ = *cp++;
+ if (cp[0] == '\0' || cp[1] == '\0')
+ break;
+
+ skipesc = 0;
+ if (cp[1] == com)
+ skipesc += (flags & FPARSELN_UNESCCOMM);
+ if (cp[1] == con)
+ skipesc += (flags & FPARSELN_UNESCCONT);
+ if (cp[1] == esc)
+ skipesc += (flags & FPARSELN_UNESCESC);
+ if (cp[1] != com && cp[1] != con && cp[1] != esc)
+ skipesc = (flags & FPARSELN_UNESCREST);
+
+ if (skipesc)
+ cp++;
+ else
+ *ptr++ = *cp++;
+ *ptr++ = *cp++;
+ }
+ *ptr = '\0';
+ len = strlen(buf);
+ }
+
+ if (size)
+ *size = len;
+ return buf;
+}
+
+#ifdef TEST
+
+int main(int, char **);
+
+int
+main(int argc, char **argv)
+{
+ char *ptr;
+ size_t size, line;
+
+ line = 0;
+ while ((ptr = fparseln(stdin, &size, &line, NULL,
+ FPARSELN_UNESCALL)) != NULL)
+ printf("line %d (%d) |%s|\n", line, size, ptr);
+ return 0;
+}
+
+/*
+
+# This is a test
+line 1
+line 2 \
+line 3 # Comment
+line 4 \# Not comment \\\\
+
+# And a comment \
+line 5 \\\
+line 6
+
+*/
+
+#endif /* TEST */
+#endif /* ! HAVE_FPARSELN */
Added: projects/makefs/compat/getmode.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/compat/getmode.c Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,63 @@
+/* $NetBSD: getmode.c,v 1.6 2004/01/13 00:53:06 simonb Exp $ */
+
+/*-
+ * Copyright (c) 2001 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Todd Vierling.
+ *
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. 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.
+ */
+
+#include "nbtool_config.h"
+#include <stdlib.h>
+
+void *
+setmode(const char *str)
+{
+ mode_t *mp = malloc(sizeof(mode_t));
+
+ *mp = strtoul(str, NULL, 8);
+
+ return mp;
+}
+
+mode_t
+getmode(const void *mp, mode_t mode)
+{
+ mode_t m;
+
+ m = *((const mode_t *)mp);
+
+ mode &= ~ALLPERMS; /* input mode less RWX permissions */
+ m &= ALLPERMS; /* new RWX permissions */
+
+ return m | mode;
+}
Added: projects/makefs/compat/machine/bswap.h
==============================================================================
Added: projects/makefs/compat/mtree/extern.h
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/compat/mtree/extern.h Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,81 @@
+/* $NetBSD: extern.h,v 1.28 2003/10/27 00:12:44 lukem Exp $ */
+
+/*-
+ * Copyright (c) 1991, 1993
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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
+ * 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.
+ *
+ * @(#)extern.h 8.1 (Berkeley) 6/6/93
+ */
+
+#include "mtree.h"
+
+#if HAVE_NBTOOL_CONFIG_H
+#include "nbtool_config.h"
+#else
+#define HAVE_STRUCT_STAT_ST_FLAGS 1
+#endif
+
+#include <err.h>
+#include <fts.h>
+
+#if HAVE_NETDB_H
+/* For MAXHOSTNAMELEN on some platforms. */
+#include <netdb.h>
+#endif
+
+#ifndef MAXHOSTNAMELEN
+#define MAXHOSTNAMELEN 256
+#endif
+
+void addtag(slist_t *, char *);
+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 init_excludes(void);
+int matchtags(NODE *);
+void mtree_err(const char *, ...)
+ __attribute__((__format__(__printf__, 1, 2)));
+const char *nodetype(u_int);
+u_int parsekey(const char *, int *);
+void parsetags(slist_t *, char *);
+u_int parsetype(const char *);
+void read_excludes_file(const char *);
+const char *rlink(const char *);
+int verify(void);
+
+extern int dflag, eflag, iflag, lflag, mflag, rflag, sflag, tflag, uflag;
+extern int Wflag;
+extern size_t mtree_lineno;
+extern u_int32_t crc_total;
+extern int ftsoptions, keys;
+extern char fullpath[];
+extern slist_t includetags, excludetags;
+
+
+#include "stat_flags.h"
Added: projects/makefs/compat/mtree/getid.c
==============================================================================
--- /dev/null 00:00:00 1970 (empty, because file is newly added)
+++ projects/makefs/compat/mtree/getid.c Sun Nov 23 19:59:42 2008 (r185222)
@@ -0,0 +1,435 @@
+/* $NetBSD: getid.c,v 1.5 2004/06/20 22:20:18 jmc 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 */
+
+/*
+ * Copyright (c) 1987, 1988, 1989, 1993, 1994, 1995
+ * The Regents of the University of California. All rights reserved.
+ *
+ * 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
+ * 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.
+ */
+
+/*-
+ * Copyright (c) 2002 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Luke Mewburn of Wasabi Systems.
+ *
+ * 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 by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. 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/param.h>
+
+#include <grp.h>
+#include <limits.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <time.h>
+#include <unistd.h>
+
+#include "extern.h"
+
+static struct group * gi_getgrnam(const char *);
+static struct group * gi_getgrgid(gid_t);
+static int gi_setgroupent(int);
+static void gi_endgrent(void);
+static int grstart(void);
+static int grscan(int, gid_t, const char *);
+static int grmatchline(int, gid_t, const char *);
+
+static struct passwd * gi_getpwnam(const char *);
+static struct passwd * gi_getpwuid(uid_t);
+static int gi_setpassent(int);
+static void gi_endpwent(void);
+static int pwstart(void);
+static int pwscan(int, uid_t, const char *);
+static int pwmatchline(int, uid_t, const char *);
+
+#define MAXGRP 200
+#define MAXLINELENGTH 1024
+
+static FILE *_gr_fp;
+static struct group _gr_group;
+static int _gr_stayopen;
+static int _gr_filesdone;
+static FILE *_pw_fp;
+static struct passwd _pw_passwd; /* password structure */
+static int _pw_stayopen; /* keep fd's open */
+static int _pw_filesdone;
+
+static char grfile[MAXPATHLEN];
+static char pwfile[MAXPATHLEN];
+
+static char *members[MAXGRP];
+static char grline[MAXLINELENGTH];
+static char pwline[MAXLINELENGTH];
+
+int
+setup_getid(const char *dir)
+{
+ if (dir == NULL)
+ return (0);
+
+ /* close existing databases */
+ gi_endgrent();
+ gi_endpwent();
+
+ /* build paths to new databases */
+ snprintf(grfile, sizeof(grfile), "%s/group", dir);
+ snprintf(pwfile, sizeof(pwfile), "%s/master.passwd", dir);
+
+ /* try to open new databases */
+ if (!grstart() || !pwstart())
+ return (0);
+
+ /* switch pwcache(3) lookup functions */
+ if (pwcache_groupdb(gi_setgroupent, gi_endgrent,
+ gi_getgrnam, gi_getgrgid) == -1
+ || pwcache_userdb(gi_setpassent, gi_endpwent,
+ gi_getpwnam, gi_getpwuid) == -1)
+ return (0);
+
+ return (1);
+}
+
+
+/*
+ * group lookup functions
+ */
+
+static struct group *
+gi_getgrnam(const char *name)
+{
+ int rval;
+
+ if (!grstart())
+ return NULL;
+ rval = grscan(1, 0, name);
+ if (!_gr_stayopen)
+ endgrent();
+ return (rval) ? &_gr_group : NULL;
+}
+
+static struct group *
+gi_getgrgid(gid_t gid)
+{
+ int rval;
+
+ if (!grstart())
+ return NULL;
+ rval = grscan(1, gid, NULL);
+ if (!_gr_stayopen)
+ endgrent();
+ return (rval) ? &_gr_group : NULL;
+}
+
+static int
+gi_setgroupent(int stayopen)
+{
+
+ if (!grstart())
+ return 0;
+ _gr_stayopen = stayopen;
+ return 1;
+}
+
+static void
+gi_endgrent(void)
+{
+
+ _gr_filesdone = 0;
+ if (_gr_fp) {
+ (void)fclose(_gr_fp);
+ _gr_fp = NULL;
+ }
+}
+
+static int
+grstart(void)
+{
+
+ _gr_filesdone = 0;
+ if (_gr_fp) {
+ rewind(_gr_fp);
+ return 1;
+ }
+ if (grfile[0] == '\0') /* sanity check */
+ return 0;
+ return (_gr_fp = fopen(grfile, "r")) ? 1 : 0;
+}
+
+
+static int
+grscan(int search, gid_t gid, const char *name)
+{
+
+ if (_gr_filesdone)
+ return 0;
+ for (;;) {
+ if (!fgets(grline, sizeof(grline), _gr_fp)) {
+ if (!search)
+ _gr_filesdone = 1;
+ return 0;
+ }
+ /* skip lines that are too big */
+ if (!strchr(grline, '\n')) {
+ int ch;
+
+ while ((ch = getc(_gr_fp)) != '\n' && ch != EOF)
+ ;
+ continue;
+ }
+ if (grmatchline(search, gid, name))
+ return 1;
+ }
+ /* NOTREACHED */
+}
+
+static int
+grmatchline(int search, gid_t gid, const char *name)
+{
+ unsigned long id;
+ char **m;
+ char *cp, *bp, *ep;
+
+ /* name may be NULL if search is nonzero */
+
+ bp = grline;
+ memset(&_gr_group, 0, sizeof(_gr_group));
+ _gr_group.gr_name = strsep(&bp, ":\n");
+ if (search && name && strcmp(_gr_group.gr_name, name))
+ return 0;
+ _gr_group.gr_passwd = strsep(&bp, ":\n");
+ if (!(cp = strsep(&bp, ":\n")))
+ return 0;
+ id = strtoul(cp, &ep, 10);
+ if (id > GID_MAX || *ep != '\0')
+ return 0;
+ _gr_group.gr_gid = (gid_t)id;
+ if (search && name == NULL && _gr_group.gr_gid != gid)
+ return 0;
+ cp = NULL;
+ if (bp == NULL)
+ return 0;
+ for (_gr_group.gr_mem = m = members;; bp++) {
+ if (m == &members[MAXGRP - 1])
+ break;
+ if (*bp == ',') {
+ if (cp) {
+ *bp = '\0';
+ *m++ = cp;
+ cp = NULL;
+ }
+ } else if (*bp == '\0' || *bp == '\n' || *bp == ' ') {
+ if (cp) {
+ *bp = '\0';
+ *m++ = cp;
+ }
+ break;
+ } else if (cp == NULL)
+ cp = bp;
+ }
+ *m = NULL;
+ return 1;
+}
+
+
+/*
+ * user lookup functions
+ */
+
+static struct passwd *
+gi_getpwnam(const char *name)
+{
+ int rval;
+
+ if (!pwstart())
+ return NULL;
+ rval = pwscan(1, 0, name);
+ if (!_pw_stayopen)
+ endpwent();
+ return (rval) ? &_pw_passwd : NULL;
+}
+
+static struct passwd *
+gi_getpwuid(uid_t uid)
+{
+ int rval;
+
+ if (!pwstart())
+ return NULL;
+ rval = pwscan(1, uid, NULL);
+ if (!_pw_stayopen)
+ endpwent();
+ return (rval) ? &_pw_passwd : NULL;
+}
+
+static int
+gi_setpassent(int stayopen)
+{
+
+ if (!pwstart())
+ return 0;
+ _pw_stayopen = stayopen;
+ return 1;
+}
+
+static void
+gi_endpwent(void)
+{
+
+ _pw_filesdone = 0;
+ if (_pw_fp) {
+ (void)fclose(_pw_fp);
+ _pw_fp = NULL;
+ }
+}
+
+static int
+pwstart(void)
+{
+
+ _pw_filesdone = 0;
+ if (_pw_fp) {
+ rewind(_pw_fp);
+ return 1;
+ }
+ if (pwfile[0] == '\0') /* sanity check */
+ return 0;
+ return (_pw_fp = fopen(pwfile, "r")) ? 1 : 0;
+}
+
+
+static int
+pwscan(int search, uid_t uid, const char *name)
+{
+
+ if (_pw_filesdone)
+ return 0;
+ for (;;) {
+ if (!fgets(pwline, sizeof(pwline), _pw_fp)) {
+ if (!search)
+ _pw_filesdone = 1;
+ return 0;
+ }
+ /* skip lines that are too big */
+ if (!strchr(pwline, '\n')) {
+ int ch;
+
+ while ((ch = getc(_pw_fp)) != '\n' && ch != EOF)
+ ;
+ continue;
+ }
+ if (pwmatchline(search, uid, name))
+ return 1;
+ }
+ /* NOTREACHED */
+}
+
+static int
+pwmatchline(int search, uid_t uid, const char *name)
+{
+ unsigned long id;
+ char *cp, *bp, *ep;
+
+ /* name may be NULL if search is nonzero */
+
+ bp = pwline;
+ memset(&_pw_passwd, 0, sizeof(_pw_passwd));
+ _pw_passwd.pw_name = strsep(&bp, ":\n"); /* name */
+ if (search && name && strcmp(_pw_passwd.pw_name, name))
+ return 0;
+
+ _pw_passwd.pw_passwd = strsep(&bp, ":\n"); /* passwd */
+
+ if (!(cp = strsep(&bp, ":\n"))) /* uid */
+ return 0;
*** DIFF OUTPUT TRUNCATED AT 1000 LINES ***
More information about the svn-src-projects
mailing list