summaryrefslogtreecommitdiffstats
path: root/sbin/mount/mount.c
diff options
context:
space:
mode:
authorpeter <peter@FreeBSD.org>1997-03-11 12:28:00 +0000
committerpeter <peter@FreeBSD.org>1997-03-11 12:28:00 +0000
commit2feef020b355ece983a669243a95d099367b171c (patch)
tree9839b9610f8f5ce97f93c3d8c197a93fc61d2c61 /sbin/mount/mount.c
parentd2924d1b179ce176f260d3d1bc75c9cc4ea6262e (diff)
downloadFreeBSD-src-2feef020b355ece983a669243a95d099367b171c.zip
FreeBSD-src-2feef020b355ece983a669243a95d099367b171c.tar.gz
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!
Diffstat (limited to 'sbin/mount/mount.c')
-rw-r--r--sbin/mount/mount.c189
1 files changed, 80 insertions, 109 deletions
diff --git a/sbin/mount/mount.c b/sbin/mount/mount.c
index 5592a63..99173ea 100644
--- a/sbin/mount/mount.c
+++ b/sbin/mount/mount.c
@@ -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(*argv)) == NULL &&
- (fs = getfsspec(*argv)) == NULL)
- 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;
+ 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;
}
- rval = mountfs(fs->fs_vfstype, fs->fs_spec,
- mntonname, init_flags, options, fs->fs_mntops);
+ if ((fs = getfsfile(*argv)) == NULL &&
+ (fs = getfsspec(*argv)) == NULL)
+ errx(1, "%s: unknown special file or file system.",
+ *argv);
+ if (BADTYPE(fs->fs_type))
+ errx(1, "%s has unknown file system type.",
+ *argv);
+ rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
+ init_flags, options, fs->fs_mntops);
break;
case 2:
/*
@@ -263,6 +259,31 @@ main(argc, argv)
}
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;
int flags;
@@ -296,12 +317,15 @@ 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 = "";
+ mntopts = "";
+ }
}
optbuf = catopt(strdup(mntopts), options);
@@ -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);
+ 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))
OpenPOWER on IntegriCloud