Merge from Lite2

- use new getvfsbyname() interface and mount(2) interface

**DANGER WILL ROBINSON!!**  You must be running a -current kernel
from within a week or so in order for this to work!
This commit is contained in:
peter 1997-03-11 12:28:00 +00:00
parent d2924d1b17
commit 2feef020b3
14 changed files with 298 additions and 312 deletions

View File

@ -1,8 +1,9 @@
# @(#)Makefile 8.5 (Berkeley) 3/27/94
# @(#)Makefile 8.6 (Berkeley) 5/8/95
PROG= mount
SRCS= mount.c mount_ufs.c getmntopts.c
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
.include <bsd.prog.mk>

View File

@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)getmntopts.3 8.1 (Berkeley) 3/27/94
.\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95
.\"
.Dd March 27, 1994
.Dd March 30, 1995
.Dt GETMNTOPTS 3
.Os BSD 4.4
.Sh NAME
@ -62,7 +62,7 @@ or
.Dv m_altloc
field of the option's table entry)
are updated.
The flag word is not initialized by
The flag words are not initialized by
.Nm getmntopt .
The table,
.Dv mopts ,
@ -154,16 +154,21 @@ struct mntopt mopts[] = {
};
...
mntflags = 0;
mntflags = mntaltflags = 0;
...
getmntopts(options, mopts, &mntflags)
getmntopts(options, mopts, &mntflags, &mntaltflags);
...
.Ed
.Sh DIAGNOSTICS
The
If the external integer variable
.Dv getmnt_silent
is non-zero then the
.Nm getmntopts
function displays an error message and exits if an
unrecognized option is encountered.
By default
.Dv getmnt_silent
is zero.
.Sh SEE ALSO
.Xr err 3 ,
.Xr mount 8

View File

@ -32,7 +32,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94";
static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
#endif /* not lint */
#include <sys/param.h>
@ -57,7 +57,7 @@ getmntopts(options, m0, flagp, altflagp)
{
const struct mntopt *m;
int negative, len;
char *opt, *optbuf;
char *opt, *optbuf, *p;
int *thisflagp;
/* Copy option string, since it is about to be torn asunder... */
@ -72,6 +72,14 @@ getmntopts(options, m0, flagp, altflagp)
} else
negative = 0;
/*
* for options with assignments in them (ie. quotas)
* ignore the assignment as it's handled elsewhere
*/
p = strchr(opt, '=');
if (p)
*p = '\0';
/* Scan option table. */
for (m = m0; m->m_option != NULL; ++m) {
len = strlen(m->m_option);
@ -89,7 +97,7 @@ getmntopts(options, m0, flagp, altflagp)
*thisflagp |= m->m_flag;
else
*thisflagp &= ~m->m_flag;
} else if(!getmnt_silent) {
} else if (!getmnt_silent) {
errx(1, "-o %s: option not supported", opt);
}
}

View File

@ -30,48 +30,48 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mntopts.h 8.3 (Berkeley) 3/27/94
* @(#)mntopts.h 8.7 (Berkeley) 3/29/95
*/
struct mntopt {
const char *m_option; /* option name */
int m_inverse; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
int m_altloc; /* zero if this is a real mount flag */
int m_altloc; /* 1 => set bit in altflags */
};
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 }
#define MOPT_NOAUTO { "auto", 1, 0, 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_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
/* Skip this options without any action (needed for checkquota/quotaon) */
#define MOPT_UQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0, 0 }
#define MOPT_USERQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 }
/* Control flags. */
#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
/* Support for old-style "ro", "rw" flags. */
#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */
#define MOPT_AUTO { "auto", 0, 0, 0 }
#define MOPT_FSTAB_COMPAT \
MOPT_RO, \
MOPT_RW
MOPT_RW, \
MOPT_AUTO
/* Standard options which all mounts can understand. */
#define MOPT_STDOPTS \
MOPT_USERQUOTA, \
MOPT_GROUPQUOTA, \
MOPT_FSTAB_COMPAT, \
MOPT_NOATIME, \
MOPT_NOAUTO, \
MOPT_NODEV, \
MOPT_NOEXEC, \
MOPT_NOSUID, \

