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.
|
|
|
|
* 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";
|
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
|
1994-05-26 06:35:07 +00:00
|
|
|
#endif /* not lint */
|
|
|
|
|
2009-01-12 08:22:36 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
#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
|
|
|
|
2002-04-22 23:03:03 +00:00
|
|
|
#include <ctype.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <err.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <fstab.h>
|
2003-06-29 17:53:48 +00:00
|
|
|
#include <paths.h>
|
1997-03-11 12:28:00 +00:00
|
|
|
#include <pwd.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <signal.h>
|
2003-12-07 17:00:14 +00:00
|
|
|
#include <stdint.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2007-02-02 23:58:10 +00:00
|
|
|
#include <libutil.h>
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
#include "extern.h"
|
1999-10-09 11:54:14 +00:00
|
|
|
#include "mntopts.h"
|
1994-05-26 06:35:07 +00:00
|
|
|
#include "pathnames.h"
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
/* `meta' options */
|
2004-02-17 08:43:05 +00:00
|
|
|
#define MOUNT_META_OPTION_FSTAB "fstab"
|
1999-05-07 05:22:08 +00:00
|
|
|
#define MOUNT_META_OPTION_CURRENT "current"
|
|
|
|
|
2011-11-04 13:36:02 +00:00
|
|
|
static int debug, fstab_style, verbose;
|
1996-07-21 23:34:04 +00:00
|
|
|
|
2009-01-10 20:54:47 +00:00
|
|
|
struct cpa {
|
2009-01-12 08:22:36 +00:00
|
|
|
char **a;
|
2009-01-13 06:08:37 +00:00
|
|
|
ssize_t sz;
|
2009-01-10 20:54:47 +00:00
|
|
|
int c;
|
|
|
|
};
|
|
|
|
|
2002-03-21 13:14:21 +00:00
|
|
|
char *catopt(char *, const char *);
|
|
|
|
struct statfs *getmntpt(const char *);
|
|
|
|
int hasopt(const char *, const char *);
|
|
|
|
int ismounted(struct fstab *, struct statfs *, int);
|
|
|
|
int isremountable(const char *);
|
2009-01-10 20:54:47 +00:00
|
|
|
void mangle(char *, struct cpa *);
|
2002-03-21 13:14:21 +00:00
|
|
|
char *update_options(char *, char *, int);
|
|
|
|
int mountfs(const char *, const char *, const char *,
|
|
|
|
int, const char *, const char *);
|
|
|
|
void remopt(char *, const char *);
|
|
|
|
void prmount(struct statfs *);
|
2008-02-03 17:23:58 +00:00
|
|
|
void putfsent(struct statfs *);
|
2002-03-21 13:14:21 +00:00
|
|
|
void usage(void);
|
|
|
|
char *flags2opts(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 {
|
2010-03-07 16:45:18 +00:00
|
|
|
uint64_t o_opt;
|
1994-05-26 06:35:07 +00:00
|
|
|
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_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" },
|
2011-07-24 18:27:09 +00:00
|
|
|
{ MNT_SUJ, "journaled soft-updates" },
|
2002-08-02 07:02:51 +00:00
|
|
|
{ MNT_MULTILABEL, "multilabel" },
|
2002-10-14 19:40:00 +00:00
|
|
|
{ MNT_ACLS, "acls" },
|
2009-12-21 19:39:10 +00:00
|
|
|
{ MNT_NFS4ACLS, "nfsv4acls" },
|
2006-10-31 21:54:51 +00:00
|
|
|
{ MNT_GJOURNAL, "gjournal" },
|
2014-08-17 09:44:42 +00:00
|
|
|
{ MNT_AUTOMOUNTED, "automounted" },
|
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[] = {
|
2000-11-22 17:54:56 +00:00
|
|
|
"ufs", "ffs", "ext2fs",
|
1997-08-24 21:02:51 +00:00
|
|
|
0
|
|
|
|
};
|
|
|
|
|
2006-05-10 14:40:40 +00:00
|
|
|
static const char userquotaeq[] = "userquota=";
|
|
|
|
static const char groupquotaeq[] = "groupquota=";
|
|
|
|
|
2009-03-05 08:57:35 +00:00
|
|
|
static char *mountprog = NULL;
|
|
|
|
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
static int
|
|
|
|
use_mountprog(const char *vfstype)
|
|
|
|
{
|
|
|
|
/* XXX: We need to get away from implementing external mount
|
|
|
|
* programs for every filesystem, and move towards having
|
|
|
|
* each filesystem properly implement the nmount() system call.
|
|
|
|
*/
|
|
|
|
unsigned int i;
|
|
|
|
const char *fs[] = {
|
2012-10-17 11:30:00 +00:00
|
|
|
"cd9660", "mfs", "msdosfs", "nfs",
|
2013-06-28 21:00:08 +00:00
|
|
|
"nullfs", "oldnfs", "smbfs", "udf", "unionfs",
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
|
2009-03-05 08:57:35 +00:00
|
|
|
if (mountprog != NULL)
|
|
|
|
return (1);
|
|
|
|
|
2006-06-10 01:44:57 +00:00
|
|
|
for (i = 0; fs[i] != NULL; ++i) {
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
if (strcmp(vfstype, fs[i]) == 0)
|
2006-06-10 01:44:57 +00:00
|
|
|
return (1);
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
}
|
2008-12-26 22:55:38 +00:00
|
|
|
|
2006-06-10 01:44:57 +00:00
|
|
|
return (0);
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2006-06-10 01:44:57 +00:00
|
|
|
exec_mountprog(const char *name, const char *execname, char *const argv[])
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
{
|
|
|
|
pid_t pid;
|
|
|
|
int status;
|
|
|
|
|
|
|
|
switch (pid = fork()) {
|
|
|
|
case -1: /* Error. */
|
|
|
|
warn("fork");
|
|
|
|
exit (1);
|
|
|
|
case 0: /* Child. */
|
|
|
|
/* Go find an executable. */
|
|
|
|
execvP(execname, _PATH_SYSPATH, argv);
|
|
|
|
if (errno == ENOENT) {
|
2009-03-05 08:57:35 +00:00
|
|
|
warn("exec %s not found", execname);
|
|
|
|
if (execname[0] != '/') {
|
|
|
|
warnx("in path: %s", _PATH_SYSPATH);
|
|
|
|
}
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
}
|
|
|
|
exit(1);
|
|
|
|
default: /* Parent. */
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2006-10-24 22:16:51 +00:00
|
|
|
static int
|
|
|
|
specified_ro(const char *arg)
|
2006-10-24 22:02:29 +00:00
|
|
|
{
|
|
|
|
char *optbuf, *opt;
|
|
|
|
int ret = 0;
|
|
|
|
|
|
|
|
optbuf = strdup(arg);
|
|
|
|
if (optbuf == NULL)
|
|
|
|
err(1, NULL);
|
|
|
|
|
|
|
|
for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
|
|
|
|
if (strcmp(opt, "ro") == 0) {
|
|
|
|
ret = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
free(optbuf);
|
|
|
|
return (ret);
|
|
|
|
}
|
|
|
|
|
2007-02-02 23:58:10 +00:00
|
|
|
static void
|
|
|
|
restart_mountd(void)
|
|
|
|
{
|
|
|
|
struct pidfh *pfh;
|
2008-12-26 22:55:38 +00:00
|
|
|
pid_t mountdpid;
|
2007-02-02 23:58:10 +00:00
|
|
|
|
|
|
|
pfh = pidfile_open(_PATH_MOUNTDPID, 0600, &mountdpid);
|
|
|
|
if (pfh != NULL) {
|
|
|
|
/* Mountd is not running. */
|
|
|
|
pidfile_remove(pfh);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (errno != EEXIST) {
|
|
|
|
/* Cannot open pidfile for some reason. */
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
/* We have mountd(8) PID in mountdpid varible, let's signal it. */
|
|
|
|
if (kill(mountdpid, SIGHUP) == -1)
|
|
|
|
err(1, "signal mountd");
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
2005-10-07 02:18:20 +00:00
|
|
|
main(int argc, char *argv[])
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
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;
|
2011-06-07 18:48:49 +00:00
|
|
|
int all, ch, i, init_flags, late, failok, mntsize, rval, have_fstab, ro;
|
2013-05-04 14:00:16 +00:00
|
|
|
int onlylate;
|
2002-04-22 23:03:03 +00:00
|
|
|
char *cp, *ep, *options;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
2013-05-04 14:00:16 +00:00
|
|
|
all = init_flags = late = onlylate = 0;
|
2006-10-24 22:02:29 +00:00
|
|
|
ro = 0;
|
|
|
|
options = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
vfslist = NULL;
|
|
|
|
vfstype = "ufs";
|
2013-07-15 21:57:21 +00:00
|
|
|
while ((ch = getopt(argc, argv, "adF:fLlno:prt:uvw")) != -1)
|
1994-05-26 06:35:07 +00:00
|
|
|
switch (ch) {
|
|
|
|
case 'a':
|
|
|
|
all = 1;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
debug = 1;
|
|
|
|
break;
|
2003-04-07 12:56:01 +00:00
|
|
|
case 'F':
|
|
|
|
setfstab(optarg);
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'f':
|
|
|
|
init_flags |= MNT_FORCE;
|
|
|
|
break;
|
2013-05-04 14:00:16 +00:00
|
|
|
case 'L':
|
|
|
|
onlylate = 1;
|
|
|
|
late = 1;
|
|
|
|
break;
|
2006-07-12 16:05:51 +00:00
|
|
|
case 'l':
|
|
|
|
late = 1;
|
|
|
|
break;
|
2013-07-15 21:57:21 +00:00
|
|
|
case 'n':
|
|
|
|
/* For compatibility with the Linux version of mount. */
|
|
|
|
break;
|
1994-05-26 06:35:07 +00:00
|
|
|
case 'o':
|
2006-10-24 22:02:29 +00:00
|
|
|
if (*optarg) {
|
|
|
|
options = catopt(options, optarg);
|
|
|
|
if (specified_ro(optarg))
|
|
|
|
ro = 1;
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
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':
|
2001-05-02 02:16:16 +00:00
|
|
|
options = catopt(options, "ro");
|
2006-10-24 22:02:29 +00:00
|
|
|
ro = 1;
|
1994-05-26 06:35:07 +00:00
|
|
|
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':
|
2001-05-02 02:16:16 +00:00
|
|
|
options = catopt(options, "noro");
|
1994-05-26 06:35:07 +00:00
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
default:
|
|
|
|
usage();
|
|
|
|
/* NOTREACHED */
|
|
|
|
}
|
|
|
|
argc -= optind;
|
|
|
|
argv += optind;
|
|
|
|
|
|
|
|
#define BADTYPE(type) \
|
|
|
|
(strcmp(type, FSTAB_RO) && \
|
|
|
|
strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
|
|
|
|
|
2006-10-24 22:02:29 +00:00
|
|
|
if ((init_flags & MNT_UPDATE) && (ro == 0))
|
|
|
|
options = catopt(options, "noro");
|
2008-12-26 22:55:38 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
rval = 0;
|
|
|
|
switch (argc) {
|
|
|
|
case 0:
|
2011-07-30 00:43:18 +00:00
|
|
|
if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
|
1997-08-24 21:02:51 +00:00
|
|
|
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;
|
2013-05-04 14:00:16 +00:00
|
|
|
if (!hasopt(fs->fs_mntops, "late") && onlylate)
|
|
|
|
continue;
|
2006-07-12 16:05:51 +00:00
|
|
|
if (hasopt(fs->fs_mntops, "late") && !late)
|
|
|
|
continue;
|
2011-06-07 18:48:49 +00:00
|
|
|
if (hasopt(fs->fs_mntops, "failok"))
|
|
|
|
failok = 1;
|
|
|
|
else
|
|
|
|
failok = 0;
|
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;
|
2004-01-29 13:16:51 +00:00
|
|
|
options = update_options(options, fs->fs_mntops,
|
|
|
|
mntbuf->f_flags);
|
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,
|
2011-06-07 18:48:49 +00:00
|
|
|
fs->fs_mntops) && !failok)
|
1997-03-12 18:35:10 +00:00
|
|
|
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;
|
2009-09-14 21:08:22 +00:00
|
|
|
if (!verbose &&
|
|
|
|
(mntbuf[i].f_flags & MNT_IGNORE) != 0)
|
|
|
|
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();
|
|
|
|
|
2004-01-07 05:37:56 +00:00
|
|
|
rmslashes(*argv, *argv);
|
1994-05-26 06:35:07 +00:00
|
|
|
if (init_flags & MNT_UPDATE) {
|
1999-10-30 17:40:10 +00:00
|
|
|
mntfromname = NULL;
|
|
|
|
have_fstab = 0;
|
1994-05-26 06:35:07 +00:00
|
|
|
if ((mntbuf = getmntpt(*argv)) == NULL)
|
1999-10-30 17:40:10 +00:00
|
|
|
errx(1, "not currently mounted %s", *argv);
|
|
|
|
/*
|
|
|
|
* Only get the mntflags from fstab if both mntpoint
|
|
|
|
* and mntspec are identical. Also handle the special
|
|
|
|
* case where just '/' is mounted and 'spec' is not
|
|
|
|
* identical with the one from fstab ('/dev' is missing
|
|
|
|
* in the spec-string at boot-time).
|
|
|
|
*/
|
1999-05-07 05:22:08 +00:00
|
|
|
if ((fs = getfsfile(mntbuf->f_mntonname)) != NULL) {
|
1999-10-30 17:40:10 +00:00
|
|
|
if (strcmp(fs->fs_spec,
|
|
|
|
mntbuf->f_mntfromname) == 0 &&
|
|
|
|
strcmp(fs->fs_file,
|
|
|
|
mntbuf->f_mntonname) == 0) {
|
|
|
|
have_fstab = 1;
|
|
|
|
mntfromname = mntbuf->f_mntfromname;
|
|
|
|
} else if (argv[0][0] == '/' &&
|
|
|
|
argv[0][1] == '\0') {
|
|
|
|
fs = getfsfile("/");
|
|
|
|
have_fstab = 1;
|
|
|
|
mntfromname = fs->fs_spec;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (have_fstab) {
|
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)
|
2002-08-21 18:11:48 +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))
|
2002-08-21 18:11:48 +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:
|
|
|
|
/*
|
1999-10-30 17:40:10 +00:00
|
|
|
* If -t flag has not been specified, the path cannot be
|
2002-04-22 23:03:03 +00:00
|
|
|
* found, spec contains either a ':' or a '@', then assume
|
2002-08-21 18:11:48 +00:00
|
|
|
* that an NFS file system is being specified ala Sun.
|
2002-04-22 23:03:03 +00:00
|
|
|
* Check if the hostname contains only allowed characters
|
|
|
|
* to reduce false positives. IPv6 addresses containing
|
|
|
|
* ':' will be correctly parsed only if the separator is '@'.
|
|
|
|
* The definition of a valid hostname is taken from RFC 1034.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
2003-12-05 09:36:56 +00:00
|
|
|
if (vfslist == NULL && ((ep = strchr(argv[0], '@')) != NULL ||
|
|
|
|
(ep = strchr(argv[0], ':')) != NULL)) {
|
2002-04-23 17:24:02 +00:00
|
|
|
if (*ep == '@') {
|
|
|
|
cp = ep + 1;
|
|
|
|
ep = cp + strlen(cp);
|
|
|
|
} else
|
|
|
|
cp = argv[0];
|
2002-04-22 23:03:03 +00:00
|
|
|
while (cp != ep) {
|
|
|
|
if (!isdigit(*cp) && !isalpha(*cp) &&
|
|
|
|
*cp != '.' && *cp != '-' && *cp != ':')
|
|
|
|
break;
|
|
|
|
cp++;
|
|
|
|
}
|
|
|
|
if (cp == ep)
|
|
|
|
vfstype = "nfs";
|
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
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
|
2007-02-02 23:58:10 +00:00
|
|
|
* good news.
|
1994-05-26 06:35:07 +00:00
|
|
|
*/
|
2007-02-02 23:58:10 +00:00
|
|
|
if (rval == 0 && getuid() == 0)
|
|
|
|
restart_mountd();
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
exit(rval);
|
|
|
|
}
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
int
|
2005-10-07 02:18:20 +00:00
|
|
|
ismounted(struct fstab *fs, struct statfs *mntbuf, int mntsize)
|
1997-08-24 21:02:51 +00:00
|
|
|
{
|
2006-01-18 11:00:34 +00:00
|
|
|
char realfsfile[PATH_MAX];
|
1997-08-24 21:02:51 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if (fs->fs_file[0] == '/' && fs->fs_file[1] == '\0')
|
2002-08-21 18:11:48 +00:00
|
|
|
/* the root file system can always be remounted */
|
1997-08-24 21:02:51 +00:00
|
|
|
return (0);
|
|
|
|
|
2006-01-18 11:00:34 +00:00
|
|
|
/* The user may have specified a symlink in fstab, resolve the path */
|
|
|
|
if (realpath(fs->fs_file, realfsfile) == NULL) {
|
|
|
|
/* Cannot resolve the path, use original one */
|
|
|
|
strlcpy(realfsfile, fs->fs_file, sizeof(realfsfile));
|
|
|
|
}
|
|
|
|
|
1997-08-24 21:02:51 +00:00
|
|
|
for (i = mntsize - 1; i >= 0; --i)
|
2006-01-18 11:00:34 +00:00
|
|
|
if (strcmp(realfsfile, mntbuf[i].f_mntonname) == 0 &&
|
1997-08-24 21:02:51 +00:00
|
|
|
(!isremountable(fs->fs_vfstype) ||
|
|
|
|
strcmp(fs->fs_spec, mntbuf[i].f_mntfromname) == 0))
|
|
|
|
return (1);
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2005-10-07 02:18:20 +00:00
|
|
|
isremountable(const char *vfsname)
|
1997-08-24 21:02:51 +00:00
|
|
|
{
|
|
|
|
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
|
2005-10-07 02:18:20 +00:00
|
|
|
hasopt(const char *mntopts, const char *option)
|
1997-03-11 12:28:00 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2009-01-10 20:54:47 +00:00
|
|
|
static void
|
|
|
|
append_arg(struct cpa *sa, char *arg)
|
|
|
|
{
|
2009-01-13 06:08:37 +00:00
|
|
|
if (sa->c + 1 == sa->sz) {
|
|
|
|
sa->sz = sa->sz == 0 ? 8 : sa->sz * 2;
|
|
|
|
sa->a = realloc(sa->a, sizeof(sa->a) * sa->sz);
|
2009-01-12 08:22:36 +00:00
|
|
|
if (sa->a == NULL)
|
|
|
|
errx(1, "realloc failed");
|
|
|
|
}
|
2009-01-10 20:54:47 +00:00
|
|
|
sa->a[++sa->c] = arg;
|
|
|
|
}
|
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
int
|
2005-10-07 02:18:20 +00:00
|
|
|
mountfs(const char *vfstype, const char *spec, const char *name, int flags,
|
|
|
|
const char *options, const char *mntopts)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
struct statfs sf;
|
2008-12-26 22:54:53 +00:00
|
|
|
int i, ret;
|
2003-08-07 04:51:41 +00:00
|
|
|
char *optbuf, execname[PATH_MAX], mntpath[PATH_MAX];
|
2009-01-13 06:08:37 +00:00
|
|
|
static struct cpa mnt_argv;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
1999-10-09 11:54:14 +00:00
|
|
|
/* resolve the mountpoint with realpath(3) */
|
2012-01-16 19:34:21 +00:00
|
|
|
if (checkpath(name, mntpath) != 0) {
|
|
|
|
warn("%s", mntpath);
|
|
|
|
return (1);
|
|
|
|
}
|
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
|
|
|
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");
|
|
|
|
|
2001-06-01 10:57:26 +00:00
|
|
|
/* Compatibility glue. */
|
2007-02-06 05:57:40 +00:00
|
|
|
if (strcmp(vfstype, "msdos") == 0) {
|
|
|
|
warnx(
|
|
|
|
"Using \"-t msdosfs\", since \"-t msdos\" is deprecated.");
|
2001-06-01 10:57:26 +00:00
|
|
|
vfstype = "msdosfs";
|
2007-02-06 05:57:40 +00:00
|
|
|
}
|
2001-06-01 10:57:26 +00:00
|
|
|
|
2005-03-26 04:45:53 +00:00
|
|
|
/* Construct the name of the appropriate mount command */
|
|
|
|
(void)snprintf(execname, sizeof(execname), "mount_%s", vfstype);
|
|
|
|
|
2009-01-10 20:54:47 +00:00
|
|
|
mnt_argv.c = -1;
|
|
|
|
append_arg(&mnt_argv, execname);
|
|
|
|
mangle(optbuf, &mnt_argv);
|
2009-03-05 08:57:35 +00:00
|
|
|
if (mountprog != NULL)
|
|
|
|
strcpy(execname, mountprog);
|
|
|
|
|
2009-01-10 20:54:47 +00:00
|
|
|
append_arg(&mnt_argv, strdup(spec));
|
|
|
|
append_arg(&mnt_argv, strdup(name));
|
|
|
|
append_arg(&mnt_argv, NULL);
|
2008-12-18 18:44:46 +00:00
|
|
|
|
1994-05-26 06:35:07 +00:00
|
|
|
if (debug) {
|
2006-11-14 01:07:42 +00:00
|
|
|
if (use_mountprog(vfstype))
|
2009-03-05 08:57:35 +00:00
|
|
|
printf("exec: %s", execname);
|
2006-11-14 01:07:42 +00:00
|
|
|
else
|
|
|
|
printf("mount -t %s", vfstype);
|
2009-01-10 20:54:47 +00:00
|
|
|
for (i = 1; i < mnt_argv.c; i++)
|
|
|
|
(void)printf(" %s", mnt_argv.a[i]);
|
1994-05-26 06:35:07 +00:00
|
|
|
(void)printf("\n");
|
2011-09-02 17:11:59 +00:00
|
|
|
free(optbuf);
|
|
|
|
free(mountprog);
|
|
|
|
mountprog = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2005-11-21 22:07:54 +00:00
|
|
|
if (use_mountprog(vfstype)) {
|
2009-01-10 20:54:47 +00:00
|
|
|
ret = exec_mountprog(name, execname, mnt_argv.a);
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
} else {
|
2009-01-10 20:54:47 +00:00
|
|
|
ret = mount_fs(vfstype, mnt_argv.c, mnt_argv.a);
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
free(optbuf);
|
2011-09-02 17:11:59 +00:00
|
|
|
free(mountprog);
|
|
|
|
mountprog = NULL;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
if (verbose) {
|
|
|
|
if (statfs(name, &sf) < 0) {
|
|
|
|
warn("statfs %s", name);
|
1994-05-26 06:35:07 +00:00
|
|
|
return (1);
|
|
|
|
}
|
- Minor fixes to raise WARNS level to 6.
- Teach the mount program to call the nmount() syscall directly
- Preserve existing method of calling mount() for UFS, until we clean things
up.
- Preserve existing method of forking and calling external mount programs for
mfs, msdosfs, nfs, nfs4, ntfs, nwfs, nullfs, portalfs, reiserfs, smbfs,
udf, umapfs, unionfs
- devfs, linprocfs, procfs, ext2fs call nmount() syscall directly, since
that is all those external mount programs were doing
Reviewed by: phk
Discussed on: arch
2005-11-12 20:12:56 +00:00
|
|
|
if (fstab_style)
|
|
|
|
putfsent(&sf);
|
|
|
|
else
|
|
|
|
prmount(&sf);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
2008-08-31 20:08:05 +00:00
|
|
|
return (ret);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2005-10-07 02:18:20 +00:00
|
|
|
prmount(struct statfs *sfp)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2010-03-07 16:45:18 +00:00
|
|
|
uint64_t flags;
|
2005-10-07 02:22:04 +00:00
|
|
|
unsigned int i;
|
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;
|
2010-03-07 16:45:18 +00:00
|
|
|
for (o = optnames; flags != 0 && o->o_opt != 0; 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;
|
|
|
|
}
|
2004-02-02 18:37:30 +00:00
|
|
|
/*
|
|
|
|
* Inform when file system is mounted by an unprivileged user
|
|
|
|
* or privileged non-root user.
|
|
|
|
*/
|
2004-02-03 04:03:19 +00:00
|
|
|
if ((flags & MNT_USER) != 0 || sfp->f_owner != 0) {
|
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);
|
|
|
|
}
|
2000-08-23 09:59:25 +00:00
|
|
|
if (verbose) {
|
|
|
|
if (sfp->f_syncwrites != 0 || sfp->f_asyncwrites != 0)
|
2003-12-07 17:00:14 +00:00
|
|
|
(void)printf(", writes: sync %ju async %ju",
|
|
|
|
(uintmax_t)sfp->f_syncwrites,
|
|
|
|
(uintmax_t)sfp->f_asyncwrites);
|
2000-08-23 09:59:25 +00:00
|
|
|
if (sfp->f_syncreads != 0 || sfp->f_asyncreads != 0)
|
2003-12-07 17:00:14 +00:00
|
|
|
(void)printf(", reads: sync %ju async %ju",
|
|
|
|
(uintmax_t)sfp->f_syncreads,
|
|
|
|
(uintmax_t)sfp->f_asyncreads);
|
2003-12-05 09:36:56 +00:00
|
|
|
if (sfp->f_fsid.val[0] != 0 || sfp->f_fsid.val[1] != 0) {
|
|
|
|
printf(", fsid ");
|
|
|
|
for (i = 0; i < sizeof(sfp->f_fsid); i++)
|
|
|
|
printf("%02x", ((u_char *)&sfp->f_fsid)[i]);
|
|
|
|
}
|
2000-08-23 09:59:25 +00:00
|
|
|
}
|
1999-10-08 19:54:32 +00:00
|
|
|
(void)printf(")\n");
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
struct statfs *
|
2005-10-07 02:18:20 +00:00
|
|
|
getmntpt(const char *name)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
struct statfs *mntbuf;
|
|
|
|
int i, mntsize;
|
|
|
|
|
2011-07-30 00:43:18 +00:00
|
|
|
mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
|
1999-10-30 17:40:10 +00:00
|
|
|
for (i = mntsize - 1; i >= 0; i--) {
|
1994-05-26 06:35:07 +00:00
|
|
|
if (strcmp(mntbuf[i].f_mntfromname, name) == 0 ||
|
|
|
|
strcmp(mntbuf[i].f_mntonname, name) == 0)
|
|
|
|
return (&mntbuf[i]);
|
1999-10-30 17:40:10 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
return (NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
char *
|
2005-10-07 02:18:20 +00:00
|
|
|
catopt(char *s0, const char *s1)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
size_t i;
|
|
|
|
char *cp;
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
if (s1 == NULL || *s1 == '\0')
|
2006-06-10 01:44:57 +00:00
|
|
|
return (s0);
|
1999-05-07 05:22:08 +00:00
|
|
|
|
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
|
2009-01-10 20:54:47 +00:00
|
|
|
mangle(char *options, struct cpa *a)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
2009-03-05 08:57:35 +00:00
|
|
|
char *p, *s, *val;
|
1994-05-26 06:35:07 +00:00
|
|
|
|
|
|
|
for (s = options; (p = strsep(&s, ",")) != NULL;)
|
1999-05-07 05:22:08 +00:00
|
|
|
if (*p != '\0') {
|
2005-11-16 02:13:27 +00:00
|
|
|
if (strcmp(p, "noauto") == 0) {
|
|
|
|
/*
|
|
|
|
* Do not pass noauto option to nmount().
|
|
|
|
* or external mount program. noauto is
|
|
|
|
* only used to prevent mounting a filesystem
|
|
|
|
* when 'mount -a' is specified, and is
|
|
|
|
* not a real mount option.
|
|
|
|
*/
|
|
|
|
continue;
|
2006-07-12 16:05:51 +00:00
|
|
|
} else if (strcmp(p, "late") == 0) {
|
|
|
|
/*
|
|
|
|
* "late" is used to prevent certain file
|
|
|
|
* systems from being mounted before late
|
|
|
|
* in the boot cycle; for instance,
|
|
|
|
* loopback NFS mounts can't be mounted
|
|
|
|
* before mountd starts.
|
|
|
|
*/
|
|
|
|
continue;
|
2011-06-07 18:48:49 +00:00
|
|
|
} else if (strcmp(p, "failok") == 0) {
|
|
|
|
/*
|
|
|
|
* "failok" is used to prevent certain file
|
|
|
|
* systems from being causing the system to
|
|
|
|
* drop into single user mode in the boot
|
|
|
|
* cycle, and is not a real mount option.
|
|
|
|
*/
|
|
|
|
continue;
|
2009-03-05 08:57:35 +00:00
|
|
|
} else if (strncmp(p, "mountprog", 9) == 0) {
|
|
|
|
/*
|
|
|
|
* "mountprog" is used to force the use of
|
|
|
|
* userland mount programs.
|
|
|
|
*/
|
|
|
|
val = strchr(p, '=');
|
|
|
|
if (val != NULL) {
|
|
|
|
++val;
|
|
|
|
if (*val != '\0')
|
|
|
|
mountprog = strdup(val);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mountprog == NULL) {
|
|
|
|
errx(1, "Need value for -o mountprog");
|
|
|
|
}
|
|
|
|
continue;
|
2005-11-23 20:17:27 +00:00
|
|
|
} else if (strcmp(p, "userquota") == 0) {
|
|
|
|
continue;
|
2006-05-10 14:40:40 +00:00
|
|
|
} else if (strncmp(p, userquotaeq,
|
|
|
|
sizeof(userquotaeq) - 1) == 0) {
|
|
|
|
continue;
|
2005-11-23 20:17:27 +00:00
|
|
|
} else if (strcmp(p, "groupquota") == 0) {
|
|
|
|
continue;
|
2006-05-10 14:40:40 +00:00
|
|
|
} else if (strncmp(p, groupquotaeq,
|
|
|
|
sizeof(groupquotaeq) - 1) == 0) {
|
|
|
|
continue;
|
2005-11-16 02:13:27 +00:00
|
|
|
} else if (*p == '-') {
|
2009-01-10 20:54:47 +00:00
|
|
|
append_arg(a, p);
|
1994-05-26 06:35:07 +00:00
|
|
|
p = strchr(p, '=');
|
2003-12-07 23:02:16 +00:00
|
|
|
if (p != NULL) {
|
1994-05-26 06:35:07 +00:00
|
|
|
*p = '\0';
|
2009-01-10 20:54:47 +00:00
|
|
|
append_arg(a, p + 1);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
2005-12-03 01:57:58 +00:00
|
|
|
} else {
|
2009-01-10 20:54:47 +00:00
|
|
|
append_arg(a, strdup("-o"));
|
|
|
|
append_arg(a, p);
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
1999-05-07 05:22:08 +00:00
|
|
|
}
|
1994-05-26 06:35:07 +00:00
|
|
|
}
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
|
|
|
|
char *
|
2006-06-10 01:44:57 +00:00
|
|
|
update_options(char *opts, char *fstab, int curflags)
|
1999-05-07 05:22:08 +00:00
|
|
|
{
|
|
|
|
char *o, *p;
|
|
|
|
char *cur;
|
|
|
|
char *expopt, *newopt, *tmpopt;
|
|
|
|
|
|
|
|
if (opts == NULL)
|
2006-06-10 01:44:57 +00:00
|
|
|
return (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);
|
|
|
|
}
|
|
|
|
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");
|
2004-02-17 08:43:05 +00:00
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
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);
|
|
|
|
|
2006-06-10 01:44:57 +00:00
|
|
|
return (newopt);
|
1999-05-07 05:22:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2006-06-10 01:44:57 +00:00
|
|
|
remopt(char *string, const char *opt)
|
1999-05-07 05:22:08 +00:00
|
|
|
{
|
|
|
|
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
|
2006-06-10 01:44:57 +00:00
|
|
|
usage(void)
|
1994-05-26 06:35:07 +00:00
|
|
|
{
|
|
|
|
|
1998-07-06 07:12:38 +00:00
|
|
|
(void)fprintf(stderr, "%s\n%s\n%s\n",
|
2006-07-12 16:05:51 +00:00
|
|
|
"usage: mount [-adflpruvw] [-F fstab] [-o options] [-t ufs | external_type]",
|
2005-02-10 09:19:34 +00:00
|
|
|
" mount [-dfpruvw] special | node",
|
|
|
|
" mount [-dfpruvw] [-o options] [-t ufs | external_type] special node");
|
1994-05-26 06:35:07 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
1996-07-21 23:34:04 +00:00
|
|
|
|
|
|
|
void
|
2008-02-03 17:23:58 +00:00
|
|
|
putfsent(struct statfs *ent)
|
1996-07-21 23:34:04 +00:00
|
|
|
{
|
1997-03-12 18:35:10 +00:00
|
|
|
struct fstab *fst;
|
2010-09-30 13:31:35 +00:00
|
|
|
char *opts, *rw;
|
2007-04-13 21:30:47 +00:00
|
|
|
int l;
|
2004-02-17 08:43:05 +00:00
|
|
|
|
2010-09-30 13:31:35 +00:00
|
|
|
opts = NULL;
|
|
|
|
/* flags2opts() doesn't return the "rw" option. */
|
|
|
|
if ((ent->f_flags & MNT_RDONLY) != 0)
|
|
|
|
rw = NULL;
|
|
|
|
else
|
|
|
|
rw = catopt(NULL, "rw");
|
|
|
|
|
1999-05-07 05:22:08 +00:00
|
|
|
opts = flags2opts(ent->f_flags);
|
2010-09-30 13:31:35 +00:00
|
|
|
opts = catopt(rw, opts);
|
2006-03-03 02:46:15 +00:00
|
|
|
|
2008-02-03 17:23:58 +00:00
|
|
|
if (strncmp(ent->f_mntfromname, "<below>", 7) == 0 ||
|
|
|
|
strncmp(ent->f_mntfromname, "<above>", 7) == 0) {
|
|
|
|
strcpy(ent->f_mntfromname, (strnstr(ent->f_mntfromname, ":", 8)
|
|
|
|
+1));
|
|
|
|
}
|
|
|
|
|
2007-04-13 21:30:47 +00:00
|
|
|
l = strlen(ent->f_mntfromname);
|
|
|
|
printf("%s%s%s%s", ent->f_mntfromname,
|
|
|
|
l < 8 ? "\t" : "",
|
|
|
|
l < 16 ? "\t" : "",
|
|
|
|
l < 24 ? "\t" : " ");
|
|
|
|
l = strlen(ent->f_mntonname);
|
|
|
|
printf("%s%s%s%s", ent->f_mntonname,
|
|
|
|
l < 8 ? "\t" : "",
|
|
|
|
l < 16 ? "\t" : "",
|
|
|
|
l < 24 ? "\t" : " ");
|
|
|
|
printf("%s\t", ent->f_fstypename);
|
2010-09-30 13:31:35 +00:00
|
|
|
l = strlen(opts);
|
|
|
|
printf("%s%s", opts,
|
|
|
|
l < 8 ? "\t" : " ");
|
1999-05-07 05:22:08 +00:00
|
|
|
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);
|
2000-01-15 14:28:14 +00:00
|
|
|
else if (strcmp(ent->f_fstypename, "ufs") == 0) {
|
|
|
|
if (strcmp(ent->f_mntonname, "/") == 0)
|
|
|
|
printf("\t1 1\n");
|
|
|
|
else
|
|
|
|
printf("\t2 2\n");
|
|
|
|
} else
|
1997-03-12 18:35:10 +00:00
|
|
|
printf("\t0 0\n");
|
1996-07-21 23:34:04 +00:00
|
|
|
}
|
1999-05-07 05:22:08 +00:00
|
|
|
|
|
|
|
|
|
|
|
char *
|
2006-06-10 01:44:57 +00:00
|
|
|
flags2opts(int flags)
|
1999-05-07 05:22:08 +00:00
|
|
|
{
|
|
|
|
char *res;
|
|
|
|
|
|
|
|
res = NULL;
|
|
|
|
|
2006-02-25 05:09:47 +00:00
|
|
|
if (flags & MNT_RDONLY) res = catopt(res, "ro");
|
1999-05-07 05:22:08 +00:00
|
|
|
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_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");
|
2002-08-02 07:02:51 +00:00
|
|
|
if (flags & MNT_MULTILABEL) res = catopt(res, "multilabel");
|
2002-10-14 19:40:00 +00:00
|
|
|
if (flags & MNT_ACLS) res = catopt(res, "acls");
|
2009-12-21 19:39:10 +00:00
|
|
|
if (flags & MNT_NFS4ACLS) res = catopt(res, "nfsv4acls");
|
1999-05-07 05:22:08 +00:00
|
|
|
|
2006-06-10 01:44:57 +00:00
|
|
|
return (res);
|
1999-05-07 05:22:08 +00:00
|
|
|
}
|