1997-08-24 21:02:51 +00:00
|
|
|
/*-
|
1994-05-26 06:35:07 +00:00
|
|
|
* Copyright (c) 1980, 1989, 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.
|
|
|
|
* 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
|
1997-08-24 21:02:51 +00:00
|
|
|
static const char copyright[] =
|
1994-05-26 06:35:07 +00:00
|
|
|
"@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n";
|
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1997-08-24 21:02:51 +00:00
|
|
|
#if 0
|
1997-03-11 12:28:00 +00:00
|
|
|
static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
|
1997-08-24 21:02:51 +00:00
|
|
|
#endif
|
1998-07-06 07:12:38 +00:00
|
|
|
static const char rcsid[] =
|
1999-08-28 00:22:10 +00:00
|
|
|
"$FreeBSD$";
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1995-02-15 14:20:50 +00:00
|
|
|
#include <sys/stat.h>
|
1997-03-12 18:35:10 +00:00
|
|
|
#include <sys/wait.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fstab.h>
|
1997-03-11 12:28:00 +00:00
|
|
|
#include <pwd.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <signal.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
#include "extern.h"
|
1994-05-26 06:35:07 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
/* `meta' options */
|
|
|
|
#define MOUNT_META_OPTION_FSTAB "fstab"
|
|
|
|
#define MOUNT_META_OPTION_CURRENT "current"
|
|
|
|
|
1997-03-12 18:35:10 +00:00
|
|
|
int debug, fstab_style, verbose;
|
1996-07-21 23:34:04 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
char *catopt __P((char *, const char *));
|
|
|
|
struct statfs
|
|
|
|
*getmntpt __P((const char *));
|
1997-03-11 12:28:00 +00:00
|
|
|
int hasopt __P((const char *, const char *));
|
1997-08-24 21:02:51 +00:00
|
|
|
int ismounted __P((struct fstab *, struct statfs *, int));
|
|
|
|
int isremountable __P((const char *));
|
1994-05-26 06:35:07 +00:00
|
|
|
void mangle __P((char *, int *, const char **));
|
1999-05-07 05:22:08 +00:00
|
|
|
char *update_options __P((char *, char *, int));
|
1994-05-26 06:35:07 +00:00
|
|
|
int mountfs __P((const char *, const char *, const char *,
|
|
|
|
int, const char *, const char *));
|
1999-05-07 05:22:08 +00:00
|
|
|
void remopt __P((char *, const char *));
|
1997-03-11 12:28:00 +00:00
|
|
|
void prmount __P((struct statfs *));
|
1996-07-21 23:34:04 +00:00
|
|
|
void putfsent __P((const struct statfs *));
|
1997-03-12 18:35:10 +00:00
|
|
|
void usage __P((void));
|
1999-05-07 05:22:08 +00:00
|
|
|
char *flags2opts __P((int));
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1998-07-06 07:12:38 +00:00
|
|
|
/* Map from mount options to printable formats. */
|
1994-05-26 06:35:07 +00:00
|
|
|
static struct opt {
|
|
|
|
int o_opt;
|
|
|
|
const char *o_name;
|
|
|
|
} optnames[] = {
|
|
|
|
{ MNT_ASYNC, "asynchronous" },
|
|
|
|
{ MNT_EXPORTED, "NFS exported" },
|
|
|
|
{ MNT_LOCAL, "local" },
|
1996-09-03 07:13:56 +00:00
|
|
|
{ MNT_NOATIME, "noatime" },
|
1994-05-26 06:35:07 +00:00
|
|
|
{ MNT_NODEV, "nodev" },
|
|
|
|
{ MNT_NOEXEC, "noexec" },
|
|
|
|
{ MNT_NOSUID, "nosuid" },
|
1998-04-08 18:31:59 +00:00
|
|
|
{ MNT_NOSYMFOLLOW, "nosymfollow" },
|
1994-05-26 06:35:07 +00:00
|
|
|
{ MNT_QUOTA, "with quotas" },
|
|
|
|
{ MNT_RDONLY, "read-only" },
|
|
|
|
{ MNT_SYNCHRONOUS, "synchronous" },
|
|
|
|
{ MNT_UNION, "union" },
|
1997-09-27 13:44:17 +00:00
|
|
|
{ MNT_NOCLUSTERR, "noclusterr" },
|
|
|
|
{ MNT_NOCLUSTERW, "noclusterw" },
|
1997-11-13 00:28:51 +00:00
|
|
|
{ MNT_SUIDDIR, "suiddir" },
|
1998-03-08 09:59:44 +00:00
|
|
|
{ MNT_SOFTDEP, "soft-updates" },
|
1999-05-07 05:22:08 +00:00
|
|
|
{ 0, NULL }
|
1994-05-26 06:35:07 +00:00
|
|
|
};
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
/*
|
|
|
|
* 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
|
|
|
|
};
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
|
|
|
int argc;
|
|
|
|
char * const argv[];
|
|
|
|
{
|
1997-03-11 12:28:00 +00:00
|
|
|
const char *mntfromname, **vfslist, *vfstype;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct fstab *fs;
|
|
|
|
struct statfs *mntbuf;
|
|
|
|
FILE *mountdfp;
|
|
|
|
pid_t pid;
|
|
|
|
int all, ch, i, init_flags, mntsize, rval;
|
|
|
|
char *options;
|
|
|
|
|
|
|
|
all = init_flags = 0;
|
|
|
|
options = NULL;
|
|
|
|
vfslist = NULL;
|
|
|
|
vfstype = "ufs";
|
1997-03-12 18:35:10 +00:00
|
|
|
while ((ch = getopt(argc, argv, "adfo:prwt:uv")) != -1)
|
1994-05-26 06:35:07 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
all = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
|
|
|
case 'f':
|
|
|
|
init_flags |= MNT_FORCE;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (*optarg)
|
|
|
|
options = catopt(options, optarg);
|
|
|
|
break;
|
1997-03-12 18:35:10 +00:00
|
|
|
case 'p':
|
|
|
|
fstab_style = 1;
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'r':
|
|
|
|
init_flags |= MNT_RDONLY;
|
|
|
|
break;
|
|
|
|
case 't':
|
|
|
|
if (vfslist != NULL)
|
1998-07-06 07:12:38 +00:00
|
|
|
errx(1, "only one -t option may be specified");
|
1994-05-26 06:35:07 +00:00
|
|
|
vfslist = makevfslist(optarg);
|
|
|
|
vfstype = optarg;
|
|
|
|
break;
|
|
|
|
case 'u':
|
|
|
|
init_flags |= MNT_UPDATE;
|
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'w':
|
|
|
|
init_flags &= ~MNT_RDONLY;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
#define BADTYPE(type) \
|
|
|
|
(strcmp(type, FSTAB_RO) && \
|
|
|
|
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
|
|
|
|
|
|
|
|
rval = 0;
|
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
1997-08-24 21:02:51 +00:00
|
|
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
|
|
|
err(1, "getmntinfo");
|
|
|
|
if (all) {
|
1994-05-26 06:35:07 +00:00
|
|
|
while ((fs = getfsent()) != NULL) {
|
|
|
|
if (BADTYPE(fs->fs_type))
|
|
|
|
continue;
|
1997-03-11 12:28:00 +00:00
|
|
|
if (checkvfsname(fs->fs_vfstype, vfslist))
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
1997-03-11 12:28:00 +00:00
|
|
|
if (hasopt(fs->fs_mntops, "noauto"))
|
1995-08-26 05:39:53 +00:00
|
|
|
continue;
|
1999-03-16 22:26:51 +00:00
|
|
|
if (!(init_flags & MNT_UPDATE) &&
|
|
|
|
ismounted(fs, mntbuf, mntsize))
|
1997-08-24 21:02:51 +00:00
|
|
|
continue;
|
1994-05-26 06:35:07 +00:00
|
|
|
if (mountfs(fs->fs_vfstype, fs->fs_spec,
|
1997-03-12 18:35:10 +00:00
|
|
|
fs->fs_file, init_flags, options,
|
|
|
|
fs->fs_mntops))
|
|
|
|
rval = 1;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1997-08-24 21:02:51 +00:00
|
|
|
} else if (fstab_style) {
|
1996-07-21 23:34:04 +00:00
|
|
|
for (i = 0; i < mntsize; i++) {
|
1997-03-11 12:28:00 +00:00
|
|
|
if (checkvfsname(mntbuf[i].f_fstypename, vfslist))
|
1996-07-21 23:34:04 +00:00
|
|
|
continue;
|
1997-03-12 18:35:10 +00:00
|
|
|
putfsent(&mntbuf[i]);
|
1996-07-21 23:34:04 +00:00
|
|
|
}
|
1997-03-12 18:35:10 +00:00
|
|
|
} else {
|
1994-05-26 06:35:07 +00:00
|
|
|
for (i = 0; i < mntsize; i++) {
|
1997-03-12 18:35:10 +00:00
|
|
|
if (checkvfsname(mntbuf[i].f_fstypename,
|
|
|
|
vfslist))
|
1994-05-26 06:35:07 +00:00
|
|
|
continue;
|
1997-03-11 12:28:00 +00:00
|
|
|
prmount(&mntbuf[i]);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
exit(rval);
|
|
|
|
case 1:
|
|
|
|
if (vfslist != NULL)
|
|
|
|
usage();
|
|
|
|
|
|
|
|
if (init_flags & MNT_UPDATE) {
|
|
|
|
if ((mntbuf = getmntpt(*argv)) == NULL)
|
|
|
|
errx(1,
|
1998-07-06 07:12:38 +00:00
|
|
|
"unknown special file or file system %s",
|
1994-05-26 06:35:07 +00:00
|
|
|
*argv);
|
1999-05-07 05:22:08 +00:00
|
|
|
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
|
1997-03-11 12:28:00 +00:00
|
|
|
mntfromname = fs->fs_spec;
|
1999-05-07 05:22:08 +00:00
|
|
|
options = update_options(options, fs->fs_mntops,
|
|
|
|
mntbuf->f_flags);
|
|
|
|
} else {
|
1997-03-11 12:28:00 +00:00
|
|
|
mntfromname = mntbuf->f_mntfromname;
|
1999-05-07 05:22:08 +00:00
|
|
|
options = update_options(options, NULL,
|
|
|
|
mntbuf->f_flags);
|
|
|
|
}
|
1997-03-11 12:28:00 +00:00
|
|
|
rval = mountfs(mntbuf->f_fstypename, mntfromname,
|
|
|
|
mntbuf->f_mntonname, init_flags, options, 0);
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1997-03-11 12:28:00 +00:00
|
|
|
if ((fs = getfsfile(*argv)) == NULL &&
|
|
|
|
(fs = getfsspec(*argv)) == NULL)
|
1998-07-06 07:12:38 +00:00
|
|
|
errx(1, "%s: unknown special file or file system",
|
1997-03-11 12:28:00 +00:00
|
|
|
*argv);
|
|
|
|
if (BADTYPE(fs->fs_type))
|
1998-07-06 07:12:38 +00:00
|
|
|
errx(1, "%s has unknown file system type",
|
1997-03-11 12:28:00 +00:00
|
|
|
*argv);
|
|
|
|
rval = mountfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file,
|
|
|
|
init_flags, options, fs->fs_mntops);
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
case 2:
|
|
|
|
/*
|
|
|
|
* If -t flag has not been specified, and spec contains either
|
|
|
|
* a ':' or a '@' then assume that an NFS filesystem is being
|
|
|
|
* specified ala Sun.
|
|
|
|
*/
|
|
|
|
if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
|
|
|
|
vfstype = "nfs";
|
|
|
|
rval = mountfs(vfstype,
|
|
|
|
argv[0], argv[1], init_flags, options, NULL);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the mount was successfully, and done by root, tell mountd the
|
|
|
|
* good news. Pid checks are probably unnecessary, but don't hurt.
|
|
|
|
*/
|
|
|
|
if (rval == 0 && getuid() == 0 &&
|
|
|
|
(mountdfp = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
|
1997-08-24 21:02:51 +00:00
|
|
|
if (fscanf(mountdfp, "%d", &pid) == 1 &&
|
1994-05-26 06:35:07 +00:00
|
|
|
pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
|
|
|
|
err(1, "signal mountd");
|
|
|
|
(void)fclose(mountdfp);
|
|
|
|
}
|
|
|
|
|
|
|
|
exit(rval);
|
|
|
|
}
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1997-03-11 12:28:00 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
|
|
|
mountfs(vfstype, spec, name, flags, options, mntopts)
|
|
|
|
const char *vfstype, *spec, *name, *options, *mntopts;
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
/* List of directories containing mount_xxx subcommands. */
|
|
|
|
static const char *edirs[] = {
|
|
|
|
_PATH_SBIN,
|
|
|
|
_PATH_USRSBIN,
|
|
|
|
NULL
|
|
|
|
};
|
|
|
|
const char *argv[100], **edir;
|
1997-03-12 18:35:10 +00:00
|
|
|
struct stat sb;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct statfs sf;
|
|
|
|
pid_t pid;
|
|
|
|
int argc, i, status;
|
|
|
|
char *optbuf, execname[MAXPATHLEN + 1], mntpath[MAXPATHLEN];
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
#if __GNUC__
|
|
|
|
(void)&optbuf;
|
|
|
|
(void)&name;
|
|
|
|
#endif
|
|
|
|
|
1995-02-16 11:23:25 +00:00
|
|
|
if (realpath(name, mntpath) != NULL && stat(mntpath, &sb) == 0) {
|
1995-02-15 14:45:08 +00:00
|
|
|
if (!S_ISDIR(sb.st_mode)) {
|
1998-07-06 07:12:38 +00:00
|
|
|
warnx("%s: not a directory", mntpath);
|
1995-02-15 14:20:50 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
} else {
|
1994-05-26 06:35:07 +00:00
|
|
|
warn("%s", mntpath);
|
|
|
|
return (1);
|
|
|
|
}
|
1995-02-15 14:20:50 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
name = mntpath;
|
|
|
|
|
1997-03-11 12:28:00 +00:00
|
|
|
if (mntopts == NULL)
|
|
|
|
mntopts = "";
|
1994-05-26 06:35:07 +00:00
|
|
|
if (options == NULL) {
|
1997-03-11 12:28:00 +00:00
|
|
|
if (*mntopts == '\0') {
|
1994-05-26 06:35:07 +00:00
|
|
|
options = "rw";
|
1997-03-11 12:28:00 +00:00
|
|
|
} else {
|
1994-05-26 06:35:07 +00:00
|
|
|
options = mntopts;
|
1997-03-11 12:28:00 +00:00
|
|
|
mntopts = "";
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
optbuf = catopt(strdup(mntopts), options);
|
|
|
|
|
|
|
|
if (strcmp(name, "/") == 0)
|
|
|
|
flags |= MNT_UPDATE;
|
|
|
|
if (flags & MNT_FORCE)
|
|
|
|
optbuf = catopt(optbuf, "force");
|
|
|
|
if (flags & MNT_RDONLY)
|
|
|
|
optbuf = catopt(optbuf, "ro");
|
|
|
|
/*
|
|
|
|
* XXX
|
|
|
|
* The mount_mfs (newfs) command uses -o to select the
|
1998-07-06 07:12:38 +00:00
|
|
|
* optimization mode. We don't pass the default "-o rw"
|
1994-05-26 06:35:07 +00:00
|
|
|
* for that reason.
|
|
|
|
*/
|
|
|
|
if (flags & MNT_UPDATE)
|
|
|
|
optbuf = catopt(optbuf, "update");
|
|
|
|
|
|
|
|
argc = 0;
|
|
|
|
argv[argc++] = vfstype;
|
|
|
|
mangle(optbuf, &argc, argv);
|
|
|
|
argv[argc++] = spec;
|
|
|
|
argv[argc++] = name;
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
|
|
|
if (debug) {
|
|
|
|
(void)printf("exec: mount_%s", vfstype);
|
|
|
|
for (i = 1; i < argc; i++)
|
|
|
|
(void)printf(" %s", argv[i]);
|
|
|
|
(void)printf("\n");
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1997-04-23 23:04:58 +00:00
|
|
|
switch (pid = fork()) {
|
1994-05-26 06:35:07 +00:00
|
|
|
case -1: /* Error. */
|
1997-04-23 23:04:58 +00:00
|
|
|
warn("fork");
|
1994-05-26 06:35:07 +00:00
|
|
|
free(optbuf);
|
|
|
|
return (1);
|
|
|
|
case 0: /* Child. */
|
|
|
|
if (strcmp(vfstype, "ufs") == 0)
|
|
|
|
exit(mount_ufs(argc, (char * const *) argv));
|
|
|
|
|
|
|
|
/* Go find an executable. */
|
1996-03-15 00:14:09 +00:00
|
|
|
for (edir = edirs; *edir; edir++) {
|
1994-05-26 06:35:07 +00:00
|
|
|
(void)snprintf(execname,
|
|
|
|
sizeof(execname), "%s/mount_%s", *edir, vfstype);
|
|
|
|
execv(execname, (char * const *)argv);
|
1996-03-15 00:14:09 +00:00
|
|
|
}
|
|
|
|
if (errno == ENOENT) {
|
|
|
|
int len = 0;
|
|
|
|
char *cp;
|
|
|
|
for (edir = edirs; *edir; edir++)
|
|
|
|
len += strlen(*edir) + 2; /* ", " */
|
1998-07-06 07:12:38 +00:00
|
|
|
if ((cp = malloc(len)) == NULL)
|
|
|
|
errx(1, "malloc failed");
|
1996-03-15 00:14:09 +00:00
|
|
|
cp[0] = '\0';
|
|
|
|
for (edir = edirs; *edir; edir++) {
|
|
|
|
strcat(cp, *edir);
|
|
|
|
if (edir[1] != NULL)
|
|
|
|
strcat(cp, ", ");
|
|
|
|
}
|
|
|
|
warn("exec mount_%s not found in %s", vfstype, cp);
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(1);
|
|
|
|
/* NOTREACHED */
|
|
|
|
default: /* Parent. */
|
|
|
|
free(optbuf);
|
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
if (statfs(name, &sf) < 0) {
|
1997-03-11 12:28:00 +00:00
|
|
|
warn("statfs %s", name);
|
1994-05-26 06:35:07 +00:00
|
|
|
return (1);
|
|
|
|
}
|
1996-07-21 23:34:04 +00:00
|
|
|
if (fstab_style)
|
1997-03-12 18:35:10 +00:00
|
|
|
putfsent(&sf);
|
1996-07-21 23:34:04 +00:00
|
|
|
else
|
1997-03-11 12:28:00 +00:00
|
|
|
prmount(&sf);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1997-03-11 12:28:00 +00:00
|
|
|
prmount(sfp)
|
|
|
|
struct statfs *sfp;
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
1997-03-11 12:28:00 +00:00
|
|
|
int flags;
|
1994-05-26 06:35:07 +00:00
|
|
|
struct opt *o;
|
1997-03-11 12:28:00 +00:00
|
|
|
struct passwd *pw;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1999-10-08 19:54:32 +00:00
|
|
|
(void)printf("%s on %s (%s", sfp->f_mntfromname, sfp->f_mntonname,
|
|
|
|
sfp->f_fstypename);
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1997-03-11 12:28:00 +00:00
|
|
|
flags = sfp->f_flags & MNT_VISFLAGMASK;
|
1999-10-08 19:54:32 +00:00
|
|
|
for (o = optnames; flags && o->o_opt; o++)
|
1994-05-26 06:35:07 +00:00
|
|
|
if (flags & o->o_opt) {
|
1999-10-08 19:54:32 +00:00
|
|
|
(void)printf(", %s", o->o_name);
|
1994-05-26 06:35:07 +00:00
|
|
|
flags &= ~o->o_opt;
|
|
|
|
}
|
1997-03-11 12:28:00 +00:00
|
|
|
if (sfp->f_owner) {
|
1999-10-08 19:54:32 +00:00
|
|
|
(void)printf(", mounted by ");
|
1997-03-11 12:28:00 +00:00
|
|
|
if ((pw = getpwuid(sfp->f_owner)) != NULL)
|
|
|
|
(void)printf("%s", pw->pw_name);
|
|
|
|
else
|
|
|
|
(void)printf("%d", sfp->f_owner);
|
|
|
|
}
|
1998-06-08 14:08:54 +00:00
|
|
|
if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
|
1999-10-08 19:54:32 +00:00
|
|
|
(void)printf(", writes: sync %ld async %ld",
|
|
|
|
sfp->f_syncwrites, sfp->f_asyncwrites);
|
|
|
|
(void)printf(")\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct statfs *
|
|
|
|
getmntpt(name)
|
|
|
|
const char *name;
|
|
|
|
{
|
|
|
|
struct statfs *mntbuf;
|
|
|
|
int i, mntsize;
|
|
|
|
|
|
|
|
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
|
|
|
for (i = 0; i < mntsize; i++)
|
|
|
|
if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
|
|
|
|
strcmp(mntbuf[i].f_mntonname, name) == 0)
|
|
|
|
return (&mntbuf[i]);
|
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
|
|
|
catopt(s0, s1)
|
|
|
|
char *s0;
|
|
|
|
const char *s1;
|
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *cp;
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
if (s1 == NULL || *s1 == '\0')
|
|
|
|
return s0;
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (s0 && *s0) {
|
|
|
|
i = strlen(s0) + strlen(s1) + 1 + 1;
|
|
|
|
if ((cp = malloc(i)) == NULL)
|
1998-07-06 07:12:38 +00:00
|
|
|
errx(1, "malloc failed");
|
1994-05-26 06:35:07 +00:00
|
|
|
(void)snprintf(cp, i, "%s,%s", s0, s1);
|
|
|
|
} else
|
|
|
|
cp = strdup(s1);
|
|
|
|
|
|
|
|
if (s0)
|
|
|
|
free(s0);
|
|
|
|
return (cp);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
mangle(options, argcp, argv)
|
|
|
|
char *options;
|
|
|
|
int *argcp;
|
|
|
|
const char **argv;
|
|
|
|
{
|
|
|
|
char *p, *s;
|
|
|
|
int argc;
|
|
|
|
|
|
|
|
argc = *argcp;
|
|
|
|
for (s = options; (p = strsep(&s, ",")) != NULL;)
|
1999-05-07 05:22:08 +00:00
|
|
|
if (*p != '\0') {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (*p == '-') {
|
|
|
|
argv[argc++] = p;
|
|
|
|
p = strchr(p, '=');
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
argv[argc++] = p+1;
|
|
|
|
}
|
|
|
|
} else if (strcmp(p, "rw") != 0) {
|
|
|
|
argv[argc++] = "-o";
|
|
|
|
argv[argc++] = p;
|
|
|
|
}
|
1999-05-07 05:22:08 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
*argcp = argc;
|
|
|
|
}
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
|
|
|
|
char *
|
|
|
|
update_options(opts, fstab, curflags)
|
|
|
|
char *opts;
|
|
|
|
char *fstab;
|
|
|
|
int curflags;
|
|
|
|
{
|
|
|
|
char *o, *p;
|
|
|
|
char *cur;
|
|
|
|
char *expopt, *newopt, *tmpopt;
|
|
|
|
|
|
|
|
if (opts == NULL)
|
|
|
|
return strdup("");
|
|
|
|
|
1999-10-08 19:54:32 +00:00
|
|
|
if (fstab == NULL)
|
|
|
|
fstab = strdup("");
|
1999-05-07 05:22:08 +00:00
|
|
|
|
|
|
|
/* remove meta options from list */
|
|
|
|
remopt(fstab, MOUNT_META_OPTION_FSTAB);
|
|
|
|
remopt(fstab, MOUNT_META_OPTION_CURRENT);
|
|
|
|
cur = flags2opts(curflags);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Expand all meta-options passed to us first.
|
|
|
|
*/
|
|
|
|
expopt = NULL;
|
|
|
|
for (p = opts; (o = strsep(&p, ",")) != NULL;) {
|
|
|
|
if (strcmp(MOUNT_META_OPTION_FSTAB, o) == 0)
|
|
|
|
expopt = catopt(expopt, fstab);
|
|
|
|
else if (strcmp(MOUNT_META_OPTION_CURRENT, o) == 0)
|
|
|
|
expopt = catopt(expopt, cur);
|
|
|
|
else
|
|
|
|
expopt = catopt(expopt, o);
|
|
|
|
}
|
1999-10-08 19:54:32 +00:00
|
|
|
if (fstab == "")
|
|
|
|
free(fstab);
|
1999-05-07 05:22:08 +00:00
|
|
|
free(cur);
|
|
|
|
free(opts);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Remove previous contradictory arguments. Given option "foo" we
|
|
|
|
* remove all the "nofoo" options. Given "nofoo" we remove "nonofoo"
|
|
|
|
* and "foo" - so we can deal with possible options like "notice".
|
|
|
|
*/
|
|
|
|
newopt = NULL;
|
|
|
|
for (p = expopt; (o = strsep(&p, ",")) != NULL;) {
|
|
|
|
if ((tmpopt = malloc( strlen(o) + 2 + 1 )) == NULL)
|
|
|
|
errx(1, "malloc failed");
|
|
|
|
|
|
|
|
strcpy(tmpopt, "no");
|
|
|
|
strcat(tmpopt, o);
|
|
|
|
remopt(newopt, tmpopt);
|
|
|
|
free(tmpopt);
|
|
|
|
|
|
|
|
if (strncmp("no", o, 2) == 0)
|
|
|
|
remopt(newopt, o+2);
|
|
|
|
|
|
|
|
newopt = catopt(newopt, o);
|
|
|
|
}
|
|
|
|
free(expopt);
|
|
|
|
|
|
|
|
return newopt;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
remopt(string, opt)
|
|
|
|
char *string;
|
|
|
|
const char *opt;
|
|
|
|
{
|
|
|
|
char *o, *p, *r;
|
|
|
|
|
|
|
|
if (string == NULL || *string == '\0' || opt == NULL || *opt == '\0')
|
|
|
|
return;
|
|
|
|
|
|
|
|
r = string;
|
|
|
|
|
|
|
|
for (p = string; (o = strsep(&p, ",")) != NULL;) {
|
|
|
|
if (strcmp(opt, o) != 0) {
|
|
|
|
if (*r == ',' && *o != '\0')
|
|
|
|
r++;
|
|
|
|
while ((*r++ = *o++) != '\0')
|
|
|
|
;
|
|
|
|
*--r = ',';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
*r = '\0';
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
void
|
|
|
|
usage()
|
|
|
|
{
|
|
|
|
|
1998-07-06 07:12:38 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n%s\n",
|
|
|
|
"usage: mount [-dfpruvw] [-o options] [-t ufs | external_type] special node",
|
|
|
|
" mount [-adfpruvw] [-t ufs | external_type]",
|
|
|
|
" mount [-dfpruvw] special | node");
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-07-21 23:34:04 +00:00
|
|
|
|
|
|
|
void
|
1997-03-12 18:35:10 +00:00
|
|
|
putfsent(ent)
|
|
|
|
const struct statfs *ent;
|
1996-07-21 23:34:04 +00:00
|
|
|
{
|
1997-03-12 18:35:10 +00:00
|
|
|
struct fstab *fst;
|
1999-05-07 05:22:08 +00:00
|
|
|
char *opts;
|
|
|
|
|
|
|
|
opts = flags2opts(ent->f_flags);
|
1997-03-12 18:35:10 +00:00
|
|
|
printf("%s\t%s\t%s %s", ent->f_mntfromname, ent->f_mntonname,
|
1999-05-07 05:22:08 +00:00
|
|
|
ent->f_fstypename, opts);
|
|
|
|
free(opts);
|
1997-03-12 18:35:10 +00:00
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
if ((fst = getfsspec(ent->f_mntfromname)))
|
1997-03-12 18:35:10 +00:00
|
|
|
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
|
1997-08-24 21:02:51 +00:00
|
|
|
else if ((fst = getfsfile(ent->f_mntonname)))
|
1997-03-12 18:35:10 +00:00
|
|
|
printf("\t%u %u\n", fst->fs_freq, fst->fs_passno);
|
1998-02-13 04:54:27 +00:00
|
|
|
else if (strcmp(ent->f_fstypename, "ufs") == 0)
|
1997-03-12 18:35:10 +00:00
|
|
|
printf("\t1 1\n");
|
|
|
|
else
|
|
|
|
printf("\t0 0\n");
|
1996-07-21 23:34:04 +00:00
|
|
|
}
|
1999-05-07 05:22:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
char *
|
|
|
|
flags2opts(flags)
|
|
|
|
int flags;
|
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
res = NULL;
|
|
|
|
|
|
|
|
res = catopt(res, (flags & MNT_RDONLY) ? "ro" : "rw");
|
|
|
|
|
|
|
|
if (flags & MNT_SYNCHRONOUS) res = catopt(res, "sync");
|
|
|
|
if (flags & MNT_NOEXEC) res = catopt(res, "noexec");
|
|
|
|
if (flags & MNT_NOSUID) res = catopt(res, "nosuid");
|
|
|
|
if (flags & MNT_NODEV) res = catopt(res, "nodev");
|
|
|
|
if (flags & MNT_UNION) res = catopt(res, "union");
|
|
|
|
if (flags & MNT_ASYNC) res = catopt(res, "async");
|
|
|
|
if (flags & MNT_NOATIME) res = catopt(res, "noatime");
|
|
|
|
if (flags & MNT_NOCLUSTERR) res = catopt(res, "noclusterr");
|
|
|
|
if (flags & MNT_NOCLUSTERW) res = catopt(res, "noclusterw");
|
|
|
|
if (flags & MNT_NOSYMFOLLOW) res = catopt(res, "nosymfollow");
|
|
|
|
if (flags & MNT_SUIDDIR) res = catopt(res, "suiddir");
|
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|