[Midnightbsd-cvs] src: sbin/mount: Sync mount, sunlabel, and umount

laffer1 at midnightbsd.org laffer1 at midnightbsd.org
Tue Nov 11 16:35:20 EST 2008


Log Message:
-----------
Sync mount, sunlabel, and umount

Modified Files:
--------------
    src/sbin/mount:
        Makefile (r1.1.1.1 -> r1.2)
        extern.h (r1.1.1.1 -> r1.2)
        getmntopts.3 (r1.1.1.1 -> r1.2)
        getmntopts.c (r1.1.1.1 -> r1.2)
        mntopts.h (r1.1.1.1 -> r1.2)
        mount.8 (r1.2 -> r1.3)
        mount.c (r1.1.1.2 -> r1.2)

Added Files:
-----------
    src/sbin/mount:
        mount_fs.c (r1.1)

Removed Files:
-------------
    src/sbin/mount:
        mount_ufs.c

-------------- next part --------------
--- /dev/null
+++ sbin/mount/mount_fs.c
@@ -0,0 +1,138 @@
+/*
+ * Copyright (c) 1992, 1993, 1994
+ *	The Regents of the University of California.  All rights reserved.
+ *
+ * This code is derived from software donated to Berkeley by
+ * Jan-Simon Pendry.
+ *
+ * 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 University of
+ *	California, Berkeley and its contributors.
+ * 4. 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.
+ */
+
+#ifndef lint
+static const char copyright[] =
+"@(#) Copyright (c) 1992, 1993, 1994\n\
+	The Regents of the University of California.  All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+#if 0
+static char sccsid[] = "@(#)mount_fs.c	8.6 (Berkeley) 4/26/95";
+#endif
+static const char rcsid[] =
+	"$FreeBSD: src/sbin/mount/mount_fs.c,v 1.3 2006/12/07 03:24:43 rodrigc Exp $";
+#endif /* not lint */
+
+#include <sys/param.h>
+#include <sys/mount.h>
+
+#include <err.h>
+#include <getopt.h>
+#include <libgen.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "extern.h"
+#include "mntopts.h"
+
+struct mntopt mopts[] = {
+	MOPT_STDOPTS,
+	MOPT_END
+};
+
+static void
+usage(void)
+{
+	(void)fprintf(stderr,
+		"usage: mount [-t fstype] [-o options] target_fs mount_point\n");
+	exit(1);
+}
+
+int
+mount_fs(const char *vfstype, int argc, char *argv[])
+{
+	struct iovec *iov;
+	int iovlen;
+	int mntflags = 0;
+	int ch;
+	char *dev, *dir, mntpath[MAXPATHLEN];
+	char fstype[32];
+	char errmsg[255];
+	char *p, *val;
+	int ret;
+
+	strncpy(fstype, vfstype, sizeof(fstype));
+	memset(errmsg, 0, sizeof(errmsg));
+
+	getmnt_silent = 1;
+	iov = NULL;
+	iovlen = 0;
+
+	optind = optreset = 1;		/* Reset for parse of new argv. */
+	while ((ch = getopt(argc, argv, "o:")) != -1) {
+		switch(ch) {
+		case 'o':
+			getmntopts(optarg, mopts, &mntflags, 0);
+			p = strchr(optarg, '=');
+			val = NULL;
+			if (p != NULL) {
+				*p = '\0';
+				val = p + 1;
+			}
+			build_iovec(&iov, &iovlen, optarg, val, (size_t)-1);
+			break;
+		case '?':
+		default:
+			usage();
+		}
+	}
+
+	argc -= optind;
+	argv += optind;
+	if (argc != 2)
+		usage();
+
+	dev = argv[0];
+	dir = argv[1];
+
+	(void)checkpath(dir, mntpath);
+	(void)rmslashes(dev, dev);
+
+	build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1);
+	build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1);
+	build_iovec(&iov, &iovlen, "from", dev, (size_t)-1);
+	build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
+	
+	ret = nmount(iov, iovlen, mntflags);
+	if (ret < 0)
+		err(1, "%s %s", dev, errmsg);
+
+	return (ret);
+}
Index: extern.h
===================================================================
RCS file: /home/cvs/src/sbin/mount/extern.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/mount/extern.h -L sbin/mount/extern.h -u -r1.1.1.1 -r1.2
--- sbin/mount/extern.h
+++ sbin/mount/extern.h
@@ -23,12 +23,11 @@
  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  *
- * $FreeBSD: src/sbin/mount/extern.h,v 1.4 2002/03/21 13:14:19 imp Exp $
+ * $FreeBSD: src/sbin/mount/extern.h,v 1.7 2005/11/23 23:22:56 rodrigc Exp $
  */
 
 /* vfslist.c */
 int checkvfsname(const char *, const char **);
 const char **makevfslist(char *);
 
-/* mount_ufs.c */
-int mount_ufs(int, char *const *);
+int mount_fs(const char *, int, char *[]);
Index: mount.c
===================================================================
RCS file: /home/cvs/src/sbin/mount/mount.c,v
retrieving revision 1.1.1.2
retrieving revision 1.2
diff -L sbin/mount/mount.c -L sbin/mount/mount.c -u -r1.1.1.2 -r1.2
--- sbin/mount/mount.c
+++ sbin/mount/mount.c
@@ -38,7 +38,7 @@
 static char sccsid[] = "@(#)mount.c	8.25 (Berkeley) 5/8/95";
 #endif
 static const char rcsid[] =