View File

@ -29,10 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)mount.8 8.7 (Berkeley) 3/27/94
.\" $Id$
.\" @(#)mount.8 8.8 (Berkeley) 6/16/94
.\" $Id: mount.8,v 1.14 1997/02/22 14:32:43 peter Exp $
.\"
.Dd March 27, 1994
.Dd June 16, 1994
.Dt MOUNT 8
.Os BSD 4
.Sh NAME
@ -76,10 +76,12 @@ this list is printed.
The options are as follows:
.Bl -tag -width indent
.It Fl a
Causes all filesystems listed in
.Pa /etc/fstab
(except those with the ``noauto'' option) to be mounted. This is normally
done during system startup.
All the filesystems described in
.Xr fstab 5
are mounted.
Exceptions are those marked as ``noauto'' or are excluded by the
.Fl t
flag (see below).
.It Fl d
Causes everything to be done except for the actual system call.
This option is useful in conjunction with the
@ -120,6 +122,10 @@ is useful on filesystems where there are large numbers of files and
performance is more critical than updating the file access time (which is
rarely ever important). This option is currently only supported on local
filesystems.
.It noauto
This filesystem should be skipped when mount is run with the
.Fl a
flag.
.It nodev
Do not interpret character or block special devices on the file system.
This option is useful for a server that has file systems containing

View File

