From owner-svn-src-all@FreeBSD.ORG Wed Sep 15 19:20:29 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6F923106566C; Wed, 15 Sep 2010 19:20:29 +0000 (UTC) (envelope-from mm@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 5DD208FC1B; Wed, 15 Sep 2010 19:20:29 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id o8FJKTqD047570; Wed, 15 Sep 2010 19:20:29 GMT (envelope-from mm@svn.freebsd.org) Received: (from mm@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id o8FJKTo4047567; Wed, 15 Sep 2010 19:20:29 GMT (envelope-from mm@svn.freebsd.org) Message-Id: <201009151920.o8FJKTo4047567@svn.freebsd.org> From: Martin Matuska Date: Wed, 15 Sep 2010 19:20:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org X-SVN-Group: stable-8 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r212688 - in stable/8/cddl/compat/opensolaris: include misc X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 15 Sep 2010 19:20:29 -0000 Author: mm Date: Wed Sep 15 19:20:29 2010 New Revision: 212688 URL: http://svn.freebsd.org/changeset/base/212688 Log: Add missing MFC to r212668 for cddl/compat/opensolaris from r209962. Modified: stable/8/cddl/compat/opensolaris/include/mnttab.h stable/8/cddl/compat/opensolaris/misc/mnttab.c Directory Properties: stable/8/cddl/compat/opensolaris/ (props changed) Modified: stable/8/cddl/compat/opensolaris/include/mnttab.h ============================================================================== --- stable/8/cddl/compat/opensolaris/include/mnttab.h Wed Sep 15 19:08:41 2010 (r212687) +++ stable/8/cddl/compat/opensolaris/include/mnttab.h Wed Sep 15 19:20:29 2010 (r212688) @@ -3,10 +3,13 @@ #ifndef _OPENSOLARIS_MNTTAB_H_ #define _OPENSOLARIS_MNTTAB_H_ +#include +#include + #include #include -#define MNTTAB _PATH_DEVNULL +#define MNTTAB _PATH_DEVZERO #define MNT_LINE_MAX 1024 #define umount2(p, f) unmount(p, f) @@ -17,7 +20,12 @@ struct mnttab { char *mnt_fstype; char *mnt_mntopts; }; +#define extmnttab mnttab int getmntany(FILE *fd, struct mnttab *mgetp, struct mnttab *mrefp); +int getmntent(FILE *fp, struct mnttab *mp); +char *hasmntopt(struct mnttab *mnt, char *opt); + +void statfs2mnttab(struct statfs *sfs, struct mnttab *mp); #endif /* !_OPENSOLARIS_MNTTAB_H_ */ Modified: stable/8/cddl/compat/opensolaris/misc/mnttab.c ============================================================================== --- stable/8/cddl/compat/opensolaris/misc/mnttab.c Wed Sep 15 19:08:41 2010 (r212687) +++ stable/8/cddl/compat/opensolaris/misc/mnttab.c Wed Sep 15 19:20:29 2010 (r212688) @@ -36,6 +36,9 @@ __FBSDID("$FreeBSD$"); #include #include #include + +#include +#include #include #include #include @@ -88,75 +91,126 @@ optadd(char *mntopts, size_t size, const strlcat(mntopts, opt, size); } -int -getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp) +void +statfs2mnttab(struct statfs *sfs, struct mnttab *mp) { - static struct statfs *sfs = NULL; static char mntopts[MNTMAXSTR]; - struct opt *o; - long i, n, flags; + long flags; - if (sfs != NULL) { - free(sfs); - sfs = NULL; - } mntopts[0] = '\0'; - n = getfsstat(NULL, 0, MNT_NOWAIT); - if (n == -1) - return (-1); - n = sizeof(*sfs) * (n + 8); - sfs = malloc(n); - if (sfs == NULL) - return (-1); - n = getfsstat(sfs, n, MNT_WAIT); - if (n == -1) { - free(sfs); - sfs = NULL; - return (-1); + flags = sfs->f_flags; +#define OPTADD(opt) optadd(mntopts, sizeof(mntopts), (opt)) + if (flags & MNT_RDONLY) + OPTADD(MNTOPT_RO); + else + OPTADD(MNTOPT_RW); + if (flags & MNT_NOSUID) + OPTADD(MNTOPT_NOSUID); + else + OPTADD(MNTOPT_SETUID); + if (flags & MNT_UPDATE) + OPTADD(MNTOPT_REMOUNT); + if (flags & MNT_NOATIME) + OPTADD(MNTOPT_NOATIME); + else + OPTADD(MNTOPT_ATIME); + OPTADD(MNTOPT_NOXATTR); + if (flags & MNT_NOEXEC) + OPTADD(MNTOPT_NOEXEC); + else + OPTADD(MNTOPT_EXEC); +#undef OPTADD + mp->mnt_special = sfs->f_mntfromname; + mp->mnt_mountp = sfs->f_mntonname; + mp->mnt_fstype = sfs->f_fstypename; + mp->mnt_mntopts = mntopts; +} + +static struct statfs *gsfs = NULL; +static int allfs = 0; + +static int +statfs_init(void) +{ + struct statfs *sfs; + int error; + + if (gsfs != NULL) { + free(gsfs); + gsfs = NULL; } - for (i = 0; i < n; i++) { + allfs = getfsstat(NULL, 0, MNT_WAIT); + if (allfs == -1) + goto fail; + gsfs = malloc(sizeof(gsfs[0]) * allfs * 2); + if (gsfs == NULL) + goto fail; + allfs = getfsstat(gsfs, (long)(sizeof(gsfs[0]) * allfs * 2), + MNT_WAIT); + if (allfs == -1) + goto fail; + sfs = realloc(gsfs, allfs * sizeof(gsfs[0])); + if (sfs != NULL) + gsfs = sfs; + return (0); +fail: + error = errno; + if (gsfs != NULL) + free(gsfs); + gsfs = NULL; + allfs = 0; + return (error); +} + +int +getmntany(FILE *fd __unused, struct mnttab *mgetp, struct mnttab *mrefp) +{ + struct statfs *sfs; + int i, error; + + error = statfs_init(); + if (error != 0) + return (error); + + for (i = 0; i < allfs; i++) { if (mrefp->mnt_special != NULL && - strcmp(mrefp->mnt_special, sfs[i].f_mntfromname) != 0) { + strcmp(mrefp->mnt_special, gsfs[i].f_mntfromname) != 0) { continue; } if (mrefp->mnt_mountp != NULL && - strcmp(mrefp->mnt_mountp, sfs[i].f_mntonname) != 0) { + strcmp(mrefp->mnt_mountp, gsfs[i].f_mntonname) != 0) { continue; } if (mrefp->mnt_fstype != NULL && - strcmp(mrefp->mnt_fstype, sfs[i].f_fstypename) != 0) { + strcmp(mrefp->mnt_fstype, gsfs[i].f_fstypename) != 0) { continue; } - flags = sfs[i].f_flags; -#define OPTADD(opt) optadd(mntopts, sizeof(mntopts), (opt)) - if (flags & MNT_RDONLY) - OPTADD(MNTOPT_RO); - else - OPTADD(MNTOPT_RW); - if (flags & MNT_NOSUID) - OPTADD(MNTOPT_NOSUID); - else - OPTADD(MNTOPT_SETUID); - if (flags & MNT_UPDATE) - OPTADD(MNTOPT_REMOUNT); - if (flags & MNT_NOATIME) - OPTADD(MNTOPT_NOATIME); - else - OPTADD(MNTOPT_ATIME); - OPTADD(MNTOPT_NOXATTR); - if (flags & MNT_NOEXEC) - OPTADD(MNTOPT_NOEXEC); - else - OPTADD(MNTOPT_EXEC); -#undef OPTADD - mgetp->mnt_special = sfs[i].f_mntfromname; - mgetp->mnt_mountp = sfs[i].f_mntonname; - mgetp->mnt_fstype = sfs[i].f_fstypename; - mgetp->mnt_mntopts = mntopts; + statfs2mnttab(&gsfs[i], mgetp); return (0); } - free(sfs); - sfs = NULL; return (-1); } + +int +getmntent(FILE *fp, struct mnttab *mp) +{ + struct statfs *sfs; + int error, nfs; + + nfs = (int)lseek(fileno(fp), 0, SEEK_CUR); + if (nfs == -1) + return (errno); + /* If nfs is 0, we want to refresh out cache. */ + if (nfs == 0 || gsfs == NULL) { + error = statfs_init(); + if (error != 0) + return (error); + } + if (nfs >= allfs) + return (-1); + statfs2mnttab(&gsfs[nfs], mp); + if (lseek(fileno(fp), 1, SEEK_CUR) == -1) + return (errno); + return (0); +}