1998-12-02 02:20:43 +03:00
|
|
|
/* $NetBSD: mount.c,v 1.45 1998/12/01 23:20:43 kenh Exp $ */
|
1995-03-18 17:54:19 +03:00
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 22:57:30 +04:00
|
|
|
* Copyright (c) 1980, 1989, 1993, 1994
|
|
|
|
* The Regents of the University of California. All rights reserved.
|
1993-03-21 12:45:37 +03:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
1997-07-04 19:17:55 +04:00
|
|
|
#include <sys/cdefs.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#ifndef lint
|
1997-07-04 19:17:55 +04:00
|
|
|
__COPYRIGHT("@(#) Copyright (c) 1980, 1989, 1993, 1994\n\
|
|
|
|
The Regents of the University of California. All rights reserved.\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#ifndef lint
|
1995-03-18 17:54:19 +03:00
|
|
|
#if 0
|
1997-09-16 16:22:39 +04:00
|
|
|
static char sccsid[] = "@(#)mount.c 8.25 (Berkeley) 5/8/95";
|
1995-03-18 17:54:19 +03:00
|
|
|
#else
|
1998-12-02 02:20:43 +03:00
|
|
|
__RCSID("$NetBSD: mount.c,v 1.45 1998/12/01 23:20:43 kenh Exp $");
|
1995-03-18 17:54:19 +03:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
#endif /* not lint */
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/mount.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <sys/wait.h>
|
|
|
|
|
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <fstab.h>
|
1997-09-16 16:22:39 +04:00
|
|
|
#include <pwd.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <signal.h>
|
1993-03-21 12:45:37 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
1994-06-08 22:57:30 +04:00
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
|
1993-03-21 12:45:37 +03:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1995-01-30 20:22:42 +03:00
|
|
|
int debug, verbose;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1997-09-16 16:22:39 +04:00
|
|
|
int checkvfsname __P((const char *, const char **));
|
1997-10-31 12:40:29 +03:00
|
|
|
void catopt __P((char **, const char *));
|
1994-06-08 22:57:30 +04:00
|
|
|
struct statfs
|
|
|
|
*getmntpt __P((const char *));
|
|
|
|
int hasopt __P((const char *, const char *));
|
1997-09-16 16:22:39 +04:00
|
|
|
const char
|
|
|
|
**makevfslist __P((char *));
|
1997-10-31 12:40:29 +03:00
|
|
|
static void
|
|
|
|
mangle __P((char *, int *, const char ***, int *));
|
1994-06-08 22:57:30 +04:00
|
|
|
int mountfs __P((const char *, const char *, const char *,
|
1995-07-12 10:05:04 +04:00
|
|
|
int, const char *, const char *, int));
|
1994-08-29 06:38:00 +04:00
|
|
|
void prmount __P((struct statfs *));
|
1994-06-08 22:57:30 +04:00
|
|
|
void usage __P((void));
|
1997-07-04 19:17:55 +04:00
|
|
|
int main __P((int, char *[]));
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
/* Map from mount otions to printable formats. */
|
|
|
|
static struct opt {
|
|
|
|
int o_opt;
|
1995-11-18 06:34:29 +03:00
|
|
|
int o_silent;
|
1994-06-08 22:57:30 +04:00
|
|
|
const char *o_name;
|
|
|
|
} optnames[] = {
|
1995-11-18 06:34:29 +03:00
|
|
|
{ MNT_ASYNC, 0, "asynchronous" },
|
|
|
|
{ MNT_DEFEXPORTED, 1, "exported to the world" },
|
|
|
|
{ MNT_EXKERB, 1, "kerberos uid mapping" },
|
|
|
|
{ MNT_EXPORTED, 0, "NFS exported" },
|
|
|
|
{ MNT_EXPORTANON, 1, "anon uid mapping" },
|
|
|
|
{ MNT_EXRDONLY, 1, "exported read-only" },
|
|
|
|
{ MNT_LOCAL, 0, "local" },
|
1997-03-10 06:59:53 +03:00
|
|
|
{ MNT_NOATIME, 0, "noatime" },
|
1996-10-24 02:50:05 +04:00
|
|
|
{ MNT_NOCOREDUMP, 0, "nocoredump" },
|
1995-11-18 06:34:29 +03:00
|
|
|
{ MNT_NODEV, 0, "nodev" },
|
1998-12-02 02:20:43 +03:00
|
|
|
{ MNT_NODEVMTIME, 0, "nodevmtime" },
|
1995-11-18 06:34:29 +03:00
|
|
|
{ MNT_NOEXEC, 0, "noexec" },
|
|
|
|
{ MNT_NOSUID, 0, "nosuid" },
|
|
|
|
{ MNT_QUOTA, 0, "with quotas" },
|
|
|
|
{ MNT_RDONLY, 0, "read-only" },
|
|
|
|
{ MNT_ROOTFS, 1, "root file system" },
|
1997-11-23 06:53:24 +03:00
|
|
|
{ MNT_SYMPERM, 0, "symperm" },
|
1995-11-18 06:34:29 +03:00
|
|
|
{ MNT_SYNCHRONOUS, 0, "synchronous" },
|
|
|
|
{ MNT_UNION, 0, "union" },
|
1997-05-17 23:36:35 +04:00
|
|
|
{ 0 }
|
1993-03-21 12:45:37 +03:00
|
|
|
};
|
|
|
|
|
1997-11-06 00:29:29 +03:00
|
|
|
static char ffs_fstype[] = "ffs";
|
1997-07-30 07:45:27 +04:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
int
|
|
|
|
main(argc, argv)
|
1993-03-21 12:45:37 +03:00
|
|
|
int argc;
|
1997-07-04 19:17:55 +04:00
|
|
|
char *argv[];
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-09-16 16:22:39 +04:00
|
|
|
const char *mntfromname, *mntonname, **vfslist, *vfstype;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct fstab *fs;
|
1994-04-14 07:25:14 +04:00
|
|
|
struct statfs *mntbuf;
|
1994-06-08 22:57:30 +04:00
|
|
|
FILE *mountdfp;
|
1995-07-12 10:05:04 +04:00
|
|
|
int all, ch, forceall, i, init_flags, mntsize, rval;
|
1994-06-08 22:57:30 +04:00
|
|
|
char *options;
|
1998-07-27 00:02:36 +04:00
|
|
|
const char *mountopts, *fstypename;
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1995-07-12 10:05:04 +04:00
|
|
|
all = forceall = init_flags = 0;
|
1994-06-08 22:57:30 +04:00
|
|
|
options = NULL;
|
1997-09-16 16:22:39 +04:00
|
|
|
vfslist = NULL;
|
1997-11-06 00:29:29 +03:00
|
|
|
vfstype = ffs_fstype;
|
1997-09-15 08:09:06 +04:00
|
|
|
while ((ch = getopt(argc, argv, "Aadfo:rwt:uv")) != -1)
|
1994-06-08 22:57:30 +04:00
|
|
|
switch (ch) {
|
1995-07-12 10:05:04 +04:00
|
|
|
case 'A':
|
|
|
|
all = forceall = 1;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'a':
|
|
|
|
all = 1;
|
|
|
|
break;
|
1994-06-08 22:57:30 +04:00
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
case 'f':
|
1994-06-08 22:57:30 +04:00
|
|
|
init_flags |= MNT_FORCE;
|
|
|
|
break;
|
|
|
|
case 'o':
|
|
|
|
if (*optarg)
|
1997-10-31 12:40:29 +03:00
|
|
|
catopt(&options, optarg);
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 'r':
|
1994-06-08 22:57:30 +04:00
|
|
|
init_flags |= MNT_RDONLY;
|
|
|
|
break;
|
|
|
|
case 't':
|
1997-09-16 16:22:39 +04:00
|
|
|
if (vfslist != NULL)
|
1994-06-08 22:57:30 +04:00
|
|
|
errx(1, "only one -t option may be specified.");
|
1997-09-16 16:22:39 +04:00
|
|
|
vfslist = makevfslist(optarg);
|
1994-06-08 22:57:30 +04:00
|
|
|
vfstype = optarg;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 'u':
|
1994-06-08 22:57:30 +04:00
|
|
|
init_flags |= MNT_UPDATE;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case 'v':
|
|
|
|
verbose = 1;
|
|
|
|
break;
|
|
|
|
case 'w':
|
1994-06-08 22:57:30 +04:00
|
|
|
init_flags &= ~MNT_RDONLY;
|
1993-03-21 12:45:37 +03:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
#define BADTYPE(type) \
|
|
|
|
(strcmp(type, FSTAB_RO) && \
|
|
|
|
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
|
|
|
|
|
|
|
|
rval = 0;
|
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
|
|
|
if (all)
|
|
|
|
while ((fs = getfsent()) != NULL) {
|
|
|
|
if (BADTYPE(fs->fs_type))
|
|
|
|
continue;
|
1997-09-16 16:22:39 +04:00
|
|
|
if (checkvfsname(fs->fs_vfstype, vfslist))
|
1994-06-08 22:57:30 +04:00
|
|
|
continue;
|
|
|
|
if (hasopt(fs->fs_mntops, "noauto"))
|
|
|
|
continue;
|
|
|
|
if (mountfs(fs->fs_vfstype, fs->fs_spec,
|
|
|
|
fs->fs_file, init_flags, options,
|
1995-07-12 10:05:04 +04:00
|
|
|
fs->fs_mntops, !forceall))
|
1994-06-08 22:57:30 +04:00
|
|
|
rval = 1;
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
|
|
|
err(1, "getmntinfo");
|
|
|
|
for (i = 0; i < mntsize; i++) {
|
1997-09-16 16:22:39 +04:00
|
|
|
if (checkvfsname(mntbuf[i].f_fstypename,
|
|
|
|
vfslist))
|
1994-06-08 22:57:30 +04:00
|
|
|
continue;
|
1994-08-29 06:38:00 +04:00
|
|
|
prmount(&mntbuf[i]);
|
1994-06-08 22:57:30 +04:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
exit(rval);
|
1997-11-06 00:29:29 +03:00
|
|
|
/* NOTREACHED */
|
1994-06-08 22:57:30 +04:00
|
|
|
case 1:
|
1997-11-06 00:29:29 +03:00
|
|
|
if (vfslist != NULL) {
|
1993-03-21 12:45:37 +03:00
|
|
|
usage();
|
1997-11-06 00:29:29 +03:00
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
if (init_flags & MNT_UPDATE) {
|
|
|
|
if ((mntbuf = getmntpt(*argv)) == NULL)
|
|
|
|
errx(1,
|
|
|
|
"unknown special file or file system %s.",
|
|
|
|
*argv);
|
1998-05-06 06:36:35 +04:00
|
|
|
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
|
1997-09-16 16:22:39 +04:00
|
|
|
mntfromname = fs->fs_spec;
|
1998-05-06 06:36:35 +04:00
|
|
|
/* ignore the fstab file options. */
|
|
|
|
fs->fs_mntops = NULL;
|
|
|
|
} else
|
1997-09-16 16:22:39 +04:00
|
|
|
mntfromname = mntbuf->f_mntfromname;
|
1998-05-06 06:36:35 +04:00
|
|
|
mntonname = mntbuf->f_mntonname;
|
|
|
|
fstypename = mntbuf->f_fstypename;
|
|
|
|
mountopts = NULL;
|
1994-06-08 22:57:30 +04:00
|
|
|
} 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);
|
1997-09-16 16:22:39 +04:00
|
|
|
mntfromname = fs->fs_spec;
|
1998-05-06 06:36:35 +04:00
|
|
|
mntonname = fs->fs_file;
|
|
|
|
fstypename = fs->fs_vfstype;
|
|
|
|
mountopts = fs->fs_mntops;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-05-06 06:36:35 +04:00
|
|
|
rval = mountfs(fstypename, mntfromname,
|
|
|
|
mntonname, init_flags, options, mountopts, 0);
|
1994-06-08 22:57:30 +04:00
|
|
|
break;
|
|
|
|
case 2:
|
1993-03-21 12:45:37 +03:00
|
|
|
/*
|
1994-06-08 22:57:30 +04:00
|
|
|
* 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.
|
1993-03-21 12:45:37 +03:00
|
|
|
*/
|
1997-09-16 16:22:39 +04:00
|
|
|
if (vfslist == NULL && strpbrk(argv[0], ":@") != NULL)
|
1994-06-08 22:57:30 +04:00
|
|
|
vfstype = "nfs";
|
|
|
|
rval = mountfs(vfstype,
|
1995-07-12 10:05:04 +04:00
|
|
|
argv[0], argv[1], init_flags, options, NULL, 0);
|
1994-06-08 22:57:30 +04:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/*
|
|
|
|
* 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-07-04 19:17:55 +04:00
|
|
|
int pid;
|
|
|
|
|
|
|
|
if (fscanf(mountdfp, "%d", &pid) == 1 &&
|
1994-06-08 22:57:30 +04:00
|
|
|
pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
|
|
|
|
err(1, "signal mountd");
|
|
|
|
(void)fclose(mountdfp);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
exit(rval);
|
1997-11-06 00:29:29 +03:00
|
|
|
/* NOTREACHED */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
int
|
|
|
|
hasopt(mntopts, option)
|
|
|
|
const char *mntopts, *option;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 22:57:30 +04:00
|
|
|
int negative, found;
|
|
|
|
char *opt, *optbuf;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
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;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
free(optbuf);
|
|
|
|
return (found);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
int
|
1995-07-12 10:05:04 +04:00
|
|
|
mountfs(vfstype, spec, name, flags, options, mntopts, skipmounted)
|
1994-06-08 22:57:30 +04:00
|
|
|
const char *vfstype, *spec, *name, *options, *mntopts;
|
1995-07-12 10:05:04 +04:00
|
|
|
int flags, skipmounted;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 22:57:30 +04:00
|
|
|
/* List of directories containing mount_xxx subcommands. */
|
|
|
|
static const char *edirs[] = {
|
|
|
|
_PATH_SBIN,
|
|
|
|
_PATH_USRSBIN,
|
|
|
|
NULL
|
|
|
|
};
|
1997-10-31 12:40:29 +03:00
|
|
|
const char **argv, **edir;
|
1997-11-01 16:59:00 +03:00
|
|
|
struct statfs *sfp, sf;
|
1994-06-08 22:57:30 +04:00
|
|
|
pid_t pid;
|
1997-11-01 16:59:00 +03:00
|
|
|
int argc, numfs, i, status, maxargc;
|
1997-10-29 21:55:58 +03:00
|
|
|
char *optbuf, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN],
|
|
|
|
mntpath[MAXPATHLEN];
|
1997-10-31 12:40:29 +03:00
|
|
|
|
1997-07-04 19:17:55 +04:00
|
|
|
#ifdef __GNUC__
|
|
|
|
(void) &name;
|
|
|
|
(void) &optbuf;
|
1997-07-30 07:45:27 +04:00
|
|
|
(void) &vfstype;
|
1997-07-04 19:17:55 +04:00
|
|
|
#endif
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
if (realpath(name, mntpath) == NULL) {
|
1995-07-05 03:41:33 +04:00
|
|
|
warn("realpath %s", name);
|
1994-06-08 22:57:30 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
name = mntpath;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-31 12:40:29 +03:00
|
|
|
optbuf = NULL;
|
|
|
|
if (mntopts)
|
|
|
|
catopt(&optbuf, mntopts);
|
|
|
|
if (options)
|
|
|
|
catopt(&optbuf, options);
|
|
|
|
if (!mntopts && !options)
|
|
|
|
catopt(&optbuf, "rw");
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1997-10-31 12:40:29 +03:00
|
|
|
if (!strcmp(name, "/"))
|
1994-06-08 22:57:30 +04:00
|
|
|
flags |= MNT_UPDATE;
|
1995-07-12 10:05:04 +04:00
|
|
|
else if (skipmounted) {
|
1997-11-01 16:59:00 +03:00
|
|
|
if ((numfs = getmntinfo(&sfp, MNT_WAIT)) == 0) {
|
|
|
|
warn("getmntinfo");
|
1995-07-12 07:45:09 +04:00
|
|
|
return (1);
|
|
|
|
}
|
1997-11-01 16:59:00 +03:00
|
|
|
for(i = 0; i < numfs; i++) {
|
|
|
|
/* XXX can't check f_mntfromname,
|
|
|
|
thanks to mfs, union, etc. */
|
|
|
|
if (strncmp(name, sfp[i].f_mntonname, MNAMELEN) == 0 &&
|
|
|
|
strncmp(vfstype, sfp[i].f_fstypename,
|
|
|
|
MFSNAMELEN) == 0) {
|
|
|
|
if (verbose)
|
|
|
|
(void)printf("%s on %s type %.*s: %s\n",
|
|
|
|
sfp[i].f_mntfromname,
|
|
|
|
sfp[i].f_mntonname,
|
|
|
|
MFSNAMELEN,
|
|
|
|
sfp[i].f_fstypename,
|
|
|
|
"already mounted");
|
|
|
|
return (0);
|
|
|
|
}
|
1995-07-12 07:45:09 +04:00
|
|
|
}
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
if (flags & MNT_FORCE)
|
1997-10-31 12:40:29 +03:00
|
|
|
catopt(&optbuf, "force");
|
1994-06-08 22:57:30 +04:00
|
|
|
if (flags & MNT_RDONLY)
|
1997-10-31 12:40:29 +03:00
|
|
|
catopt(&optbuf, "ro");
|
1997-10-29 21:55:58 +03:00
|
|
|
|
1997-07-30 07:45:27 +04:00
|
|
|
if (flags & MNT_UPDATE) {
|
1997-10-31 12:40:29 +03:00
|
|
|
catopt(&optbuf, "update");
|
1997-07-30 07:45:27 +04:00
|
|
|
/* Figure out the fstype only if we defaulted to ffs */
|
1997-11-06 00:29:29 +03:00
|
|
|
if (vfstype == ffs_fstype && statfs(name, &sf) != -1)
|
1997-07-30 07:45:27 +04:00
|
|
|
vfstype = sf.f_fstypename;
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1997-10-31 12:40:29 +03:00
|
|
|
maxargc = 64;
|
|
|
|
argv = malloc(sizeof(char *) * maxargc);
|
|
|
|
|
1997-10-29 21:55:58 +03:00
|
|
|
(void) snprintf(execbase, sizeof(execbase), "mount_%s", vfstype);
|
1994-06-08 22:57:30 +04:00
|
|
|
argc = 0;
|
1997-10-29 21:55:58 +03:00
|
|
|
argv[argc++] = execbase;
|
1997-10-31 12:40:29 +03:00
|
|
|
if (optbuf)
|
|
|
|
mangle(optbuf, &argc, &argv, &maxargc);
|
1994-06-08 22:57:30 +04:00
|
|
|
argv[argc++] = spec;
|
|
|
|
argv[argc++] = name;
|
|
|
|
argv[argc] = NULL;
|
|
|
|
|
1997-10-29 22:41:24 +03:00
|
|
|
if (verbose) {
|
1997-10-31 12:40:29 +03:00
|
|
|
(void)printf("exec:");
|
|
|
|
for (i = 0; i < argc; i++)
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf(" %s", argv[i]);
|
|
|
|
(void)printf("\n");
|
|
|
|
}
|
1993-08-03 05:25:52 +04:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
switch (pid = vfork()) {
|
|
|
|
case -1: /* Error. */
|
|
|
|
warn("vfork");
|
1997-10-31 12:40:29 +03:00
|
|
|
if (optbuf)
|
|
|
|
free(optbuf);
|
1994-06-08 22:57:30 +04:00
|
|
|
return (1);
|
1997-10-31 12:40:29 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
case 0: /* Child. */
|
1997-10-29 22:41:24 +03:00
|
|
|
if (debug)
|
|
|
|
_exit(0);
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
/* Go find an executable. */
|
|
|
|
edir = edirs;
|
|
|
|
do {
|
|
|
|
(void)snprintf(execname,
|
1997-10-29 21:55:58 +03:00
|
|
|
sizeof(execname), "%s/%s", *edir, execbase);
|
1997-11-06 00:29:29 +03:00
|
|
|
(void)execv(execname, (char * const *)argv);
|
1994-06-08 22:57:30 +04:00
|
|
|
if (errno != ENOENT)
|
|
|
|
warn("exec %s for %s", execname, name);
|
|
|
|
} while (*++edir != NULL);
|
|
|
|
|
|
|
|
if (errno == ENOENT)
|
1997-10-29 21:55:58 +03:00
|
|
|
warnx("%s not found for %s", execbase, name);
|
1997-10-29 22:41:24 +03:00
|
|
|
_exit(1);
|
1994-06-08 22:57:30 +04:00
|
|
|
/* NOTREACHED */
|
1997-10-31 12:40:29 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
default: /* Parent. */
|
1997-10-31 12:40:29 +03:00
|
|
|
if (optbuf)
|
|
|
|
free(optbuf);
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
if (waitpid(pid, &status, 0) < 0) {
|
|
|
|
warn("waitpid");
|
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
if (WIFEXITED(status)) {
|
|
|
|
if (WEXITSTATUS(status) != 0)
|
|
|
|
return (WEXITSTATUS(status));
|
|
|
|
} else if (WIFSIGNALED(status)) {
|
1995-05-28 09:25:34 +04:00
|
|
|
warnx("%s: %s", name, strsignal(WTERMSIG(status)));
|
1994-06-08 22:57:30 +04:00
|
|
|
return (1);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
if (verbose) {
|
|
|
|
if (statfs(name, &sf) < 0) {
|
|
|
|
warn("statfs %s", name);
|
|
|
|
return (1);
|
|
|
|
}
|
1994-08-29 06:38:00 +04:00
|
|
|
prmount(&sf);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
break;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
return (0);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
void
|
1997-09-16 16:22:39 +04:00
|
|
|
prmount(sfp)
|
|
|
|
struct statfs *sfp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-08-29 06:38:00 +04:00
|
|
|
int flags;
|
1994-06-08 22:57:30 +04:00
|
|
|
struct opt *o;
|
1997-09-16 16:22:39 +04:00
|
|
|
struct passwd *pw;
|
1994-06-08 22:57:30 +04:00
|
|
|
int f;
|
|
|
|
|
1997-09-16 16:22:39 +04:00
|
|
|
(void)printf("%s on %s type %.*s", sfp->f_mntfromname, sfp->f_mntonname,
|
|
|
|
MFSNAMELEN, sfp->f_fstypename);
|
1994-06-08 22:57:30 +04:00
|
|
|
|
1997-09-16 16:22:39 +04:00
|
|
|
flags = sfp->f_flags & MNT_VISFLAGMASK;
|
1994-06-08 22:57:30 +04:00
|
|
|
for (f = 0, o = optnames; flags && o->o_opt; o++)
|
|
|
|
if (flags & o->o_opt) {
|
1995-11-18 06:34:29 +03:00
|
|
|
if (!o->o_silent)
|
|
|
|
(void)printf("%s%s", !f++ ? " (" : ", ",
|
|
|
|
o->o_name);
|
1994-06-08 22:57:30 +04:00
|
|
|
flags &= ~o->o_opt;
|
|
|
|
}
|
1995-11-18 06:34:29 +03:00
|
|
|
if (flags)
|
1997-05-17 23:36:35 +04:00
|
|
|
(void)printf("%sunknown flag%s %#x", !f++ ? " (" : ", ",
|
1995-11-18 06:34:29 +03:00
|
|
|
flags & (flags - 1) ? "s" : "", flags);
|
1997-09-16 16:22:39 +04:00
|
|
|
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);
|
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
(void)printf(f ? ")\n" : "\n");
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
struct statfs *
|
|
|
|
getmntpt(name)
|
1994-06-08 22:57:30 +04:00
|
|
|
const char *name;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
|
|
|
struct statfs *mntbuf;
|
1994-06-08 22:57:30 +04:00
|
|
|
int i, mntsize;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
|
|
|
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
1994-06-08 22:57:30 +04:00
|
|
|
for (i = 0; i < mntsize; i++)
|
|
|
|
if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
|
|
|
|
strcmp(mntbuf[i].f_mntonname, name) == 0)
|
1993-03-21 12:45:37 +03:00
|
|
|
return (&mntbuf[i]);
|
1994-06-08 22:57:30 +04:00
|
|
|
return (NULL);
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-31 12:40:29 +03:00
|
|
|
void
|
|
|
|
catopt(sp, o)
|
|
|
|
char **sp;
|
|
|
|
const char *o;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1997-10-31 12:40:29 +03:00
|
|
|
char *s;
|
|
|
|
size_t i, j;
|
|
|
|
|
|
|
|
s = *sp;
|
|
|
|
if (s) {
|
|
|
|
i = strlen(s);
|
|
|
|
j = i + 1 + strlen(o) + 1;
|
|
|
|
s = realloc(s, j);
|
|
|
|
(void)snprintf(s + i, j, ",%s", o);
|
1994-06-08 22:57:30 +04:00
|
|
|
} else
|
1997-10-31 12:40:29 +03:00
|
|
|
s = strdup(o);
|
|
|
|
*sp = s;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1997-10-31 12:40:29 +03:00
|
|
|
static void
|
|
|
|
mangle(options, argcp, argvp, maxargcp)
|
1994-06-08 22:57:30 +04:00
|
|
|
char *options;
|
1997-10-31 12:40:29 +03:00
|
|
|
int *argcp, *maxargcp;
|
|
|
|
const char ***argvp;
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 22:57:30 +04:00
|
|
|
char *p, *s;
|
1997-10-31 12:40:29 +03:00
|
|
|
int argc, maxargc;
|
|
|
|
const char **argv;
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
argc = *argcp;
|
1997-10-31 12:40:29 +03:00
|
|
|
argv = *argvp;
|
|
|
|
maxargc = *maxargcp;
|
|
|
|
|
|
|
|
for (s = options; (p = strsep(&s, ",")) != NULL;) {
|
|
|
|
/* Always leave space for one more argument and the NULL. */
|
|
|
|
if (argc >= maxargc - 4) {
|
|
|
|
maxargc <<= 1;
|
|
|
|
argv = realloc(argv, maxargc * sizeof(char *));
|
|
|
|
}
|
1998-08-25 23:18:12 +04:00
|
|
|
if (*p != '\0') {
|
1994-06-08 22:57:30 +04:00
|
|
|
if (*p == '-') {
|
|
|
|
argv[argc++] = p;
|
|
|
|
p = strchr(p, '=');
|
|
|
|
if (p) {
|
|
|
|
*p = '\0';
|
|
|
|
argv[argc++] = p+1;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1994-06-08 22:57:30 +04:00
|
|
|
} else if (strcmp(p, "rw") != 0) {
|
|
|
|
argv[argc++] = "-o";
|
|
|
|
argv[argc++] = p;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
1998-08-25 23:18:12 +04:00
|
|
|
}
|
1997-10-31 12:40:29 +03:00
|
|
|
}
|
1993-03-21 12:45:37 +03:00
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
*argcp = argc;
|
1997-10-31 12:40:29 +03:00
|
|
|
*argvp = argv;
|
|
|
|
*maxargcp = maxargc;
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|
|
|
|
|
1994-06-08 22:57:30 +04:00
|
|
|
void
|
|
|
|
usage()
|
1993-03-21 12:45:37 +03:00
|
|
|
{
|
1994-06-08 22:57:30 +04:00
|
|
|
|
|
|
|
(void)fprintf(stderr,
|
|
|
|
"usage: mount %s %s\n mount %s\n mount %s\n",
|
1995-08-22 23:58:33 +04:00
|
|
|
"[-dfruvw] [-o options] [-t ffs | external_type]",
|
1994-06-08 22:57:30 +04:00
|
|
|
"special node",
|
1995-08-22 23:58:33 +04:00
|
|
|
"[-adfruvw] [-t ffs | external_type]",
|
1994-06-08 22:57:30 +04:00
|
|
|
"[-dfruvw] special | node");
|
|
|
|
exit(1);
|
1997-11-06 00:29:29 +03:00
|
|
|
/* NOTREACHED */
|
1993-03-21 12:45:37 +03:00
|
|
|
}
|