@ -38,7 +38,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
#endif /* not lint */
#include <sys/param.h>
@ -50,6 +50,7 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include <err.h>
#include <errno.h>
#include <fstab.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -58,22 +59,20 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include "pathnames.h"
int debug, verbose, skipvfs;
int debug, verbose;
int fstab_style = 0;
static char *mnttype[] = INITMOUNTNAMES;
int badvfsname __P((const char *, const char **));
int badvfstype __P((int, const char **));
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 *));
void mangle __P((char *, int *, const char **));
int mountfs __P((const char *, const char *, const char *,
int, const char *, const char *));
void prmount __P((const char *, const char *, int));
void prmount __P((struct statfs *));
void usage __P((void));
void putfsent __P((const struct statfs *));
@ -96,7 +95,7 @@ static struct opt {
{ MNT_RDONLY, "read-only" },
{ MNT_SYNCHRONOUS, "synchronous" },
{ MNT_UNION, "union" },
{ MNT_USER, "user mount" },
{ MNT_NOATIME, "noatime" },
{ NULL }
};
@ -105,7 +104,7 @@ main(argc, argv)
int argc;
char * const argv[];
{
const char *mntonname, **vfslist, *vfstype;
const char *mntfromname, **vfslist, *vfstype;
struct fstab *fs;
struct statfs *mntbuf;
FILE *mountdfp;
@ -173,9 +172,9 @@ main(argc, argv)
while ((fs = getfsent()) != NULL) {
if (BADTYPE(fs->fs_type))
continue;
if (badvfsname(fs->fs_vfstype, vfslist))
if (checkvfsname(fs->fs_vfstype, vfslist))
continue;
if (strstr(fs->fs_mntops, "noauto"))
if (hasopt(fs->fs_mntops, "noauto"))
continue;
if (mountfs(fs->fs_vfstype, fs->fs_spec,
fs->fs_file, init_flags, options,
@ -186,7 +185,7 @@ main(argc, argv)
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
err(1, "getmntinfo");
for (i = 0; i < mntsize; i++) {
if (badvfstype(mntbuf[i].f_type, vfslist))
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
putfsent (&mntbuf[i]);
}
@ -195,10 +194,9 @@ main(argc, argv)
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
err(1, "getmntinfo");
for (i = 0; i < mntsize; i++) {
if (badvfstype(mntbuf[i].f_type, vfslist))
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
prmount(mntbuf[i].f_mntfromname,
mntbuf[i].f_mntonname, mntbuf[i].f_flags);
prmount(&mntbuf[i]);
}
}
exit(rval);
@ -211,25 +209,23 @@ main(argc, argv)
errx(1,
"unknown special file or file system %s.",
*argv);
if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
errx(1, "can't find fstab entry for %s.",
*argv);
/* If it's an update, ignore the fstab file options. */
fs->fs_mntops = NULL;
mntonname = mntbuf->f_mntonname;
} else {
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL)
mntfromname = fs->fs_spec;
else
mntfromname = mntbuf->f_mntfromname;
rval = mountfs(mntbuf->f_fstypename, mntfromname,
mntbuf->f_mntonname, init_flags, options, 0);
break;
}
if ((fs = getfsfile(*argv)) == NULL &&
(fs = getfsspec(*argv)) == NULL)
errx(1,
"%s: unknown special file or file system.",
errx(1, "%s: unknown special file or file system.",
*argv);
if (BADTYPE(fs->fs_type))
errx(1, "%s has unknown file system type.",
*argv);
mntonname = fs->fs_file;
}
rval = mountfs(fs->fs_vfstype, fs->fs_spec,
mntonname, init_flags, options, fs->fs_mntops);
rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
init_flags, options, fs->fs_mntops);
break;
case 2:
/*
@ -262,6 +258,31 @@ main(argc, argv)
exit(rval);
}
int
hasopt(mntopts, option)
const char *mntopts, *option;
{
int negative, found;
char *opt, *optbuf;
if (option[0] == 'n' && option[1] == 'o') {
negative = 1;
option += 2;
} else
negative = 0;
optbuf = strdup(mntopts);
found = 0;
for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
if (opt[0] == 'n' && opt[1] == 'o') {
if (!strcasecmp(opt + 2, option))
found = negative;
} else if (!strcasecmp(opt, option))
found = !negative;
}
free(optbuf);
return (found);
}
int
mountfs(vfstype, spec, name, flags, options, mntopts)
const char *vfstype, *spec, *name, *options, *mntopts;
@ -296,13 +317,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
name = mntpath;
if (mntopts == NULL)
mntopts = "";
if (options == NULL) {
if (*mntopts == '\0')
if (*mntopts == '\0') {
options = "rw";
else
} else {
options = mntopts;
mntopts = "";
}
}
optbuf = catopt(strdup(mntopts), options);
if (strcmp(name, "/") == 0)
@ -387,15 +411,13 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
if (verbose) {
if (statfs(name, &sf) < 0) {
warn("%s", name);
warn("statfs %s", name);
return (1);
}
if (fstab_style)
putfsent (&sf);
else
prmount (sf.f_mntfromname,
sf.f_mntonname, sf.f_flags);
prmount(&sf);
}
break;
}
@ -404,21 +426,29 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
}
void
prmount(spec, name, flags)
const char *spec, *name;
int flags;
prmount(sfp)
struct statfs *sfp;
{
int flags;
struct opt *o;
struct passwd *pw;
int f;
(void)printf("%s on %s", spec, name);
(void)printf("%s on %s", sfp->f_mntfromname, sfp->f_mntonname);
flags &= MNT_VISFLAGMASK;
flags = sfp->f_flags & MNT_VISFLAGMASK;
for (f = 0, o = optnames; flags && o->o_opt; o++)
if (flags & o->o_opt) {
(void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
flags &= ~o->o_opt;
}
if (sfp->f_owner) {
(void)printf("%smounted by ", !f++ ? " (" : ", ");
if ((pw = getpwuid(sfp->f_owner)) != NULL)
(void)printf("%s", pw->pw_name);
else
(void)printf("%d", sfp->f_owner);
}
(void)printf(f ? ")\n" : "\n");
}
@ -437,68 +467,6 @@ getmntpt(name)
return (NULL);
}
int
badvfsname(vfsname, vfslist)
const char *vfsname;
const char **vfslist;
{
if (vfslist == NULL)
return (0);
while (*vfslist != NULL) {
if (strcmp(vfsname, *vfslist) == 0)
return (skipvfs);
++vfslist;
}
return (!skipvfs);
}
int
badvfstype(vfstype, vfslist)
int vfstype;
const char **vfslist;
{
struct vfsconf *vfc;
vfc = getvfsbytype(vfstype);
if ( ! vfc )
return (0);
return (badvfsname(vfc->vfc_name, vfslist));
}
const char **
makevfslist(fslist)
char *fslist;
{
const char **av;
int i;
char *nextcp;
if (fslist == NULL)
return (NULL);
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
}
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
if (*nextcp == ',')
i++;
if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
warn(NULL);
return (NULL);
}
nextcp = fslist;
i = 0;
av[i++] = nextcp;
while ((nextcp = strchr(nextcp, ',')) != NULL) {
*nextcp++ = '\0';
av[i++] = nextcp;
}
av[i++] = NULL;
return (av);
}
char *
catopt(s0, s1)
char *s0;
@ -568,7 +536,7 @@ putfsent (ent)
printf ("%s\t%s\t%s %s",
ent->f_mntfromname, ent->f_mntonname,
mnttype[ent->f_type],
ent->f_fstypename,
(ent->f_flags & MNT_RDONLY) ? "ro" : "rw");
if (ent->f_flags & MNT_SYNCHRONOUS)
@ -589,6 +557,9 @@ putfsent (ent)
if (ent->f_flags & MNT_ASYNC)
printf (",async");
if (ent->f_flags & MNT_NOATIME)
printf (",noatime");
if (fst = getfsspec (ent->f_mntfromname))
printf ("\t%u %u\n", fst->fs_freq, fst->fs_passno);
else if (fst = getfsfile (ent->f_mntonname))

View File

@ -38,7 +38,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mount_ufs.c 8.2 (Berkeley) 3/27/94";
static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95";
#endif /* not lint */
#include <sys/param.h>
@ -51,6 +51,8 @@ static char sccsid[] = "@(#)mount_ufs.c 8.2 (Berkeley) 3/27/94";
#include <string.h>
#include <unistd.h>
#include <ufs/ufs/ufsmount.h>
#include "mntopts.h"
void ufs_usage __P((void));
@ -61,8 +63,7 @@ static struct mntopt mopts[] = {
MOPT_SYNC,
MOPT_FORCE,
MOPT_UPDATE,
MOPT_UQUOTA,
MOPT_GQUOTA,
MOPT_FORCE,
{ NULL }
};
@ -75,7 +76,8 @@ mount_ufs(argc, argv)
struct ufs_args args;
int ch, mntflags;
char *fs_name;
struct vfsconf *vfc;
struct vfsconf vfc;
int error = 0;
mntflags = 0;
optind = optreset = 1; /* Reset for parse of new argv. */
@ -104,21 +106,21 @@ mount_ufs(argc, argv)
else
args.export.ex_flags = 0;
setvfsent(0);
if(!(vfc = getvfsbyname("ufs"))) {
if(vfsisloadable("ufs")) {
if(vfsload("ufs")) {
warn("vfsload(\"ufs\")");
return 1;
error = getvfsbyname("ufs", &vfc);
if (error && vfsisloadable("ufs")) {
if (vfsload("ufs")) {
warn("vfsload(ufs)");
return (1);
}
endvfsent(); /* flush old table */
vfc = getvfsbyname("ufs");
} else {
/*warnx("ufs: filesystem not found");*/
error = getvfsbyname("ufs", &vfc);
}
if (error) {
warnx("ufs filesystem is not available");
return (1);
}
if (mount(vfc ? vfc->vfc_index : MOUNT_UFS, fs_name, mntflags, &args) < 0) {
if (mount(vfc.vfc_name, fs_name, mntflags, &args) < 0) {
(void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name);
switch (errno) {
case EMFILE:

View File

@ -1,8 +1,9 @@
# @(#)Makefile 8.5 (Berkeley) 3/27/94
# @(#)Makefile 8.6 (Berkeley) 5/8/95
PROG= mount
SRCS= mount.c mount_ufs.c getmntopts.c
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
.include <bsd.prog.mk>

View File

@ -29,9 +29,9 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)getmntopts.3 8.1 (Berkeley) 3/27/94
.\" @(#)getmntopts.3 8.3 (Berkeley) 3/30/95
.\"
.Dd March 27, 1994
.Dd March 30, 1995
.Dt GETMNTOPTS 3
.Os BSD 4.4
.Sh NAME
@ -62,7 +62,7 @@ or
.Dv m_altloc
field of the option's table entry)
are updated.
The flag word is not initialized by
The flag words are not initialized by
.Nm getmntopt .
The table,
.Dv mopts ,
@ -154,16 +154,21 @@ struct mntopt mopts[] = {
};
...
mntflags = 0;
mntflags = mntaltflags = 0;
...
getmntopts(options, mopts, &mntflags)
getmntopts(options, mopts, &mntflags, &mntaltflags);
...
.Ed
.Sh DIAGNOSTICS
The
If the external integer variable
.Dv getmnt_silent
is non-zero then the
.Nm getmntopts
function displays an error message and exits if an
unrecognized option is encountered.
By default
.Dv getmnt_silent
is zero.
.Sh SEE ALSO
.Xr err 3 ,
.Xr mount 8

View File

@ -32,7 +32,7 @@
*/
#ifndef lint
static char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94";
static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95";
#endif /* not lint */
#include <sys/param.h>
@ -57,7 +57,7 @@ getmntopts(options, m0, flagp, altflagp)
{
const struct mntopt *m;
int negative, len;
char *opt, *optbuf;
char *opt, *optbuf, *p;
int *thisflagp;
/* Copy option string, since it is about to be torn asunder... */
@ -72,6 +72,14 @@ getmntopts(options, m0, flagp, altflagp)
} else
negative = 0;
/*
* for options with assignments in them (ie. quotas)
* ignore the assignment as it's handled elsewhere
*/
p = strchr(opt, '=');
if (p)
*p = '\0';
/* Scan option table. */
for (m = m0; m->m_option != NULL; ++m) {
len = strlen(m->m_option);
@ -89,7 +97,7 @@ getmntopts(options, m0, flagp, altflagp)
*thisflagp |= m->m_flag;
else
*thisflagp &= ~m->m_flag;
} else if(!getmnt_silent) {
} else if (!getmnt_silent) {
errx(1, "-o %s: option not supported", opt);
}
}

View File

@ -30,48 +30,48 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
* @(#)mntopts.h 8.3 (Berkeley) 3/27/94
* @(#)mntopts.h 8.7 (Berkeley) 3/29/95
*/
struct mntopt {
const char *m_option; /* option name */
int m_inverse; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
int m_altloc; /* zero if this is a real mount flag */
int m_altloc; /* 1 => set bit in altflags */
};
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
#define MOPT_NOATIME { "atime", 1, MNT_NOATIME, 0 }
#define MOPT_NOAUTO { "auto", 1, 0, 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_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
/* Skip this options without any action (needed for checkquota/quotaon) */
#define MOPT_UQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0, 0 }
#define MOPT_USERQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GROUPQUOTA { "groupquota", 0, 0, 0 }
/* Control flags. */
#define MOPT_FORCE { "force", 0, MNT_FORCE, 0 }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
/* Support for old-style "ro", "rw" flags. */
#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
/* This is parsed by mount(8), but is ignored by specific mount_*(8)s. */
#define MOPT_AUTO { "auto", 0, 0, 0 }
#define MOPT_FSTAB_COMPAT \
MOPT_RO, \
MOPT_RW
MOPT_RW, \
MOPT_AUTO
/* Standard options which all mounts can understand. */
#define MOPT_STDOPTS \
MOPT_USERQUOTA, \
MOPT_GROUPQUOTA, \
MOPT_FSTAB_COMPAT, \
MOPT_NOATIME, \
MOPT_NOAUTO, \
MOPT_NODEV, \
MOPT_NOEXEC, \
MOPT_NOSUID, \

View File

@ -29,10 +29,10 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)mount.8 8.7 (Berkeley) 3/27/94
.\" $Id$
.\" @(#)mount.8 8.8 (Berkeley) 6/16/94
.\" $Id: mount.8,v 1.14 1997/02/22 14:32:43 peter Exp $
.\"
.Dd March 27, 1994
.Dd June 16, 1994
.Dt MOUNT 8
.Os BSD 4
.Sh NAME
@ -76,10 +76,12 @@ this list is printed.
The options are as follows:
.Bl -tag -width indent
.It Fl a
Causes all filesystems listed in
.Pa /etc/fstab
(except those with the ``noauto'' option) to be mounted. This is normally
done during system startup.
All the filesystems described in
.Xr fstab 5
are mounted.
Exceptions are those marked as ``noauto'' or are excluded by the
.Fl t
flag (see below).
.It Fl d
Causes everything to be done except for the actual system call.
This option is useful in conjunction with the
@ -120,6 +122,10 @@ is useful on filesystems where there are large numbers of files and
performance is more critical than updating the file access time (which is
rarely ever important). This option is currently only supported on local
filesystems.
.It noauto
This filesystem should be skipped when mount is run with the
.Fl a
flag.
.It nodev
Do not interpret character or block special devices on the file system.
This option is useful for a server that has file systems containing

View File

@ -38,7 +38,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
#endif /* not lint */
#include <sys/param.h>
@ -50,6 +50,7 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include <err.h>
#include <errno.h>
#include <fstab.h>
#include <pwd.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -58,22 +59,20 @@ static char sccsid[] = "@(#)mount.c 8.19 (Berkeley) 4/19/94";
#include "pathnames.h"
int debug, verbose, skipvfs;
int debug, verbose;
int fstab_style = 0;
static char *mnttype[] = INITMOUNTNAMES;
int badvfsname __P((const char *, const char **));
int badvfstype __P((int, const char **));
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 *));
void mangle __P((char *, int *, const char **));
int mountfs __P((const char *, const char *, const char *,
int, const char *, const char *));
void prmount __P((const char *, const char *, int));
void prmount __P((struct statfs *));
void usage __P((void));
void putfsent __P((const struct statfs *));
@ -96,7 +95,7 @@ static struct opt {
{ MNT_RDONLY, "read-only" },
{ MNT_SYNCHRONOUS, "synchronous" },
{ MNT_UNION, "union" },
{ MNT_USER, "user mount" },
{ MNT_NOATIME, "noatime" },
{ NULL }
};
@ -105,7 +104,7 @@ main(argc, argv)
int argc;
char * const argv[];
{
const char *mntonname, **vfslist, *vfstype;
const char *mntfromname, **vfslist, *vfstype;
struct fstab *fs;
struct statfs *mntbuf;
FILE *mountdfp;
@ -173,9 +172,9 @@ main(argc, argv)
while ((fs = getfsent()) != NULL) {
if (BADTYPE(fs->fs_type))
continue;
if (badvfsname(fs->fs_vfstype, vfslist))
if (checkvfsname(fs->fs_vfstype, vfslist))
continue;
if (strstr(fs->fs_mntops, "noauto"))
if (hasopt(fs->fs_mntops, "noauto"))
continue;
if (mountfs(fs->fs_vfstype, fs->fs_spec,
fs->fs_file, init_flags, options,
@ -186,7 +185,7 @@ main(argc, argv)
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
err(1, "getmntinfo");
for (i = 0; i < mntsize; i++) {
if (badvfstype(mntbuf[i].f_type, vfslist))
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
putfsent (&mntbuf[i]);
}
@ -195,10 +194,9 @@ main(argc, argv)
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
err(1, "getmntinfo");
for (i = 0; i < mntsize; i++) {
if (badvfstype(mntbuf[i].f_type, vfslist))
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
continue;
prmount(mntbuf[i].f_mntfromname,
mntbuf[i].f_mntonname, mntbuf[i].f_flags);
prmount(&mntbuf[i]);
}
}
exit(rval);
@ -211,25 +209,23 @@ main(argc, argv)
errx(1,
"unknown special file or file system %s.",
*argv);
if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
errx(1, "can't find fstab entry for %s.",
*argv);
/* If it's an update, ignore the fstab file options. */
fs->fs_mntops = NULL;
mntonname = mntbuf->f_mntonname;
} else {
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL)
mntfromname = fs->fs_spec;
else
mntfromname = mntbuf->f_mntfromname;
rval = mountfs(mntbuf->f_fstypename, mntfromname,
mntbuf->f_mntonname, init_flags, options, 0);
break;
}
if ((fs = getfsfile(*argv)) == NULL &&
(fs = getfsspec(*argv)) == NULL)
errx(1,
"%s: unknown special file or file system.",
errx(1, "%s: unknown special file or file system.",
*argv);
if (BADTYPE(fs->fs_type))
errx(1, "%s has unknown file system type.",
*argv);
mntonname = fs->fs_file;
}
rval = mountfs(fs->fs_vfstype, fs->fs_spec,
mntonname, init_flags, options, fs->fs_mntops);
rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
init_flags, options, fs->fs_mntops);
break;
case 2:
/*
@ -262,6 +258,31 @@ main(argc, argv)
exit(rval);
}
int
hasopt(mntopts, option)
const char *mntopts, *option;
{
int negative, found;
char *opt, *optbuf;
if (option[0] == 'n' && option[1] == 'o') {
negative = 1;
option += 2;
} else
negative = 0;
optbuf = strdup(mntopts);
found = 0;
for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
if (opt[0] == 'n' && opt[1] == 'o') {
if (!strcasecmp(opt + 2, option))
found = negative;
} else if (!strcasecmp(opt, option))
found = !negative;
}
free(optbuf);
return (found);
}
int
mountfs(vfstype, spec, name, flags, options, mntopts)
const char *vfstype, *spec, *name, *options, *mntopts;
@ -296,13 +317,16 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
name = mntpath;
if (mntopts == NULL)
mntopts = "";
if (options == NULL) {
if (*mntopts == '\0')
if (*mntopts == '\0') {
options = "rw";
else
} else {
options = mntopts;
mntopts = "";
}
}
optbuf = catopt(strdup(mntopts), options);
if (strcmp(name, "/") == 0)
@ -387,15 +411,13 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
if (verbose) {
if (statfs(name, &sf) < 0) {
warn("%s", name);
warn("statfs %s", name);
return (1);
}
if (fstab_style)
putfsent (&sf);
else
prmount (sf.f_mntfromname,
sf.f_mntonname, sf.f_flags);
prmount(&sf);
}
break;
}
@ -404,21 +426,29 @@ mountfs(vfstype, spec, name, flags, options, mntopts)
}
void
prmount(spec, name, flags)
const char *spec, *name;
int flags;
prmount(sfp)
struct statfs *sfp;
{
int flags;
struct opt *o;
struct passwd *pw;
int f;
(void)printf("%s on %s", spec, name);
(void)printf("%s on %s", sfp->f_mntfromname, sfp->f_mntonname);
flags &= MNT_VISFLAGMASK;
flags = sfp->f_flags & MNT_VISFLAGMASK;
for (f = 0, o = optnames; flags && o->o_opt; o++)
if (flags & o->o_opt) {
(void)printf("%s%s", !f++ ? " (" : ", ", o->o_name);
flags &= ~o->o_opt;
}
if (sfp->f_owner) {
(void)printf("%smounted by ", !f++ ? " (" : ", ");
if ((pw = getpwuid(sfp->f_owner)) != NULL)
(void)printf("%s", pw->pw_name);
else
(void)printf("%d", sfp->f_owner);
}
(void)printf(f ? ")\n" : "\n");
}
@ -437,68 +467,6 @@ getmntpt(name)
return (NULL);
}
int
badvfsname(vfsname, vfslist)
const char *vfsname;
const char **vfslist;
{
if (vfslist == NULL)
return (0);
while (*vfslist != NULL) {
if (strcmp(vfsname, *vfslist) == 0)
return (skipvfs);
++vfslist;
}
return (!skipvfs);
}
int
badvfstype(vfstype, vfslist)
int vfstype;
const char **vfslist;
{
struct vfsconf *vfc;
vfc = getvfsbytype(vfstype);
if ( ! vfc )
return (0);
return (badvfsname(vfc->vfc_name, vfslist));
}
const char **
makevfslist(fslist)
char *fslist;
{
const char **av;
int i;
char *nextcp;
if (fslist == NULL)
return (NULL);
if (fslist[0] == 'n' && fslist[1] == 'o') {
fslist += 2;
skipvfs = 1;
}
for (i = 0, nextcp = fslist; *nextcp; nextcp++)
if (*nextcp == ',')
i++;
if ((av = malloc((size_t)(i + 2) * sizeof(char *))) == NULL) {
warn(NULL);
return (NULL);
}
nextcp = fslist;
i = 0;
av[i++] = nextcp;
while ((nextcp = strchr(nextcp, ',')) != NULL) {
*nextcp++ = '\0';
av[i++] = nextcp;
}
av[i++] = NULL;
return (av);
}
char *
catopt(s0, s1)
char *s0;
@ -568,7 +536,7 @@ putfsent (ent)
printf ("%s\t%s\t%s %s",
ent->f_mntfromname, ent->f_mntonname,
mnttype[ent->f_type],
ent->f_fstypename,
(ent->f_flags & MNT_RDONLY) ? "ro" : "rw");
if (ent->f_flags & MNT_SYNCHRONOUS)
@ -589,6 +557,9 @@ putfsent (ent)
if (ent->f_flags & MNT_ASYNC)
printf (",async");
if (ent->f_flags & MNT_NOATIME)
printf (",noatime");
if (fst = getfsspec (ent->f_mntfromname))
printf ("\t%u %u\n", fst->fs_freq, fst->fs_passno);
else if (fst = getfsfile (ent->f_mntonname))

View File

@ -38,7 +38,7 @@ static char copyright[] =
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)mount_ufs.c 8.2 (Berkeley) 3/27/94";
static char sccsid[] = "@(#)mount_ufs.c 8.4 (Berkeley) 4/26/95";
#endif /* not lint */
#include <sys/param.h>
@ -51,6 +51,8 @@ static char sccsid[] = "@(#)mount_ufs.c 8.2 (Berkeley) 3/27/94";
#include <string.h>
#include <unistd.h>
#include <ufs/ufs/ufsmount.h>
#include "mntopts.h"
void ufs_usage __P((void));
@ -61,8 +63,7 @@ static struct mntopt mopts[] = {
MOPT_SYNC,
MOPT_FORCE,
MOPT_UPDATE,
MOPT_UQUOTA,
MOPT_GQUOTA,
MOPT_FORCE,
{ NULL }
};
@ -75,7 +76,8 @@ mount_ufs(argc, argv)
struct ufs_args args;
int ch, mntflags;
char *fs_name;
struct vfsconf *vfc;
struct vfsconf vfc;
int error = 0;
mntflags = 0;
optind = optreset = 1; /* Reset for parse of new argv. */
@ -104,21 +106,21 @@ mount_ufs(argc, argv)
else
args.export.ex_flags = 0;
setvfsent(0);
if(!(vfc = getvfsbyname("ufs"))) {
if(vfsisloadable("ufs")) {
if(vfsload("ufs")) {
warn("vfsload(\"ufs\")");
return 1;
error = getvfsbyname("ufs", &vfc);
if (error && vfsisloadable("ufs")) {
if (vfsload("ufs")) {
warn("vfsload(ufs)");
return (1);
}
endvfsent(); /* flush old table */
vfc = getvfsbyname("ufs");
} else {
/*warnx("ufs: filesystem not found");*/
error = getvfsbyname("ufs", &vfc);
}
if (error) {
warnx("ufs filesystem is not available");
return (1);
}
if (mount(vfc ? vfc->vfc_index : MOUNT_UFS, fs_name, mntflags, &args) < 0) {
if (mount(vfc.vfc_name, fs_name, mntflags, &args) < 0) {
(void)fprintf(stderr, "%s on %s: ", args.fspec, fs_name);
switch (errno) {
case EMFILE: