aboutsummaryrefslogtreecommitdiff
path: root/sbin/mount
diff options
context:
space:
mode:
authorSteve Price <steve@FreeBSD.org>1997-08-24 21:02:51 +0000
committerSteve Price <steve@FreeBSD.org>1997-08-24 21:02:51 +0000
commitfba1c154b289460fbbbfa7c2da35328882dbd595 (patch)
tree4542ac0e257b9dcc355baeddafdfb7a6165fad0e /sbin/mount
parent8ee0110a449904883ddcc5dea6f61a690bab1d5a (diff)
downloadsrc-fba1c154b289460fbbbfa7c2da35328882dbd595.tar.gz
src-fba1c154b289460fbbbfa7c2da35328882dbd595.zip
Try to avoid mounting filesystems multiple times. Also while
I'm here do some -Wall cleaning. PR: kern/1839 Reviewed and corrected by: joerg
Notes
Notes: svn path=/head/; revision=28671
Diffstat (limited to 'sbin/mount')
-rw-r--r--sbin/mount/Makefile2
-rw-r--r--sbin/mount/getmntopts.c6
-rw-r--r--sbin/mount/mntopts.h4
-rw-r--r--sbin/mount/mount.88
-rw-r--r--sbin/mount/mount.c84
-rw-r--r--sbin/mount/mount_ufs.c12
-rw-r--r--sbin/mount/vfslist.c12
7 files changed, 99 insertions, 29 deletions
diff --git a/sbin/mount/Makefile b/sbin/mount/Makefile
index a06b102ee7c4..d6a589fb1e6d 100644
--- a/sbin/mount/Makefile
+++ b/sbin/mount/Makefile
@@ -1,9 +1,11 @@
# @(#)Makefile 8.6 (Berkeley) 5/8/95
+# $Id$
PROG= mount
SRCS= mount.c mount_ufs.c getmntopts.c vfslist.c
MAN8= mount.8
# We do NOT install the getmntopts.3 man page.
CFLAGS+= -D_NEW_VFSCONF
+NOSHARED= yes
.include <bsd.prog.mk>
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c
index f0cd27c058a7..733ef7f7acc9 100644
--- a/sbin/mount/getmntopts.c
+++ b/sbin/mount/getmntopts.c
@@ -32,7 +32,12 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
+#else
+static const char rcsid[] =
+ "$Id$";
+#endif
#endif /* not lint */
#include <sys/param.h>
@@ -44,6 +49,7 @@ static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
#include <stdlib.h>
#include <string.h>
+#include "extern.h"
#include "mntopts.h"
int getmnt_silent = 0;
diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h
index 8ca12603d771..4a595ee47dd0 100644
--- a/sbin/mount/mntopts.h
+++ b/sbin/mount/mntopts.h
@@ -31,6 +31,7 @@
* SUCH DAMAGE.
*
* @(#)mntopts.h 8.7 (Berkeley) 3/29/95
+ * $Id$
*/
struct mntopt {
@@ -77,6 +78,3 @@ struct mntopt {
MOPT_NOSUID, \
MOPT_RDONLY, \
MOPT_UNION
-
-void getmntopts __P((const char *, const struct mntopt *, int *, int *));
-extern int getmnt_silent;
diff --git a/sbin/mount/mount.8 b/sbin/mount/mount.8
index ca2652997dfc..4468340ad69d 100644
--- a/sbin/mount/mount.8
+++ b/sbin/mount/mount.8
@@ -30,7 +30,7 @@
.\" SUCH DAMAGE.
.\"
.\" @(#)mount.8 8.8 (Berkeley) 6/16/94
-.\" $Id: mount.8,v 1.16 1997/08/24 02:27:08 steve Exp $
+.\" $Id: mount.8,v 1.17 1997/08/24 17:51:12 joerg Exp $
.\"
.Dd June 16, 1994
.Dt MOUNT 8
@@ -79,9 +79,11 @@ The options are as follows:
All the filesystems described in
.Xr fstab 5
are mounted.
-Exceptions are those marked as ``noauto'' or are excluded by the
+Exceptions are those marked as ``noauto'', excluded by the
.Fl t
-flag (see below).
+flag (see below), or if they are already mounted (except the
+root filesystem which is always remounted to preserve
+traditional single user mode behavior).
.It Fl d
Causes everything to be done except for the actual system call.
This option is useful in conjunction with the
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index b0d010562fca..bc1c8f43c6f1 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -1,4 +1,4 @@
-/*
+/*-
* Copyright (c) 1980, 1989, 1993, 1994
* The Regents of the University of California. All rights reserved.
*
@@ -32,13 +32,18 @@
*/
#ifndef lint
-static char copyright[] =
+static const char copyright[] =
"@(#) Copyright (c) 1980, 1989, 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.c 8.25 (Berkeley) 5/8/95";
+#else
+static const char rcsid[] =
+ "$Id$";
+#endif
#endif /* not lint */
#include <sys/param.h>
@@ -56,17 +61,17 @@ static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
#include <string.h>
#include <unistd.h>
+#include "extern.h"
#include "pathnames.h"
int debug, fstab_style, verbose;
-int checkvfsname __P((const char *, const char **));
char *catopt __P((char *, const char *));
struct statfs
*getmntpt __P((const char *));
int hasopt __P((const char *, const char *));
-const char
- **makevfslist __P((char *));
+int ismounted __P((struct fstab *, struct statfs *, int));
+int isremountable __P((const char *));
void mangle __P((char *, int *, const char **));
int mountfs __P((const char *, const char *, const char *,
int, const char *, const char *));
@@ -74,9 +79,6 @@ void prmount __P((struct statfs *));
void putfsent __P((const struct statfs *));
void usage __P((void));
-/* From mount_ufs.c. */
-int mount_ufs __P((int, char * const *));
-
/* Map from mount otions to printable formats. */
static struct opt {
int o_opt;
@@ -96,6 +98,17 @@ static struct opt {
{ NULL }
};
+/*
+ * List of VFS types that can be remounted without becoming mounted on top
+ * of each other.
+ * XXX Is this list correct?
+ */
+static const char *
+remountable_fs_names[] = {
+ "ufs", "ffs", "lfs", "ext2fs",
+ 0
+};
+
int
main(argc, argv)
int argc;
@@ -165,7 +178,9 @@ main(argc, argv)
rval = 0;
switch (argc) {
case 0:
- if (all)
+ if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
+ err(1, "getmntinfo");
+ if (all) {
while ((fs = getfsent()) != NULL) {
if (BADTYPE(fs->fs_type))
continue;
@@ -173,22 +188,20 @@ main(argc, argv)
continue;
if (hasopt(fs->fs_mntops, "noauto"))
continue;
+ if (ismounted(fs, mntbuf, mntsize))
+ continue;
if (mountfs(fs->fs_vfstype, fs->fs_spec,
fs->fs_file, init_flags, options,
fs->fs_mntops))
rval = 1;
}
- else if (fstab_style) {
- if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
- err(1, "getmntinfo");
+ } else if (fstab_style) {
for (i = 0; i < mntsize; i++) {
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
putfsent(&mntbuf[i]);
}
} else {
- if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
- err(1, "getmntinfo");
for (i = 0; i < mntsize; i++) {
if (checkvfsname(mntbuf[i].f_fstypename,
vfslist))
@@ -246,7 +259,7 @@ main(argc, argv)
*/
if (rval == 0 && getuid() == 0 &&
(mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
- if (fscanf(mountdfp, "%ld", &pid) == 1 &&
+ if (fscanf(mountdfp, "%d", &pid) == 1 &&
pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
err(1, "signal mountd");
(void)fclose(mountdfp);
@@ -256,6 +269,38 @@ main(argc, argv)
}
int
+ismounted(fs, mntbuf, mntsize)
+ struct fstab *fs;
+ struct statfs *mntbuf;
+ int mntsize;
+{
+ int i;
+
+ if (fs->fs_file[0] == '/' && fs->fs_file[1] == '\0')
+ /* the root file system can always be remounted */
+ return (0);
+
+ for (i = mntsize - 1; i >= 0; --i)
+ if (strcmp(fs->fs_file, mntbuf[i].f_mntonname) == 0 &&
+ (!isremountable(fs->fs_vfstype) ||
+ strcmp(fs->fs_spec, mntbuf[i].f_mntfromname) == 0))
+ return (1);
+ return (0);
+}
+
+int
+isremountable(vfsname)
+ const char *vfsname;
+{
+ const char **cp;
+
+ for (cp = remountable_fs_names; *cp; cp++)
+ if (strcmp(*cp, vfsname) == 0)
+ return (1);
+ return (0);
+}
+
+int
hasopt(mntopts, option)
const char *mntopts, *option;
{
@@ -298,6 +343,11 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
int argc, i, status;
char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
+#if __GNUC__
+ (void)&optbuf;
+ (void)&name;
+#endif
+
if (realpath(name, mntpath) != NULL && stat(mntpath, &sb) == 0) {
if (!S_ISDIR(sb.st_mode)) {
warnx("%s: Not a directory", mntpath);
@@ -546,9 +596,9 @@ putfsent(ent)
if (ent->f_flags & MNT_NOATIME)
printf(",noatime");
- if (fst = getfsspec(ent->f_mntfromname))
+ if ((fst = getfsspec(ent->f_mntfromname)))
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
- else if (fst = getfsfile(ent->f_mntonname))
+ else if ((fst = getfsfile(ent->f_mntonname)))
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
else if (ent->f_type == MOUNT_UFS)
printf("\t1 1\n");
diff --git a/sbin/mount/mount_ufs.c b/sbin/mount/mount_ufs.c
index b6344d125963..58a1addc2332 100644
--- a/sbin/mount/mount_ufs.c
+++ b/sbin/mount/mount_ufs.c
@@ -32,13 +32,18 @@
*/
#ifndef lint
-static char copyright[] =
+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";
+#else
+static const char rcsid[] =
+ "$Id$";
+#endif
#endif /* not lint */
#include <sys/param.h>
@@ -53,9 +58,10 @@ static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95";
#include <ufs/ufs/ufsmount.h>
+#include "extern.h"
#include "mntopts.h"
-void ufs_usage __P((void));
+static void ufs_usage __P((void));
static struct mntopt mopts[] = {
MOPT_STDOPTS,
@@ -143,7 +149,7 @@ mount_ufs(argc, argv)
return (0);
}
-void
+static void
ufs_usage()
{
(void)fprintf(stderr, "usage: mount_ufs [-o options] special node\n");
diff --git a/sbin/mount/vfslist.c b/sbin/mount/vfslist.c
index 1a00a235fd6c..15edaf3ec1aa 100644
--- a/sbin/mount/vfslist.c
+++ b/sbin/mount/vfslist.c
@@ -1,4 +1,4 @@
-/*
+/*-
* Copyright (c) 1995
* The Regents of the University of California. All rights reserved.
*
@@ -32,15 +32,21 @@
*/
#ifndef lint
+#if 0
static char sccsid[] = "@(#)vfslist.c 8.1 (Berkeley) 5/8/95";
+#else
+static const char rcsid[] =
+ "$Id$";
+#endif
#endif /* not lint */
+#include <err.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
-int checkvfsname __P((const char *, const char **));
-const char **makevfslist __P((char *));
+#include "extern.h"
+
static int skipvfs;
int