Add support for filesystem-specific `-o' options, and re-implement the

most common cd9660 and nfs options like God intended them.  (It is now
possible to say

	mount -o ro,soft,bg,intr there:/foo/bar /foo/bar

again.)  This whole getmntopt() business is an incredible botch;
it never should have been anything more than a wrapper around
getsubopt(3).  Because if the way the current hackaround is implemented,
options which take arguments (like the old `rsize' and `wsize') are still
unavailable, and must be accessed the new, broken way.

(It's unimaginable how Berkeley managed to screw up one of the few things
about NFS that Sun actually got right to begin with!)
This commit is contained in:
Garrett Wollman 1994-11-01 23:51:53 +00:00
parent f23c6e08df
commit 3fa88dec7f
27 changed files with 169 additions and 65 deletions

View File

@ -29,7 +29,7 @@
*/
#ifndef lint
static char rcsid[] = "$Id: mount_msdos.c,v 1.1 1994/09/19 15:30:36 dfr Exp $";
static char rcsid[] = "$Id: mount_msdos.c,v 1.2 1994/09/22 22:16:35 wollman Exp $";
#endif /* not lint */
#include <sys/cdefs.h>
@ -87,7 +87,7 @@ main(argc, argv)
set_mask = 1;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <mntopts.h>
.Ft void
.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp"
.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp" "int *altflagp"
.Sh DESCRIPTION
The
.Nm getmntopts
@ -54,8 +54,13 @@ is broken down into a sequence of comma separated tokens.
Each token is looked up in the table described by
.Dv mopts
and the bits in
the word referenced by
the word referenced by either
.Dv flagp
or
.Dv altflagp
(depending on the
.Dv m_altloc
field of the option's table entry)
are updated.
The flag word is not initialized by
.Nm getmntopt .
@ -67,6 +72,7 @@ struct mntopt {
char *m_option; /* option name */
int m_inverse; /* is this a negative option, eg "dev" */
int m_flag; /* bit to set, eg MNT_RDONLY */
int m_altloc; /* non-zero to use altflagp rather than flagp */
};
.Ed
.Pp
@ -100,6 +106,11 @@ by the letters
The
.Dv m_inverse
flag causes these two operations to be reversed.
.It Fa m_altloc
the bit should be set or cleared in
.Dv altflagp
rather than
.Dv flagp .
.El
.Pp
Each of the user visible

View File

@ -46,15 +46,19 @@ static char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94";
#include "mntopts.h"
int getmnt_silent = 0;
void
getmntopts(options, m0, flagp)
getmntopts(options, m0, flagp, altflagp)
const char *options;
const struct mntopt *m0;
int *flagp;
int *altflagp;
{
const struct mntopt *m;
int negative, len;
char *opt, *optbuf;
int *thisflagp;
/* Copy option string, since it is about to be torn asunder... */
if ((optbuf = strdup(options)) == NULL)
@ -80,12 +84,14 @@ getmntopts(options, m0, flagp)
/* Save flag, or fail if option is not recognised. */
if (m->m_option) {
thisflagp = m->m_altloc ? altflagp : flagp;
if (negative == m->m_inverse)
*flagp |= m->m_flag;
*thisflagp |= m->m_flag;
else
*flagp &= ~m->m_flag;
} else
*thisflagp &= ~m->m_flag;
} else if(!getmnt_silent) {
errx(1, "-o %s: option not supported", opt);
}
}
free(optbuf);

View File