-  "$FreeBSD: src/sbin/mount/mount.c,v 1.69.2.1 2006/01/24 15:27:25 pjd Exp $";
+  "$FreeBSD: src/sbin/mount/mount.c,v 1.96 2007/06/25 05:06:54 rafan Exp $";
 #endif /* not lint */
 
 #include <sys/param.h>
@@ -58,6 +58,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <libutil.h>
 
 #include "extern.h"
 #include "mntopts.h"
@@ -74,7 +75,7 @@
 int	hasopt(const char *, const char *);
 int	ismounted(struct fstab *, struct statfs *, int);
 int	isremountable(const char *);
-void	mangle(char *, int *, const char **);
+void	mangle(char *, int *, char *[]);
 char   *update_options(char *, char *, int);
 int	mountfs(const char *, const char *, const char *,
 			int, const char *, const char *);
@@ -106,6 +107,7 @@
 	{ MNT_SOFTDEP,		"soft-updates" },
 	{ MNT_MULTILABEL,	"multilabel" },
 	{ MNT_ACLS,		"acls" },
+	{ MNT_GJOURNAL,		"gjournal" },
 	{ 0, NULL }
 };
 
@@ -120,24 +122,124 @@
 	0
 };
 
+static const char userquotaeq[] = "userquota=";
+static const char groupquotaeq[] = "groupquota=";
+
+static int
+use_mountprog(const char *vfstype)
+{
+	/* XXX: We need to get away from implementing external mount
+	 *      programs for every filesystem, and move towards having
+	 *	each filesystem properly implement the nmount() system call.
+	 */
+	unsigned int i;
+	const char *fs[] = {
+	"cd9660", "mfs", "msdosfs", "nfs", "nfs4", "ntfs",
+	"nwfs", "nullfs", "portalfs", "smbfs", "udf", "unionfs",
+	NULL
+	};
+
+	for (i = 0; fs[i] != NULL; ++i) {
+		if (strcmp(vfstype, fs[i]) == 0)
+			return (1);
+	}
+	
+	return (0);
+}
+
+static int
+exec_mountprog(const char *name, const char *execname, char *const argv[])
+{
+	pid_t pid;
+	int status;
+
+	switch (pid = fork()) {
+	case -1:				/* Error. */
+		warn("fork");
+		exit (1);
+	case 0:					/* Child. */
+		/* Go find an executable. */
+		execvP(execname, _PATH_SYSPATH, argv);
+		if (errno == ENOENT) {
+			warn("exec %s not found in %s", execname,
+			    _PATH_SYSPATH);
+		}
+		exit(1);
+	default:				/* Parent. */
+		if (waitpid(pid, &status, 0) < 0) {
+			warn("waitpid");
+			return (1);
+		}
+
+		if (WIFEXITED(status)) {
+			if (WEXITSTATUS(status) != 0)
+				return (WEXITSTATUS(status));
+		} else if (WIFSIGNALED(status)) {
+			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
+			return (1);
+		}
+		break;
+	}
+
+	return (0);
+}
+
+static int
+specified_ro(const char *arg)
+{
+	char *optbuf, *opt;
+	int ret = 0;
+
+	optbuf = strdup(arg);
+	if (optbuf == NULL)
+		 err(1, NULL);
+
+	for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
+		if (strcmp(opt, "ro") == 0) {
+			ret = 1;
+			break;
+		}
+	}
+	free(optbuf);
+	return (ret);
+}
+
+static void
+restart_mountd(void)
+{
+	struct pidfh *pfh;
+	pid_t mountdpid; 
+
+	pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid);
+	if (pfh != NULL) {
+		/* Mountd is not running. */
+		pidfile_remove(pfh);
+		return;
+	}
+	if (errno != EEXIST) {
+		/* Cannot open pidfile for some reason. */
+		return;
+	}
+	/* We have mountd(8) PID in mountdpid varible, let's signal it. */
+	if (kill(mountdpid, SIGHUP) == -1)
+		err(1, "signal mountd");
+}
+
 int