@ -37,28 +37,29 @@ struct mntopt {
const char *m_option; /* option name */
int m_inverse; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
int m_altloc; /* zero if this is a real mount flag */
};
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC }
#define MOPT_NODEV { "dev", 1, MNT_NODEV }
#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC }
#define MOPT_NOSUID { "suid", 1, MNT_NOSUID }
#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS }
#define MOPT_UNION { "union", 0, MNT_UNION }
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 }
#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 }
#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 }
#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
/* Skip this options without any action (needed for checkquota/quotaon) */
#define MOPT_UQUOTA { "userquota", 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0 }
#define MOPT_UQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0, 0 }
/* Control flags. */
#define MOPT_FORCE { "force", 1, MNT_FORCE }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE }
#define MOPT_FORCE { "force", 1, MNT_FORCE, 0 }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
/* Support for old-style "ro", "rw" flags. */
#define MOPT_RO { "ro", 0, MNT_RDONLY }
#define MOPT_RW { "rw", 1, MNT_RDONLY }
#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
#define MOPT_FSTAB_COMPAT \
MOPT_RO, \
@ -73,4 +74,5 @@ struct mntopt {
MOPT_RDONLY, \
MOPT_UNION
void getmntopts __P((const char *, const struct mntopt *, int *));
void getmntopts __P((const char *, const struct mntopt *, int *, int *));
extern int getmnt_silent;

View File

@ -81,7 +81,7 @@ mount_ufs(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -63,6 +63,9 @@ static char sccsid[] = "@(#)mount_cd9660.c 8.4 (Berkeley) 3/27/94";
struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_UPDATE,
{ "extatt", 0, ISOFSMNT_EXTATT, 1 },
{ "gens", 0, ISOFSMNT_GENS, 1 },
{ "rrip", 1, ISOFSMNT_NORRIP, 1 },
{ NULL }
};
@ -88,7 +91,7 @@ main(argc, argv)
opts |= ISOFSMNT_GENS;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, &opts);
break;
case 'r':
opts |= ISOFSMNT_NORRIP;

View File

@ -75,7 +75,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -40,7 +40,7 @@
.Sh SYNOPSIS
.Fd #include <mntopts.h>
.Ft void
.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp"
.Fn getmntopts "char *options" "struct mntopt *mopts" "int *flagp" "int *altflagp"
.Sh DESCRIPTION
The
.Nm getmntopts
@ -54,8 +54,13 @@ is broken down into a sequence of comma separated tokens.
Each token is looked up in the table described by
.Dv mopts
and the bits in
the word referenced by
the word referenced by either
.Dv flagp
or
.Dv altflagp
(depending on the
.Dv m_altloc
field of the option's table entry)
are updated.
The flag word is not initialized by
.Nm getmntopt .
@ -67,6 +72,7 @@ struct mntopt {
char *m_option; /* option name */
int m_inverse; /* is this a negative option, eg "dev" */
int m_flag; /* bit to set, eg MNT_RDONLY */
int m_altloc; /* non-zero to use altflagp rather than flagp */
};
.Ed
.Pp
@ -100,6 +106,11 @@ by the letters
The
.Dv m_inverse
flag causes these two operations to be reversed.
.It Fa m_altloc
the bit should be set or cleared in
.Dv altflagp
rather than
.Dv flagp .
.El
.Pp
Each of the user visible

View File

@ -46,15 +46,19 @@ static char sccsid[] = "@(#)getmntopts.c 8.1 (Berkeley) 3/27/94";
#include "mntopts.h"
int getmnt_silent = 0;
void
getmntopts(options, m0, flagp)
getmntopts(options, m0, flagp, altflagp)
const char *options;
const struct mntopt *m0;
int *flagp;
int *altflagp;
{
const struct mntopt *m;
int negative, len;
char *opt, *optbuf;
int *thisflagp;
/* Copy option string, since it is about to be torn asunder... */
if ((optbuf = strdup(options)) == NULL)
@ -80,12 +84,14 @@ getmntopts(options, m0, flagp)
/* Save flag, or fail if option is not recognised. */
if (m->m_option) {
thisflagp = m->m_altloc ? altflagp : flagp;
if (negative == m->m_inverse)
*flagp |= m->m_flag;
*thisflagp |= m->m_flag;
else
*flagp &= ~m->m_flag;
} else
*thisflagp &= ~m->m_flag;
} else if(!getmnt_silent) {
errx(1, "-o %s: option not supported", opt);
}
}
free(optbuf);

View File

@ -37,28 +37,29 @@ struct mntopt {
const char *m_option; /* option name */
int m_inverse; /* if a negative option, eg "dev" */
int m_flag; /* bit to set, eg. MNT_RDONLY */
int m_altloc; /* zero if this is a real mount flag */
};
/* User-visible MNT_ flags. */
#define MOPT_ASYNC { "async", 0, MNT_ASYNC }
#define MOPT_NODEV { "dev", 1, MNT_NODEV }
#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC }
#define MOPT_NOSUID { "suid", 1, MNT_NOSUID }
#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS }
#define MOPT_UNION { "union", 0, MNT_UNION }
#define MOPT_ASYNC { "async", 0, MNT_ASYNC, 0 }
#define MOPT_NODEV { "dev", 1, MNT_NODEV, 0 }
#define MOPT_NOEXEC { "exec", 1, MNT_NOEXEC, 0 }
#define MOPT_NOSUID { "suid", 1, MNT_NOSUID, 0 }
#define MOPT_RDONLY { "rdonly", 0, MNT_RDONLY, 0 }
#define MOPT_SYNC { "sync", 0, MNT_SYNCHRONOUS, 0 }
#define MOPT_UNION { "union", 0, MNT_UNION, 0 }
/* Skip this options without any action (needed for checkquota/quotaon) */
#define MOPT_UQUOTA { "userquota", 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0 }
#define MOPT_UQUOTA { "userquota", 0, 0, 0 }
#define MOPT_GQUOTA { "groupquota", 0, 0, 0 }
/* Control flags. */
#define MOPT_FORCE { "force", 1, MNT_FORCE }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE }
#define MOPT_FORCE { "force", 1, MNT_FORCE, 0 }
#define MOPT_UPDATE { "update", 0, MNT_UPDATE, 0 }
/* Support for old-style "ro", "rw" flags. */
#define MOPT_RO { "ro", 0, MNT_RDONLY }
#define MOPT_RW { "rw", 1, MNT_RDONLY }
#define MOPT_RO { "ro", 0, MNT_RDONLY, 0 }
#define MOPT_RW { "rw", 1, MNT_RDONLY, 0 }
#define MOPT_FSTAB_COMPAT \
MOPT_RO, \
@ -73,4 +74,5 @@ struct mntopt {
MOPT_RDONLY, \
MOPT_UNION
void getmntopts __P((const char *, const struct mntopt *, int *));
void getmntopts __P((const char *, const struct mntopt *, int *, int *));
extern int getmnt_silent;

View File

@ -81,7 +81,7 @@ mount_ufs(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -75,7 +75,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -85,7 +85,7 @@ main(argc, argv)
noclean = 1;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case 's':
short_rds = 1;

View File

@ -29,7 +29,7 @@
*/
#ifndef lint
static char rcsid[] = "$Id: mount_msdos.c,v 1.1 1994/09/19 15:30:36 dfr Exp $";
static char rcsid[] = "$Id: mount_msdos.c,v 1.2 1994/09/22 22:16:35 wollman Exp $";
#endif /* not lint */
#include <sys/cdefs.h>
@ -87,7 +87,7 @@ main(argc, argv)
set_mask = 1;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -29,7 +29,7 @@
*/
#ifndef lint
static char rcsid[] = "$Id: mount_msdos.c,v 1.1 1994/09/19 15:30:36 dfr Exp $";
static char rcsid[] = "$Id: mount_msdos.c,v 1.2 1994/09/22 22:16:35 wollman Exp $";
#endif /* not lint */
#include <sys/cdefs.h>
@ -87,7 +87,7 @@ main(argc, argv)
set_mask = 1;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -86,10 +86,41 @@ static char sccsid[] = "@(#)mount_nfs.c 8.3 (Berkeley) 3/27/94";
#include "mntopts.h"
#define ALTF_BG 0x1
#define ALTF_NOCONN 0x2
#define ALTF_DUMBTIMR 0x4
#define ALTF_INTR 0x8
#define ALTF_KERB 0x10
#define ALTF_NQLOOKLSE 0x20
#define ALTF_RDIRALOOK 0x40
#define ALTF_MYWRITE 0x80
#define ALTF_RESVPORT 0x100
#define ALTF_SEQPACKET 0x200
#define ALTF_NQNFS 0x400
#define ALTF_SOFT 0x800
#define ALTF_TCP 0x1000
struct mntopt mopts[] = {
MOPT_STDOPTS,
MOPT_FORCE,
MOPT_UPDATE,
{ "bg", 0, ALTF_BG, 1 },
{ "conn", 1, ALTF_NOCONN, 1 },
{ "dumbtimer", 0, ALTF_DUMBTIMR, 1 },
{ "intr", 0, ALTF_INTR, 1 },
#ifdef KERBEROS
{ "kerb", 0, ALTF_KERB, 1 },
#endif
{ "nqlooklease", 0, ALTF_NQLOOKLSE, 1 },
{ "rdiralook", 0, ALTF_RDIRALOOK, 1 },
{ "mywrite", 0, ALTF_MYWRITE, 1 },
{ "resvport", 0, ALTF_RESVPORT, 1 },
#ifdef ISO
{ "seqpacket", 0, ALTF_SEQPACKET, 1 },
#endif
{ "nqnfs", 0, ALTF_NQNFS, 1 },
{ "soft", 0, ALTF_SOFT, 1 },
{ "tcp", 0, ALTF_TCP, 1 },
{ NULL }
};
@ -145,7 +176,7 @@ main(argc, argv)
register struct nfs_args *nfsargsp;
struct nfs_args nfsargs;
struct nfsd_cargs ncd;
int mntflags, i, nfssvc_flag, num;
int mntflags, altflags, i, nfssvc_flag, num;
char *name, *p, *spec;
int error = 0;
struct vfsconf *vfc;
@ -160,6 +191,7 @@ main(argc, argv)
retrycnt = DEF_RETRY;
mntflags = 0;
altflags = 0;
nfsargs = nfsdefargs;
nfsargsp = &nfsargs;
while ((c = getopt(argc, argv,
@ -227,7 +259,38 @@ main(argc, argv)
break;
#endif
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, &altflags);
if(altflags & ALTF_BG)
opflags |= BGRND;
if(altflags & ALTF_NOCONN)
nfsargsp->flags |= NFSMNT_NOCONN;
if(altflags & ALTF_DUMBTIMR)
nfsargsp->flags |= NFSMNT_DUMBTIMR;
if(altflags & ALTF_INTR)
nfsargsp->flags |= NFSMNT_INT;
#ifdef KERBEROS
if(altflags & ALTF_KERB)
nfsargsp->flags |= NFSMNT_KERB;
#endif
if(altflags & ALTF_NQLOOKLSE)
nfsargsp->flags |= NFSMNT_NQLOOKLEASE;
if(altflags & ALTF_RDIRALOOK)
nfsargsp->flags |= NFSMNT_RDIRALOOK;
if(altflags & ALTF_MYWRITE)
nfsargsp->flags |= NFSMNT_MYWRITE;
if(altflags & ALTF_RESVPORT)
nfsargsp->flags |= NFSMNT_RESVPORT;
#ifdef ISO
if(altflags & ALTF_SEQPACKET)
nfsargsp->sotype = SOCK_SEQPACKET;
#endif
if(altflags & ALTF_NQNFS)
nfsargsp->flags |= NFSMNT_NQNFS;
if(altflags & ALTF_SOFT)
nfsargsp->flags |= NFSMNT_SOFT;
if(altflags & ALTF_TCP)
nfsargsp->sotype = SOCK_STREAM;
altflags = 0;
break;
case 'P':
nfsargsp->flags |= NFSMNT_RESVPORT;

View File

@ -78,7 +78,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch(ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -78,7 +78,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch(ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -109,7 +109,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF) {
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
default:
error = 1;

View File

@ -109,7 +109,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF) {
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
default:
error = 1;

View File

@ -75,7 +75,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF)
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case '?':
default:

View File

@ -105,7 +105,7 @@ main(argc, argv)
gmapfile = optarg;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case 'u':
mapfile = optarg;

View File

@ -105,7 +105,7 @@ main(argc, argv)
gmapfile = optarg;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case 'u':
mapfile = optarg;

View File

@ -84,7 +84,7 @@ main(argc, argv)
args.mntflags |= UNMNT_BELOW;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case 'r':
args.mntflags &= ~UNMNT_OPMASK;

View File

@ -84,7 +84,7 @@ main(argc, argv)
args.mntflags |= UNMNT_BELOW;
break;
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
case 'r':
args.mntflags &= ~UNMNT_OPMASK;

View File

@ -291,7 +291,7 @@ main(argc, argv)
break;
case 'o':
if (mfs)
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
else {
if (strcmp(optarg, "space") == 0)
opt = FS_OPTSPACE;

View File

@ -109,7 +109,7 @@ main(argc, argv)
while ((ch = getopt(argc, argv, "o:")) != EOF) {
switch (ch) {
case 'o':
getmntopts(optarg, mopts, &mntflags);
getmntopts(optarg, mopts, &mntflags, 0);
break;
default:
error = 1;