-main(argc, argv)
-	int argc;
-	char * const argv[];
+main(int argc, char *argv[])
 {
 	const char *mntfromname, **vfslist, *vfstype;
 	struct fstab *fs;
 	struct statfs *mntbuf;
-	FILE *mountdfp;
-	pid_t pid;
-	int all, ch, i, init_flags, mntsize, rval, have_fstab;
+	int all, ch, i, init_flags, late, mntsize, rval, have_fstab, ro;
 	char *cp, *ep, *options;
 
-	all = init_flags = 0;
+	all = init_flags = late = 0;
+	ro = 0;
 	options = NULL;
 	vfslist = NULL;
 	vfstype = "ufs";
-	while ((ch = getopt(argc, argv, "adF:fo:prwt:uv")) != -1)
+	while ((ch = getopt(argc, argv, "adF:flo:prt:uvw")) != -1)
 		switch (ch) {
 		case 'a':
 			all = 1;
@@ -151,9 +253,15 @@
 		case 'f':
 			init_flags |= MNT_FORCE;
 			break;
+		case 'l':
+			late = 1;
+			break;
 		case 'o':
-			if (*optarg)
+			if (*optarg) {
 				options = catopt(options, optarg);
+				if (specified_ro(optarg))
+					ro = 1;
+			}
 			break;
 		case 'p':
 			fstab_style = 1;
@@ -161,6 +269,7 @@
 			break;
 		case 'r':
 			options = catopt(options, "ro");
+			ro = 1;
 			break;
 		case 't':
 			if (vfslist != NULL)
@@ -189,6 +298,9 @@
 	(strcmp(type, FSTAB_RO) &&					\
 	    strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
 
+	if ((init_flags & MNT_UPDATE) && (ro == 0))
+		options = catopt(options, "noro");
+ 
 	rval = 0;
 	switch (argc) {
 	case 0:
@@ -202,6 +314,8 @@
 					continue;
 				if (hasopt(fs->fs_mntops, "noauto"))
 					continue;
+				if (hasopt(fs->fs_mntops, "late") && !late)
+					continue;
 				if (!(init_flags & MNT_UPDATE) &&
 				    ismounted(fs, mntbuf, mntsize))
 					continue;
@@ -316,24 +430,16 @@
 
 	/*
 	 * If the mount was successfully, and done by root, tell mountd the
-	 * good news.  Pid checks are probably unnecessary, but don't hurt.
+	 * good news.
 	 */
-	if (rval == 0 && getuid() == 0 &&
-	    (mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
-		if (fscanf(mountdfp, "%d", &pid) == 1 &&
-		     pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
-			err(1, "signal mountd");
-		(void)fclose(mountdfp);
-	}
+	if (rval == 0 && getuid() == 0)
+		restart_mountd();
 
 	exit(rval);
 }
 
 int
-ismounted(fs, mntbuf, mntsize)
-	struct fstab *fs;
-	struct statfs *mntbuf;
-	int mntsize;
+ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize)
 {
 	char realfsfile[PATH_MAX];
 	int i;
@@ -357,8 +463,7 @@
 }
 
 int
-isremountable(vfsname)
-	const char *vfsname;
+isremountable(const char *vfsname)
 {
 	const char **cp;
 
@@ -369,8 +474,7 @@
 }
 
 int
-hasopt(mntopts, option)
-	const char *mntopts, *option;
+hasopt(const char *mntopts, const char *option)
 {
 	int negative, found;
 	char *opt, *optbuf;
@@ -394,35 +498,20 @@
 }
 
 int
-mountfs(vfstype, spec, name, flags, options, mntopts)
-	const char *vfstype, *spec, *name, *options, *mntopts;
-	int flags;
+mountfs(const char *vfstype, const char *spec, const char *name, int flags,
+	const char *options, const char *mntopts)
 {
-	const char *argv[100];
+	char *argv[100];
 	struct statfs sf;
-	pid_t pid;
-	int argc, i, status;
+	int argc, i, ret;
 	char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
 
-#if __GNUC__
-	(void)&optbuf;
-	(void)&name;
-#endif
-
 	/* resolve the mountpoint with realpath(3) */
 	(void)checkpath(name, mntpath);
 	name = mntpath;
 
 	if (mntopts == NULL)
 		mntopts = "";
-	if (options == NULL) {
-		if (*mntopts == '\0') {
-			options = "rw";
-		} else {
-			options = mntopts;
-			mntopts = "";
-		}
-	}
 	optbuf = catopt(strdup(mntopts), options);
 
 	if (strcmp(name, "/") == 0)
@@ -441,8 +530,11 @@
 		optbuf = catopt(optbuf, "update");
 
 	/* Compatibility glue. */
-	if (strcmp(vfstype, "msdos") == 0)
+	if (strcmp(vfstype, "msdos") == 0) {
+		warnx(
+		    "Using \"-t msdosfs\", since \"-t msdos\" is deprecated.");
 		vfstype = "msdosfs";
+	}
 
 	/* Construct the name of the appropriate mount command */
 	(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
@@ -450,72 +542,48 @@
 	argc = 0;
 	argv[argc++] = execname;
 	mangle(optbuf, &argc, argv);
-	argv[argc++] = spec;
-	argv[argc++] = name;
+	argv[argc++] = strdup(spec);
+	argv[argc++] = strdup(name);
 	argv[argc] = NULL;
 
 	if (debug) {
-		(void)printf("exec: mount_%s", vfstype);
+		if (use_mountprog(vfstype))
+			printf("exec: mount_%s", vfstype);
+		else
+			printf("mount -t %s", vfstype);
 		for (i = 1; i < argc; i++)
 			(void)printf(" %s", argv[i]);
 		(void)printf("\n");
 		return (0);
 	}
 
-	switch (pid = fork()) {
-	case -1:				/* Error. */
-		warn("fork");
-		free(optbuf);
-		return (1);
-	case 0:					/* Child. */
-		if (strcmp(vfstype, "ufs") == 0)
-			exit(mount_ufs(argc, (char * const *) argv));
-
-		/* Go find an executable. */
-		execvP(execname, _PATH_SYSPATH, (char * const *)argv);
-		if (errno == ENOENT) {
-			warn("exec mount_%s not found in %s", vfstype,
-			    _PATH_SYSPATH);
-		}
-		exit(1);
-		/* NOTREACHED */
-	default:				/* Parent. */
-		free(optbuf);
+	if (use_mountprog(vfstype)) {
+		ret = exec_mountprog(name, execname, argv);
+	} else {
+		ret = mount_fs(vfstype, argc, argv); 
+	}
 
-		if (waitpid(pid, &status, 0) < 0) {
-			warn("waitpid");
-			return (1);
-		}
+	free(optbuf);
 
-		if (WIFEXITED(status)) {
-			if (WEXITSTATUS(status) != 0)
-				return (WEXITSTATUS(status));
-		} else if (WIFSIGNALED(status)) {
-			warnx("%s: %s", name, sys_siglist[WTERMSIG(status)]);
+	if (verbose) {
+		if (statfs(name, &sf) < 0) {
+			warn("statfs %s", name);
 			return (1);
 		}
-
-		if (verbose) {
-			if (statfs(name, &sf) < 0) {
-				warn("statfs %s", name);
-				return (1);
-			}
-			if (fstab_style)
-				putfsent(&sf);
-			else
-				prmount(&sf);
-		}
-		break;
+		if (fstab_style)
+			putfsent(&sf);
+		else
+			prmount(&sf);
 	}
 
 	return (0);
 }
 
 void
-prmount(sfp)
-	struct statfs *sfp;
+prmount(struct statfs *sfp)
 {
-	int flags, i;
+	int flags;
+	unsigned int i;
 	struct opt *o;
 	struct passwd *pw;
 
@@ -558,8 +626,7 @@
 }
 
 struct statfs *
-getmntpt(name)
-	const char *name;
+getmntpt(const char *name)
 {
 	struct statfs *mntbuf;
 	int i, mntsize;
@@ -574,15 +641,13 @@
 }
 
 char *
-catopt(s0, s1)
-	char *s0;
-	const char *s1;
+catopt(char *s0, const char *s1)
 {
 	size_t i;
 	char *cp;
 
 	if (s1 == NULL || *s1 == '\0')
-		return s0;
+		return (s0);
 
 	if (s0 && *s0) {
 		i = strlen(s0) + strlen(s1) + 1 + 1;
@@ -598,10 +663,7 @@
 }
 
 void
-mangle(options, argcp, argv)
-	char *options;
-	int *argcp;
-	const char **argv;
+mangle(char *options, int *argcp, char *argv[])
 {
 	char *p, *s;
 	int argc;
@@ -609,15 +671,43 @@
 	argc = *argcp;
 	for (s = options; (p = strsep(&s, ",")) != NULL;)
 		if (*p != '\0') {
-			if (*p == '-') {
+			if (strcmp(p, "noauto") == 0) {
+				/*
+				 * Do not pass noauto option to nmount().
+				 * or external mount program.  noauto is
+				 * only used to prevent mounting a filesystem
+				 * when 'mount -a' is specified, and is
+				 * not a real mount option.
+				 */
+				continue;
+			} else if (strcmp(p, "late") == 0) {
+				/*
+				 * "late" is used to prevent certain file
+				 * systems from being mounted before late
+				 * in the boot cycle; for instance,
+				 * loopback NFS mounts can't be mounted
+				 * before mountd starts.
+				 */
+				continue;
+			} else if (strcmp(p, "userquota") == 0) {
+				continue;
+			} else if (strncmp(p, userquotaeq,
+			    sizeof(userquotaeq) - 1) == 0) {
+				continue;
+			} else if (strcmp(p, "groupquota") == 0) {
+				continue;
+			} else if (strncmp(p, groupquotaeq,
+			    sizeof(groupquotaeq) - 1) == 0) {
+				continue;
+			} else if (*p == '-') {
 				argv[argc++] = p;
 				p = strchr(p, '=');
 				if (p != NULL) {
 					*p = '\0';
 					argv[argc++] = p+1;
 				}
-			} else if (strcmp(p, "rw") != 0) {
-				argv[argc++] = "-o";
+			} else {
+				argv[argc++] = strdup("-o");
 				argv[argc++] = p;
 			}
 		}
@@ -627,17 +717,14 @@
 
 
 char *
-update_options(opts, fstab, curflags)
-	char *opts;
-	char *fstab;
-	int curflags;
+update_options(char *opts, char *fstab, int curflags)
 {
 	char *o, *p;
 	char *cur;
 	char *expopt, *newopt, *tmpopt;
 
 	if (opts == NULL)
-		return strdup("");
+		return (strdup(""));
 
 	/* remove meta options from list */
 	remopt(fstab, MOUNT_META_OPTION_FSTAB);
@@ -681,13 +768,11 @@
 	}
 	free(expopt);
 
-	return newopt;
+	return (newopt);
 }
 
 void
-remopt(string, opt)
-	char *string;
- 	const char *opt;
+remopt(char *string, const char *opt)
 {
 	char *o, *p, *r;
 
@@ -709,26 +794,47 @@
 }
 
 void
-usage()
+usage(void)
 {
 
 	(void)fprintf(stderr, "%s\n%s\n%s\n",
-"usage: mount [-adfpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
+"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
 "       mount [-dfpruvw] special | node",
 "       mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
 	exit(1);
 }
 
 void
-putfsent(ent)
-	const struct statfs *ent;
+putfsent(const struct statfs *ent)
 {
 	struct fstab *fst;
 	char *opts;
+	int l;
 
 	opts = flags2opts(ent->f_flags);
-	printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
-	    ent->f_fstypename, opts);
+
+	/*
+	 * "rw" is not a real mount option; this is why we print NULL as "rw"
+	 * if opts is still NULL here.
+	 */
+	l = strlen(ent->f_mntfromname);
+	printf("%s%s%s%s", ent->f_mntfromname,
+	    l < 8 ? "\t" : "",
+	    l < 16 ? "\t" : "",
+	    l < 24 ? "\t" : " ");
+	l = strlen(ent->f_mntonname);
+	printf("%s%s%s%s", ent->f_mntonname,
+	    l < 8 ? "\t" : "",
+	    l < 16 ? "\t" : "",
+	    l < 24 ? "\t" : " ");
+	printf("%s\t", ent->f_fstypename);
+	if (opts == NULL) {
+		printf("%s\t", "rw");
+	} else {
+		l = strlen(opts);
+		printf("%s%s", opts,
+		    l < 8 ? "\t" : " ");
+	}
 	free(opts);
 
 	if ((fst = getfsspec(ent->f_mntfromname)))
@@ -746,15 +852,13 @@
 
 
 char *
-flags2opts(flags)
-	int flags;
+flags2opts(int flags)
 {
 	char *res;
 
 	res = NULL;
 
-	res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw");
-
+	if (flags & MNT_RDONLY)		res = catopt(res, "ro");
 	if (flags & MNT_SYNCHRONOUS)	res = catopt(res, "sync");
 	if (flags & MNT_NOEXEC)		res = catopt(res, "noexec");
 	if (flags & MNT_NOSUID)		res = catopt(res, "nosuid");
@@ -767,6 +871,7 @@
 	if (flags & MNT_SUIDDIR)	res = catopt(res, "suiddir");
 	if (flags & MNT_MULTILABEL)	res = catopt(res, "multilabel");
 	if (flags & MNT_ACLS)		res = catopt(res, "acls");
+	if (flags & MNT_GJOURNAL)	res = catopt(res, "gjournal");
 
-	return res;
+	return (res);
 }
--- sbin/mount/mount_ufs.c
+++ /dev/null
@@ -1,135 +0,0 @@
-/*-
- * Copyright (c) 1993, 1994
- *	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.
- * 4. 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.
- */
-
-#ifndef lint
-static const char copyright[] =
-"@(#) Copyright (c) 1993, 1994\n\
-	The Regents of the University of California.  All rights reserved.\n";
-#endif /* not lint */
-
-#ifndef lint
-#if 0
-static char sccsid[] = "@(#)mount_ufs.c	8.4 (Berkeley) 4/26/95";
-#endif
-static const char rcsid[] =
-  "$FreeBSD: src/sbin/mount/mount_ufs.c,v 1.26 2005/06/10 09:51:40 delphij Exp $";
-#endif /* not lint */
-
-#include <sys/param.h>
-#include <sys/mount.h>
-
-#include <err.h>
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <unistd.h>
-
-#include <ufs/ufs/ufsmount.h>
-
-#include "extern.h"
-#include "mntopts.h"
-
-static void ufs_usage(void);
-
-static struct mntopt mopts[] = {
-	MOPT_STDOPTS,
-	MOPT_ASYNC,
-	MOPT_FORCE,
-	MOPT_SYNC,
-	MOPT_UPDATE,
-	MOPT_SNAPSHOT,
-	MOPT_END
-};
-
-int
-mount_ufs(argc, argv)
-	int argc;
-	char * const argv[];
-{
-	struct ufs_args args;
-	int ch, mntflags;
-	char *fs_name;
-
-	mntflags = 0;
-	optind = optreset = 1;		/* Reset for parse of new argv. */
-	while ((ch = getopt(argc, argv, "o:")) != -1)
-		switch (ch) {
-		case 'o':
-			getmntopts(optarg, mopts, &mntflags, 0);
-			break;
-		case '?':
-		default:
-			ufs_usage();
-		}
-	argc -= optind;
-	argv += optind;
-
-	if (argc != 2)
-		ufs_usage();
-
-        args.fspec = argv[0];		/* The name of the device file. */
-	fs_name = argv[1];		/* The mount point. */
-
-#define DEFAULT_ROOTUID	-2
-	args.export.ex_root = DEFAULT_ROOTUID;
-	if (mntflags & MNT_RDONLY)
-		args.export.ex_flags = MNT_EXRDONLY;
-	else
-		args.export.ex_flags = 0;
-
-	if (mount("ufs", fs_name, mntflags, &args) < 0) {
-		switch (errno) {
-		case EMFILE:
-			warnx("%s on %s: mount table full",
-				args.fspec, fs_name);
-			break;
-		case EINVAL:
-			if (mntflags & MNT_UPDATE)
-				warnx(
-		"%s on %s: specified device does not match mounted device",
-					args.fspec, fs_name);
-			else
-				warnx("%s on %s: incorrect super block",
-					args.fspec, fs_name);
-			break;
-		default:
-			warn("%s", args.fspec);
-			break;
-		}
-		return (1);
-	}
-	return (0);
-}
-
-static void
-ufs_usage()
-{
-	(void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
-	exit(1);
-}
Index: mntopts.h
===================================================================
RCS file: /home/cvs/src/sbin/mount/mntopts.h,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/mount/mntopts.h -L sbin/mount/mntopts.h -u -r1.1.1.1 -r1.2
--- sbin/mount/mntopts.h
+++ sbin/mount/mntopts.h
@@ -27,12 +27,12 @@
  * SUCH DAMAGE.
  *
  *	@(#)mntopts.h	8.7 (Berkeley) 3/29/95
- * $FreeBSD: src/sbin/mount/mntopts.h,v 1.26 2005/06/10 09:51:40 delphij Exp $
+ * $FreeBSD: src/sbin/mount/mntopts.h,v 1.29 2005/12/02 03:55:02 rodrigc Exp $
  */
 
 struct mntopt {
 	const char *m_option;	/* option name */
-	int m_inverse;		/* if a negative option, e.g. "dev" */
+	int m_inverse;		/* if a negative option, e.g. "atime" */
 	int m_flag;		/* bit to set, e.g. MNT_RDONLY */
 	int m_altloc;		/* 1 => set bit in altflags */
 };
@@ -40,7 +40,6 @@
 /* User-visible MNT_ flags. */
 #define MOPT_ASYNC		{ "async",	0, MNT_ASYNC, 0 }
 #define MOPT_NOATIME		{ "atime",	1, MNT_NOATIME, 0 }
-#define MOPT_NODEV		{ "dev",	1, MNT_NODEV, 0 }
 #define MOPT_NOEXEC		{ "exec",	1, MNT_NOEXEC, 0 }
 #define MOPT_NOSUID		{ "suid",	1, MNT_NOSUID, 0 }
 #define MOPT_NOSYMFOLLOW	{ "symfollow",  1, MNT_NOSYMFOLLOW, 0 }
@@ -79,7 +78,6 @@
 	MOPT_GROUPQUOTA,						\
 	MOPT_FSTAB_COMPAT,						\
 	MOPT_NOATIME,							\
-	MOPT_NODEV,							\
 	MOPT_NOEXEC,							\
 	MOPT_SUIDDIR,		/* must be before MOPT_NOSUID */	\
 	MOPT_NOSUID,							\
@@ -95,4 +93,5 @@
 void rmslashes(char *, char *);
 void checkpath(const char *, char resolved_path[]);
 extern int getmnt_silent;
-void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len);
+void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len);
+void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...);
Index: getmntopts.3
===================================================================
RCS file: /home/cvs/src/sbin/mount/getmntopts.3,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/mount/getmntopts.3 -L sbin/mount/getmntopts.3 -u -r1.1.1.1 -r1.2
--- sbin/mount/getmntopts.3
+++ sbin/mount/getmntopts.3
@@ -26,7 +26,7 @@
 .\" SUCH DAMAGE.
 .\"
 .\"	@(#)getmntopts.3	8.3 (Berkeley) 3/30/95
-.\" $FreeBSD: src/sbin/mount/getmntopts.3,v 1.13 2004/04/09 19:58:30 markm Exp $
+.\" $FreeBSD: src/sbin/mount/getmntopts.3,v 1.14 2005/11/24 14:27:53 ru Exp $
 .\"
 .Dd March 30, 1995
 .Dt GETMNTOPTS 3
@@ -37,7 +37,10 @@
 .Sh SYNOPSIS
 .Fd #include \&"mntopts.h"
 .Ft void
-.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp" "int *altflagp"
+.Fo getmntopts
+.Fa "const char *options" "const struct mntopt *mopts"
+.Fa "int *flagp" "int *altflagp"
+.Fc
 .Sh DESCRIPTION
 The
 .Fn getmntopts
Index: mount.8
===================================================================
RCS file: /home/cvs/src/sbin/mount/mount.8,v
retrieving revision 1.2
retrieving revision 1.3
diff -L sbin/mount/mount.8 -L sbin/mount/mount.8 -u -r1.2 -r1.3
--- sbin/mount/mount.8
+++ sbin/mount/mount.8
@@ -26,9 +26,9 @@
 .\" SUCH DAMAGE.
 .\"
 .\"     @(#)mount.8	8.8 (Berkeley) 6/16/94
-.\" $FreeBSD: src/sbin/mount/mount.8,v 1.73.2.1 2006/01/13 20:05:59 pav Exp $
+.\" $FreeBSD: src/sbin/mount/mount.8,v 1.82.2.1 2007/12/06 08:08:04 jhb Exp $
 .\"
-.Dd November 26, 2004
+.Dd July 12, 2006
 .Dt MOUNT 8
 .Os
 .Sh NAME
@@ -36,26 +36,26 @@
 .Nd mount file systems
 .Sh SYNOPSIS
 .Nm
-.Op Fl adfpruvw
+.Op Fl adflpruvw
 .Op Fl F Ar fstab
 .Op Fl o Ar options
-.Op Fl t Ar ufs | external_type
+.Op Fl t Cm ufs | Ar external_type
 .Nm
 .Op Fl dfpruvw
 .Ar special | node
 .Nm
 .Op Fl dfpruvw
 .Op Fl o Ar options
-.Op Fl t Ar ufs | external_type
+.Op Fl t Cm ufs | Ar external_type
 .Ar special node
 .Sh DESCRIPTION
 The
 .Nm
 utility calls the
-.Xr mount 2
+.Xr nmount 2
 system call to prepare and graft a
-.Ar "special device"
-or the remote node (rhost:path) on to the file system tree at the point
+.Ar special
+device or the remote node (rhost:path) on to the file system tree at the point
 .Ar node .
 If either
 .Ar special
@@ -77,8 +77,13 @@
 .Xr fstab 5
 are mounted.
 Exceptions are those marked as
-.Dq noauto ,
-excluded by the
+.Dq Li noauto ,
+those marked as
+.Dq Li late
+(unless the
+.Fl l
+option was specified),
+those excluded by the
 .Fl t
 flag (see below), or if they are already mounted (except the
 root file system which is always remounted to preserve
@@ -101,6 +106,11 @@
 Also
 forces the R/W mount of an unclean file system (dangerous; use with
 caution).
+.It Fl l
+When used in conjunction with the
+.Fl a
+option, also mount those file systems which are marked as
+.Dq Li late .
 .It Fl o
 Options are specified with a
 .Fl o
@@ -121,9 +131,12 @@
 to the file system should be done asynchronously.
 This is a
 .Em dangerous
-flag to set,
-and should not be used unless you are prepared to recreate the file
-system should your system crash.
+flag to set, since it does not guarantee that the file system structure
+on the disk will remain consistent.
+For this reason, the
+.Cm async
+flag should be used sparingly, and only when some data recovery
+mechanism is present.
 .It Cm current
 When used with the
 .Fl u
@@ -142,6 +155,14 @@
 flag, this is the same as specifying all the options listed in the
 .Xr fstab 5
 file for the file system.
+.It Cm late
+This file system should be skipped when
+.Nm
+is run with the
+.Fl a
+flag but without the
+.Fl l
+flag.
 .It Cm multilabel
 Enable multi-label Mandatory Access Control, or MAC, on the specified file
 system.
@@ -200,10 +221,6 @@
 The same as
 .Fl r ;
 mount the file system read-only (even the super-user may not write it).
-.It Cm sync
-All
-.Tn I/O
-to the file system should be done synchronously.
 .It Cm snapshot
 This option allows a snapshot of the specified file system to be taken.
 The
@@ -289,6 +306,10 @@
 See
 .Xr chmod 2
 for more information.
+.It Cm sync
+All
+.Tn I/O
+to the file system should be done synchronously.
 .It Cm update
 The same as
 .Fl u ;
@@ -347,12 +368,12 @@
 argument to the
 .Fl o
 option.
-.It Fl t Ar ufs | external_type
+.It Fl t Cm ufs | Ar external_type
 The argument following the
 .Fl t
 is used to indicate the file system type.
 The type
-.Ar ufs
+.Cm ufs
 is the default.
 The
 .Fl t
@@ -361,7 +382,7 @@
 file systems of the specified type.
 More than one type may be specified in a comma separated list.
 The list of file system types can be prefixed with
-.Dq no
+.Dq Li no
 to specify the file system types for which action should
 .Em not
 be taken.
@@ -377,13 +398,38 @@
 and
 .Tn NULLFS .
 .Pp
-If the type is not one of the internally known types,
+The default behavior of
+.Nm
+is to pass the
+.Fl t
+option directly to the
+.Xr nmount 2
+system call in the
+.Li fstype
+option.
+.Pp
+However, for the following file system types:
+.Cm cd9660 ,
+.Cm mfs ,
+.Cm msdosfs ,
+.Cm nfs ,
+.Cm nfs4 ,
+.Cm ntfs ,
+.Cm nwfs ,
+.Cm nullfs ,
+.Cm portalfs ,
+.Cm smbfs ,
+.Cm udf ,
+and
+.Cm unionfs ,
 .Nm
-will attempt to execute a program in
+will not call
+.Xr nmount 2
+directly and will instead attempt to execute a program in
 .Pa /sbin/mount_ Ns Sy XXX
 where
 .Sy XXX
-is replaced by the type name.
+is replaced by the file system type name.
 For example, nfs file systems are mounted by the program
 .Pa /sbin/mount_nfs .
 .Pp
@@ -449,24 +495,20 @@
 .Sh SEE ALSO
 .Xr getfacl 1 ,
 .Xr setfacl 1 ,
-.Xr mount 2 ,
+.Xr nmount 2 ,
 .Xr acl 3 ,
 .Xr mac 4 ,
+.Xr ext2fs 5 ,
 .Xr fstab 5 ,
+.Xr procfs 5 ,
 .Xr kldload 8 ,
 .Xr mount_cd9660 8 ,
-.Xr mount_devfs 8 ,
-.Xr mount_ext2fs 8 ,
-.Xr mount_fdescfs 8 ,
-.Xr mount_linprocfs 8 ,
 .Xr mount_msdosfs 8 ,
 .Xr mount_nfs 8 ,
 .Xr mount_ntfs 8 ,
 .Xr mount_nullfs 8 ,
 .Xr mount_nwfs 8 ,
 .Xr mount_portalfs 8 ,
-.Xr mount_procfs 8 ,
-.Xr mount_reiserfs 8 ,
 .Xr mount_smbfs 8 ,
 .Xr mount_std 8 ,
 .Xr mount_udf 8 ,
Index: Makefile
===================================================================
RCS file: /home/cvs/src/sbin/mount/Makefile,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/mount/Makefile -L sbin/mount/Makefile -u -r1.1.1.1 -r1.2
--- sbin/mount/Makefile
+++ sbin/mount/Makefile
@@ -1,10 +1,13 @@
 #	@(#)Makefile	8.6 (Berkeley) 5/8/95
-# $FreeBSD: src/sbin/mount/Makefile,v 1.15 2004/04/26 15:13:45 bmilekic Exp $
+# $FreeBSD: src/sbin/mount/Makefile,v 1.19 2007/02/02 23:58:10 pjd Exp $
 
 PROG=	mount
-SRCS=	mount.c mount_ufs.c getmntopts.c vfslist.c
-WARNS?=	0
+SRCS=	mount.c mount_fs.c getmntopts.c vfslist.c
+WARNS?=	6
 MAN=	mount.8
 # We do NOT install the getmntopts.3 man page.
 
+DPADD=	${LIBUTIL}
+LDADD=	-lutil
+
 .include <bsd.prog.mk>
Index: getmntopts.c
===================================================================
RCS file: /home/cvs/src/sbin/mount/getmntopts.c,v
retrieving revision 1.1.1.1
retrieving revision 1.2
diff -L sbin/mount/getmntopts.c -L sbin/mount/getmntopts.c -u -r1.1.1.1 -r1.2
--- sbin/mount/getmntopts.c
+++ sbin/mount/getmntopts.c
@@ -33,14 +33,17 @@
 #endif /* not lint */
 #endif
 #include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sbin/mount/getmntopts.c,v 1.15 2004/11/25 16:14:27 delphij Exp $");
+__FBSDID("$FreeBSD: src/sbin/mount/getmntopts.c,v 1.18 2005/11/14 17:39:00 rodrigc Exp $");
 
 #include <sys/param.h>
+#include <sys/mount.h>
 #include <sys/stat.h>
 #include <sys/uio.h>
 
 #include <err.h>
 #include <errno.h>
+#include <stdarg.h>
+#include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
 #include <sysexits.h>
@@ -50,11 +53,8 @@
 int getmnt_silent = 0;
 
 void
-getmntopts(options, m0, flagp, altflagp)
-	const char *options;
-	const struct mntopt *m0;
-	int *flagp;
-	int *altflagp;
+getmntopts(const char *options, const struct mntopt *m0, int *flagp,
+	int *altflagp)
 {
 	const struct mntopt *m;
 	int negative, len;
@@ -105,9 +105,7 @@
 }
 
 void
-rmslashes(rrpin, rrpout)
-	char *rrpin;
-	char *rrpout;
+rmslashes(char *rrpin, char *rrpout)
 {
 	char *rrpoutstart;
 
@@ -127,9 +125,7 @@
 }
 
 void
-checkpath(path, resolved)
-	const char *path;
-	char *resolved;
+checkpath(const char *path, char *resolved)
 {
 	struct stat sb;
 
@@ -141,7 +137,8 @@
 }
 
 void
-build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len)
+build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val,
+	    size_t len)
 {
 	int i;
 
@@ -157,8 +154,29 @@
 	(*iov)[i].iov_len = strlen(name) + 1;
 	i++;
 	(*iov)[i].iov_base = val;
-	if (len < 0)
-		len = strlen(val) + 1;
-	(*iov)[i].iov_len = len;
+	if (len == (size_t)-1) {
+		if (val != NULL)
+			len = strlen(val) + 1;
+		else
+			len = 0;
+	}
+	(*iov)[i].iov_len = (int)len;
 	*iovlen = ++i;
 }
+
+/*
+ * This function is needed for compatibility with parameters
+ * which used to use the mount_argf() command for the old mount() syscall.
+ */
+void
+build_iovec_argf(struct iovec **iov, int *iovlen, const char *name,
+    const char *fmt, ...)
+{
+	va_list ap;
+	char val[255] = { 0 };
+
+	va_start(ap, fmt);
+	vsnprintf(val, sizeof(val), fmt, ap);  
+	va_end(ap);
+	build_iovec(iov, iovlen, name, strdup(val), (size_t)-1);
+}


More information about the Midnightbsd-cvs mailing list