no newlines on err(3) calls; section 3 sets errno, too
[unix-history] / usr / src / sbin / mount / mount.c
index bc49c5c..6044ff9 100644 (file)
 /*
 /*
- * Copyright (c) 1980, 1989 The Regents of the University of California.
- * All rights reserved.
+ * Copyright (c) 1980, 1989, 1993
+ *     The Regents of the University of California.  All rights reserved.
  *
  *
- * Redistribution and use in source and binary forms are permitted
- * provided that the above copyright notice and this paragraph are
- * duplicated in all such forms and that any documentation,
- * advertising materials, and other materials related to such
- * distribution and use acknowledge that the software was developed
- * by the University of California, Berkeley.  The name of the
- * University may not be used to endorse or promote products derived
- * from this software without specific prior written permission.
- * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
- * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-char copyright[] =
-"@(#) Copyright (c) 1980, 1989 The Regents of the University of California.\n\
- All rights reserved.\n";
+static char copyright[] =
+"@(#) Copyright (c) 1980, 1989, 1993\n\
      The Regents of the University of California.  All rights reserved.\n";
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mount.c    5.29 (Berkeley) %G%";
+static char sccsid[] = "@(#)mount.c    8.11 (Berkeley) %G%";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "pathnames.h"
 #include <sys/param.h>
 #include <sys/param.h>
-#include <sys/file.h>
-#include <sys/time.h>
 #include <sys/wait.h>
 #include <sys/wait.h>
-#include <fstab.h>
+#include <sys/mount.h>
+
+#include <err.h>
 #include <errno.h>
 #include <errno.h>
-#include <stdio.h>
+#include <fstab.h>
 #include <signal.h>
 #include <signal.h>
-#include <strings.h>
-#include <sys/mount.h>
-#ifdef NFS
-#include <sys/socket.h>
-#include <sys/socketvar.h>
-#include <netdb.h>
-#include <rpc/rpc.h>
-#include <rpc/pmap_clnt.h>
-#include <rpc/pmap_prot.h>
-#include <nfs/rpcv2.h>
-#include <nfs/nfsv2.h>
-#include <nfs/nfs.h>
-#endif
-
-#define DEFAULT_ROOTUID        -2
-
-#define        BADTYPE(type) \
-       (strcmp(type, FSTAB_RO) && strcmp(type, FSTAB_RW) && \
-           strcmp(type, FSTAB_RQ))
-#define        SETTYPE(type) \
-       (!strcmp(type, FSTAB_RW) || !strcmp(type, FSTAB_RQ))
-
-int fake, verbose, updateflg, mnttype;
-char *mntname, **envp;
-char **vfslist, **makevfslist();
-
-#ifdef NFS
-int xdr_dir(), xdr_fh();
-char *getnfsargs();
-struct nfs_args nfsargs = {
-       (struct sockaddr_in *)0,
-       (nfsv2fh_t *)0,
-       0,
-       NFS_WSIZE,
-       NFS_RSIZE,
-       NFS_TIMEO,
-       NFS_RETRANS,
-       (char *)0,
-};
-
-struct nfhret {
-       u_long  stat;
-       nfsv2fh_t nfh;
-};
-#define        DEF_RETRY       10000
-int retrycnt;
-#define        BGRND   1
-#define        ISBGRND 2
-int opflags = 0;
-#endif
-
-main(argc, argv, arge)
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+#include "pathnames.h"
+
+
+int debug, force, verbose, mnttype, skipvfs;
+char *mntname;
+
+int    badvfsname __P((char *, char **));
+int    badvfstype __P((int, char **));
+int    getexecopts __P((char *, char **));
+struct statfs
+      *getmntpt __P((char *));
+int    getmnttype __P((char *));
+void   getstdopts __P((char *, int *));
+void   getufsopts __P((char *, int *));
+char **makevfslist __P((char *));
+int    mountfs __P((char *, char *, int, char *, char *, char *));
+void   prmount __P((char *, char *, int));
+void   usage __P((void));
+
+int
+main(argc, argv)
        int argc;
        int argc;
-       char **argv;
-       char **arge;
+       char *argv[];
 {
 {
-       extern char *optarg;
-       extern int optind;
-       register struct fstab *fs;
-       register int cnt;
-       int all, ch, rval, flags, ret, pid, i;
-       long mntsize;
-       struct statfs *mntbuf, *getmntpt();
-       char *type, *options = NULL;
+       struct fstab *fs;
+       struct statfs *mntbuf;
        FILE *pidfile;
        FILE *pidfile;
+       long mntsize;
+       int all, ch, i, pid, ret, rval, updateflg;
+       char *cp, *type, *options, **vfslist;
 
 
-       envp = arge;
-       all = 0;
-       type = NULL;
-       mnttype = MOUNT_UFS;
        mntname = "ufs";
        mntname = "ufs";
-       while ((ch = getopt(argc, argv, "afrwuvt:o:")) != EOF)
-               switch((char)ch) {
+       mnttype = MOUNT_UFS;
+
+       all = updateflg = 0;
+       options = type = NULL;
+       vfslist = NULL;
+       while ((ch = getopt(argc, argv, "adfo:rwt:uv")) != EOF)
+               switch(ch) {
                case 'a':
                        all = 1;
                        break;
                case 'a':
                        all = 1;
                        break;
+               case 'd':
+                       debug = 1;
+                       break;
                case 'f':
                case 'f':
-                       fake = 1;
+                       force = 1;
+                       break;
+               case 'o':
+                       options = optarg;
                        break;
                case 'r':
                        type = FSTAB_RO;
                        break;
                        break;
                case 'r':
                        type = FSTAB_RO;
                        break;
+               case 't':
+                       vfslist = makevfslist(optarg);
+                       mnttype = getmnttype(optarg);
+                       break;
                case 'u':
                case 'u':
-                       updateflg = M_UPDATE;
+                       updateflg = MNT_UPDATE;
                        break;
                case 'v':
                        verbose = 1;
                        break;
                case 'v':
                        verbose = 1;
@@ -125,13 +95,6 @@ main(argc, argv, arge)
                case 'w':
                        type = FSTAB_RW;
                        break;
                case 'w':
                        type = FSTAB_RW;
                        break;
-               case 'o':
-                       options = optarg;
-                       break;
-               case 't':
-                       vfslist = makevfslist(optarg);
-                       mnttype = getmnttype(optarg);
-                       break;
                case '?':
                default:
                        usage();
                case '?':
                default:
                        usage();
@@ -140,96 +103,125 @@ main(argc, argv, arge)
        argc -= optind;
        argv += optind;
 
        argc -= optind;
        argv += optind;
 
-       /* NOSTRICT */
+#define        BADTYPE(type)                                                   \
+       (strcmp(type, FSTAB_RO) &&                                      \
+           strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ))
 
        if (all) {
                rval = 0;
 
        if (all) {
                rval = 0;
-               while (fs = getfsent()) {
+               while ((fs = getfsent()) != NULL) {
                        if (BADTYPE(fs->fs_type))
                                continue;
                        if (BADTYPE(fs->fs_type))
                                continue;
-                       if (badvfstype(fs->fs_vfstype, vfslist))
+                       if (badvfsname(fs->fs_vfstype, vfslist))
                                continue;
                                continue;
-                       /* `/' is special, it's always mounted */
-                       if (!strcmp(fs->fs_file, "/"))
-                               flags = M_UPDATE;
-                       else
-                               flags = updateflg;
+                       /* `/' is special, it's always mounted. */
                        mnttype = getmnttype(fs->fs_vfstype);
                        mnttype = getmnttype(fs->fs_vfstype);
-                       rval |= mountfs(fs->fs_spec, fs->fs_file, flags,
+                       rval |= mountfs(fs->fs_spec, fs->fs_file, updateflg,
                            type, options, fs->fs_mntops);
                }
                exit(rval);
        }
 
        if (argc == 0) {
                            type, options, fs->fs_mntops);
                }
                exit(rval);
        }
 
        if (argc == 0) {
-               if (verbose || fake || type)
+               if (verbose || debug || type)
                        usage();
                        usage();
-               if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
-                       fprintf(stderr,
-                               "mount: cannot get mount information\n");
-                       exit(1);
+               if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
+                       err(1, "getmntinfo");
+               for (i = 0; i < mntsize; i++) {
+                       if (badvfstype(mntbuf[i].f_type, vfslist))
+                               continue;
+                       prmount(mntbuf[i].f_mntfromname,
+                            mntbuf[i].f_mntonname, mntbuf[i].f_flags);
                }
                }
-               for (i = 0; i < mntsize; i++)
-                       prmount(mntbuf[i].f_mntfromname, mntbuf[i].f_mntonname,
-                               mntbuf[i].f_flags);
                exit(0);
        }
 
                exit(0);
        }
 
+       if (argc == 1 && vfslist != NULL)
+               usage();
+
        if (argc == 1 && updateflg) {
        if (argc == 1 && updateflg) {
-               if ((mntbuf = getmntpt(*argv)) == NULL) {
-                       fprintf(stderr,
-                           "mount: unknown special file or file system %s.\n",
-                           *argv);
-                       exit(1);
-               }
+               if ((mntbuf = getmntpt(*argv)) == NULL)
+                       errx(1,
+                           "unknown special file or file system %s.", *argv);
                mnttype = mntbuf->f_type;
                mnttype = mntbuf->f_type;
-               if (!strcmp(mntbuf->f_mntfromname, "root_device")) {
-                       fs = getfsfile("/");
-                       strcpy(mntbuf->f_mntfromname, fs->fs_spec);
+               if ((fs = getfsfile(mntbuf->f_mntonname)) == NULL)
+                       errx(1, "can't find fstab entry for %s.", *argv);
+               mntname = fs->fs_vfstype;
+
+               /*
+                * Default type to fstab version if none specified on the
+                * command line.
+                */
+               if (type == NULL)
+                       type = fs->fs_type;
+
+               /*
+                * Default options to fstab version if none specified on the
+                * command line.
+                */
+               if (options == NULL)
+                       options = fs->fs_mntops;
+               else {
+                       /*
+                        * Concat the two strings with the command line
+                        * options last so that they will override the
+                        * fstab options.
+                        */
+                       i = strlen(fs->fs_mntops) + strlen(options) + 2;
+                       if ((cp = malloc((size_t)i)) == NULL)
+                               err(1, NULL);
+                       (void)snprintf(cp, i, "%s,%s", fs->fs_mntops, options);
+                       options = cp;
                }
                }
-               ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
-                   updateflg, type, options, NULL);
+               ret = mountfs(fs->fs_spec,
+                   mntbuf->f_mntonname, updateflg, type, options, NULL);
        } else if (argc == 1) {
        } else if (argc == 1) {
-               if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
-                       fprintf(stderr,
-                           "mount: unknown special file or file system %s.\n",
-                           *argv);
-                       exit(1);
-               }
-               if (BADTYPE(fs->fs_type)) {
-                       fprintf(stderr,
-                           "mount: %s has unknown file system type.\n", *argv);
-                       exit(1);
-               }
+               if ((fs = getfsfile(*argv)) == NULL &&
+                   (fs = getfsspec(*argv)) == NULL)
+                       errx(1,
+                           "unknown special file or file system %s.", *argv);
+               if (BADTYPE(fs->fs_type))
+                       errx(1, "%s has unknown file system type.", *argv);
                mnttype = getmnttype(fs->fs_vfstype);
                mnttype = getmnttype(fs->fs_vfstype);
-               ret = mountfs(fs->fs_spec, fs->fs_file, updateflg,
-                   type, options, fs->fs_mntops);
+               ret = mountfs(fs->fs_spec,
+                   fs->fs_file, updateflg, type, options, fs->fs_mntops);
        } else if (argc != 2) {
                usage();
                ret = 1;
        } else {
        } else if (argc != 2) {
                usage();
                ret = 1;
        } else {
+               /*
+                * 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 &&
+                   (strchr(argv[0], ':') || strchr(argv[0], '@'))) {
+                       mnttype = MOUNT_NFS;
+                       mntname = "nfs";
+               }
                ret = mountfs(argv[0], argv[1], updateflg, type, options, NULL);
        }
        if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
                pid = 0;
                ret = mountfs(argv[0], argv[1], updateflg, type, options, NULL);
        }
        if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
                pid = 0;
-               fscanf(pidfile, "%d", &pid);
-               fclose(pidfile);
-               if (pid > 0)
-                       kill(pid, SIGHUP);
+               (void)fscanf(pidfile, "%ld", &pid);
+               (void)fclose(pidfile);
+               if (pid > 0 && kill(pid, SIGHUP))
+                       err(1, "signal mountd");
        }
        }
-       exit (ret);
+
+       exit(ret);
 }
 
 }
 
+int
 mountfs(spec, name, flags, type, options, mntopts)
        char *spec, *name, *type, *options, *mntopts;
        int flags;
 {
 mountfs(spec, name, flags, type, options, mntopts)
        char *spec, *name, *type, *options, *mntopts;
        int flags;
 {
-       extern int errno;
-       register int cnt;
-       int argc, status, i;
        struct ufs_args args;
        struct ufs_args args;
+       pid_t pid;
+       int argc, i, status;
        char *argp, *argv[50];
        char *argp, *argv[50];
-       char execname[MAXPATHLEN + 1], flagval[12];
+       char execname[MAXPATHLEN + 1], flagval[12], mntpath[MAXPATHLEN];
 
        if (mntopts)
                getstdopts(mntopts, &flags);
 
        if (mntopts)
                getstdopts(mntopts, &flags);
@@ -237,6 +229,19 @@ mountfs(spec, name, flags, type, options, mntopts)
                getstdopts(options, &flags);
        if (type)
                getstdopts(type, &flags);
                getstdopts(options, &flags);
        if (type)
                getstdopts(type, &flags);
+       if (force)
+               flags |= MNT_FORCE;
+
+       if (realpath(name, mntpath) == 0) {
+               warn("%s", mntpath);
+               return (1);
+       }
+
+       name = mntpath;
+
+       if (strcmp(name, "/") == 0)
+               flags |= MNT_UPDATE;
+
        switch (mnttype) {
        case MOUNT_UFS:
                if (mntopts)
        switch (mnttype) {
        case MOUNT_UFS:
                if (mntopts)
@@ -244,33 +249,22 @@ mountfs(spec, name, flags, type, options, mntopts)
                if (options)
                        getufsopts(options, &flags);
                args.fspec = spec;
                if (options)
                        getufsopts(options, &flags);
                args.fspec = spec;
-               args.exroot = DEFAULT_ROOTUID;
-               if (flags & M_RDONLY)
-                       args.exflags = M_EXRDONLY;
+#define        DEFAULT_ROOTUID -2
+               args.export.ex_root = DEFAULT_ROOTUID;
+               if (flags & MNT_RDONLY)
+                       args.export.ex_flags = MNT_EXRDONLY;
                else
                else
-                       args.exflags = 0;
+                       args.export.ex_flags = 0;
                argp = (caddr_t)&args;
                break;
                argp = (caddr_t)&args;
                break;
-
-#ifdef NFS
-       case MOUNT_NFS:
-               retrycnt = DEF_RETRY;
-               if (mntopts)
-                       getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
-               if (options)
-                       getnfsopts(options, &nfsargs, &opflags, &retrycnt);
-               if (argp = getnfsargs(spec, name, type))
-                       break;
-               return (1);
-#endif /* NFS */
-
        case MOUNT_MFS:
        case MOUNT_MFS:
+       case MOUNT_NFS:
        default:
                argv[0] = mntname;
                argc = 1;
                if (flags) {
                        argv[argc++] = "-F";
        default:
                argv[0] = mntname;
                argc = 1;
                if (flags) {
                        argv[argc++] = "-F";
-                       sprintf(flagval, "%d", flags);
+                       (void)snprintf(flagval, sizeof(flagval), "%d", flags);
                        argv[argc++] = flagval;
                }
                if (mntopts)
                        argv[argc++] = flagval;
                }
                if (mntopts)
@@ -280,185 +274,195 @@ mountfs(spec, name, flags, type, options, mntopts)
                argv[argc++] = spec;
                argv[argc++] = name;
                argv[argc++] = NULL;
                argv[argc++] = spec;
                argv[argc++] = name;
                argv[argc++] = NULL;
-               sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
+               snprintf(execname, sizeof(execname),
+                   "%s/mount_%s", _PATH_EXECDIR, mntname);
                if (verbose) {
                if (verbose) {
-                       printf("exec: %s", execname);
-                       for (i = 1; i < argc; i++)
-                               printf(" %s", argv[i]);
-                       printf("\n");
+                       (void)printf("exec: %s", execname);
+                       for (i = 1; i < argc - 1; i++)
+                               (void)printf(" %s", argv[i]);
+                       (void)printf("\n");
                }
                }
-               if (fake)
+               if (debug)
                        break;
                        break;
-               if (i = vfork()) {
-                       if (i == -1) {
-                               perror("mount: vfork starting file system");
+               if (pid = vfork()) {
+                       if (pid == -1) {
+                               warn("vfork starting file system");
                                return (1);
                        }
                                return (1);
                        }
-                       if (waitpid(i, &status, 0) != -1 &&
+                       if (waitpid(pid, &status, 0) != -1 &&
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
                        spec = mntname;
                        goto out;
                }
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
                        spec = mntname;
                        goto out;
                }
-               execve(execname, argv, envp);
-               fprintf(stderr, "mount: cannot exec %s for %s: ",
-                       execname, name);
-               perror("");
-               exit (1);
+               execv(execname, argv);
+               err(1, "cannot exec %s for %s", execname, name);
                /* NOTREACHED */
 
        }
                /* NOTREACHED */
 
        }
-       if (!fake && mount(mnttype, name, flags, argp)) {
-               if (opflags & ISBGRND)
-                       exit(1);
-               fprintf(stderr, "%s on %s: ", spec, name);
+       if (!debug && mount(mnttype, name, flags, argp)) {
+               (void)fprintf(stderr, "%s on %s: ", spec, name);
                switch (errno) {
                case EMFILE:
                switch (errno) {
                case EMFILE:
-                       fprintf(stderr, "Mount table full\n");
+                       (void)fprintf(stderr, "Mount table full.\n");
                        break;
                case EINVAL:
                        break;
                case EINVAL:
-                       if (flags & M_UPDATE)
-                               fprintf(stderr, "Specified device does %s\n",
-                                       "not match mounted device");
+                       if (flags & MNT_UPDATE)
+                               (void)fprintf(stderr, "Specified device %s\n",
+                                       "does not match mounted device");
+                       else if (mnttype == MOUNT_UFS)
+                               (void)fprintf(stderr, "Bogus super block\n");
                        else
                        else
-                               fprintf(stderr, "Bogus super block\n");
-                       break;
-               case EOPNOTSUPP:
-                       fprintf(stderr, "Operation not supported\n");
+                               perror(NULL);
                        break;
                default:
                        break;
                default:
-                       perror((char *)NULL);
+                       perror(NULL);
                        break;
                }
                        break;
                }
-               return(1);
+               return (1);
        }
 
        }
 
-out:
-       if (verbose)
+out:   if (verbose)
                prmount(spec, name, flags);
                prmount(spec, name, flags);
-
-       if (opflags & ISBGRND)
-               exit();
-       else
-               return(0);
+       return (0);
 }
 
 }
 
-static
+void
 prmount(spec, name, flags)
        char *spec, *name;
 prmount(spec, name, flags)
        char *spec, *name;
-       long flags;
+       int flags;
 {
 {
+       int first;
 
 
-       if (opflags & ISBGRND)
+       (void)printf("%s on %s", spec, name);
+       if (!(flags & MNT_VISFLAGMASK)) {
+               (void)printf("\n");
                return;
                return;
-       printf("%s on %s", spec, name);
-       if (flags & M_RDONLY)
-               printf(" (read-only)");
-       if (flags & M_NOEXEC)
-               printf(" (noexec)");
-       if (flags & M_NOSUID)
-               printf(" (nosuid)");
-       if (flags & M_NODEV)
-               printf(" (nodev)");
-       if (flags & M_SYNCHRONOUS)
-               printf(" (synchronous)");
-       if (flags & M_UPDATE)
-               printf(" (update only)");
-       printf("\n");
+       }
+       first = 0;
+#define        PR(msg) (void)printf("%s%s", !first++ ? " (" : ", ", msg)
+       if (flags & MNT_RDONLY)
+               PR("read-only");
+       if (flags & MNT_NOEXEC)
+               PR("noexec");
+       if (flags & MNT_NOSUID)
+               PR("nosuid");
+       if (flags & MNT_NODEV)
+               PR("nodev");
+       if (flags & MNT_SYNCHRONOUS)
+               PR("synchronous");
+       if (flags & MNT_ASYNC)
+               PR("asynchronous");
+       if (flags & MNT_QUOTA)
+               PR("with quotas");
+       if (flags & MNT_LOCAL)
+               PR("local");
+       if (flags & MNT_UNION)
+               PR("union");
+       if (flags & MNT_EXPORTED)
+               PR("NFS exported");
+       (void)printf(")\n");
 }
 
 }
 
+int
 getmnttype(fstype)
        char *fstype;
 {
 
        mntname = fstype;
 getmnttype(fstype)
        char *fstype;
 {
 
        mntname = fstype;
-       if (!strcmp(fstype, "ufs"))
-               return (MOUNT_UFS);
-       if (!strcmp(fstype, "nfs"))
-               return (MOUNT_NFS);
-       if (!strcmp(fstype, "mfs"))
-               return (MOUNT_MFS);
-       return (0);
-}
-
-usage()
-{
-       fprintf(stderr, "usage: mount [-afurw]\nor mount [-furw] special | node\nor mount [-furw] special node\n");
-       exit(1);
+       return (strcmp(fstype, "ufs") == 0 ? MOUNT_UFS : 0);
 }
 
 }
 
+void
 getstdopts(options, flagp)
        char *options;
 getstdopts(options, flagp)
        char *options;
-       long *flagp;
+       int *flagp;
 {
 {
-       register char *opt;
        int negative;
        int negative;
-       char *optbuf[BUFSIZ], *strtok();
+       char *opt, optbuf[BUFSIZ];
 
 
-       strcpy(optbuf, options);
+       (void)strcpy(optbuf, options);
        for (opt = strtok(optbuf, ","); opt; opt = strtok(NULL, ",")) {
        for (opt = strtok(optbuf, ","); opt; opt = strtok(NULL, ",")) {
+               if (opt[0] == '-')
+                       continue;
                if (opt[0] == 'n' && opt[1] == 'o') {
                        negative++;
                        opt += 2;
                if (opt[0] == 'n' && opt[1] == 'o') {
                        negative++;
                        opt += 2;
-               } else {
+               } else
                        negative = 0;
                        negative = 0;
-               }
                if (!negative && !strcasecmp(opt, FSTAB_RO)) {
                if (!negative && !strcasecmp(opt, FSTAB_RO)) {
-                       *flagp |= M_RDONLY;
+                       *flagp |= MNT_RDONLY;
                        continue;
                }
                if (!negative && !strcasecmp(opt, FSTAB_RW)) {
                        continue;
                }
                if (!negative && !strcasecmp(opt, FSTAB_RW)) {
-                       *flagp &= ~M_RDONLY;
+                       *flagp &= ~MNT_RDONLY;
                        continue;
                }
                if (!strcasecmp(opt, "exec")) {
                        if (negative)
                        continue;
                }
                if (!strcasecmp(opt, "exec")) {
                        if (negative)
-                               *flagp |= M_NOEXEC;
+                               *flagp |= MNT_NOEXEC;
                        else
                        else
-                               *flagp &= ~M_NOEXEC;
+                               *flagp &= ~MNT_NOEXEC;
                        continue;
                }
                if (!strcasecmp(opt, "suid")) {
                        if (negative)
                        continue;
                }
                if (!strcasecmp(opt, "suid")) {
                        if (negative)
-                               *flagp |= M_NOSUID;
+                               *flagp |= MNT_NOSUID;
                        else
                        else
-                               *flagp &= ~M_NOSUID;
+                               *flagp &= ~MNT_NOSUID;
                        continue;
                }
                if (!strcasecmp(opt, "dev")) {
                        if (negative)
                        continue;
                }
                if (!strcasecmp(opt, "dev")) {
                        if (negative)
-                               *flagp |= M_NODEV;
+                               *flagp |= MNT_NODEV;
                        else
                        else
-                               *flagp &= ~M_NODEV;
+                               *flagp &= ~MNT_NODEV;
                        continue;
                }
                if (!strcasecmp(opt, "synchronous")) {
                        if (!negative)
                        continue;
                }
                if (!strcasecmp(opt, "synchronous")) {
                        if (!negative)
-                               *flagp |= M_SYNCHRONOUS;
+                               *flagp |= MNT_SYNCHRONOUS;
+                       else
+                               *flagp &= ~MNT_SYNCHRONOUS;
+                       continue;
+               }
+               if (!strcasecmp(opt, "asynchronous")) {
+                       if (!negative)
+                               *flagp |= MNT_ASYNC;
                        else
                        else
-                               *flagp &= ~M_SYNCHRONOUS;
+                               *flagp &= ~MNT_ASYNC;
                        continue;
                }
                        continue;
                }
+               if (!strcasecmp(opt, "union")) {
+                       if (!negative)
+                               *flagp |= MNT_UNION;
+                       else
+                               *flagp &= ~MNT_UNION;
+                       continue;
+               }
+               (void)fprintf(stderr, "mount: %s: unknown option\n", opt);
        }
 }
 
        }
 }
 
+/* ARGSUSED */
+void
 getufsopts(options, flagp)
        char *options;
 getufsopts(options, flagp)
        char *options;
-       long *flagp;
+       int *flagp;
 {
 
        return;
 }
 
 {
 
        return;
 }
 
+int
 getexecopts(options, argv)
 getexecopts(options, argv)
-       char *options;
-       char **argv;
+       char *options, **argv;
 {
 {
-       register int argc = 0;
-       register char *opt;
-       char *strtok();
+       int argc;
+       char *opt;
 
 
+       argc = 0;
        for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
                if (opt[0] != '-')
                        continue;
        for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
                if (opt[0] != '-')
                        continue;
@@ -475,9 +479,8 @@ struct statfs *
 getmntpt(name)
        char *name;
 {
 getmntpt(name)
        char *name;
 {
-       long mntsize;
-       register long i;
        struct statfs *mntbuf;
        struct statfs *mntbuf;
+       long i, mntsize;
 
        mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
        for (i = 0; i < mntsize; i++) {
 
        mntsize = getmntinfo(&mntbuf, MNT_NOWAIT);
        for (i = 0; i < mntsize; i++) {
@@ -485,21 +488,36 @@ getmntpt(name)
                    !strcmp(mntbuf[i].f_mntonname, name))
                        return (&mntbuf[i]);
        }
                    !strcmp(mntbuf[i].f_mntonname, name))
                        return (&mntbuf[i]);
        }
-       return ((struct statfs *)0);
+       return (NULL);
 }
 
 }
 
-static int skipvfs;
-
+int
 badvfstype(vfstype, vfslist)
 badvfstype(vfstype, vfslist)
-       char *vfstype;
+       int vfstype;
+       char **vfslist;
+{
+
+       if (vfslist == NULL)
+               return (0);
+       while (*vfslist != NULL) {
+               if (vfstype == getmnttype(*vfslist))
+                       return (skipvfs);
+               vfslist++;
+       }
+       return (!skipvfs);
+}
+
+int
+badvfsname(vfsname, vfslist)
+       char *vfsname;
        char **vfslist;
 {
 
        char **vfslist;
 {
 
-       if (vfslist == 0)
-               return(0);
-       while (*vfslist) {
-               if (strcmp(vfstype, *vfslist) == 0)
-                       return(skipvfs);
+       if (vfslist == NULL)
+               return (0);
+       while (*vfslist != NULL) {
+               if (strcmp(vfsname, *vfslist) == 0)
+                       return (skipvfs);
                vfslist++;
        }
        return (!skipvfs);
                vfslist++;
        }
        return (!skipvfs);
@@ -509,9 +527,8 @@ char **
 makevfslist(fslist)
        char *fslist;
 {
 makevfslist(fslist)
        char *fslist;
 {
-       register char **av, *nextcp;
-       register int i;
-       char *malloc();
+       int i;
+       char **av, *nextcp;
 
        if (fslist == NULL)
                return (NULL);
 
        if (fslist == NULL)
                return (NULL);
@@ -522,182 +539,29 @@ makevfslist(fslist)
        for (i = 0, nextcp = fslist; *nextcp; nextcp++)
                if (*nextcp == ',')
                        i++;
        for (i = 0, nextcp = fslist; *nextcp; nextcp++)
                if (*nextcp == ',')
                        i++;
-       av = (char **)malloc((i+2) * sizeof(char *));
+       av = malloc((size_t)(i + 2) * sizeof(char *));
        if (av == NULL)
                return (NULL);
        nextcp = fslist;
        i = 0;
        av[i++] = nextcp;
        if (av == NULL)
                return (NULL);
        nextcp = fslist;
        i = 0;
        av[i++] = nextcp;
-       while (nextcp = index(nextcp, ',')) {
+       while ((nextcp = index(nextcp, ',')) != NULL) {
                *nextcp++ = '\0';
                av[i++] = nextcp;
        }
                *nextcp++ = '\0';
                av[i++] = nextcp;
        }
-       av[i++] = 0;
+       av[i++] = NULL;
        return (av);
 }
 
        return (av);
 }
 
-#ifdef NFS
-/*
- * Handle the getoption arg.
- * Essentially update "opflags", "retrycnt" and "nfsargs"
- */
-getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
-       char *optarg;
-       struct nfs_args *nfsargsp;
-       int *opflagsp;
-       int *retrycntp;
-{
-       register char *cp, *nextcp;
-       int num;
-       char *nump;
-
-       cp = optarg;
-       while (cp != NULL && *cp != '\0') {
-               if ((nextcp = index(cp, ',')) != NULL)
-                       *nextcp++ = '\0';
-               if ((nump = index(cp, '=')) != NULL) {
-                       *nump++ = '\0';
-                       num = atoi(nump);
-               } else
-                       num = -1;
-               /*
-                * Just test for a string match and do it
-                */
-               if (!strcmp(cp, "bg")) {
-                       *opflagsp |= BGRND;
-               } else if (!strcmp(cp, "soft")) {
-                       nfsargsp->flags |= NFSMNT_SOFT;
-               } else if (!strcmp(cp, "intr")) {
-                       nfsargsp->flags |= NFSMNT_INT;
-               } else if (!strcmp(cp, "retry") && num > 0) {
-                       *retrycntp = num;
-               } else if (!strcmp(cp, "rsize") && num > 0) {
-                       nfsargsp->rsize = num;
-                       nfsargsp->flags |= NFSMNT_RSIZE;
-               } else if (!strcmp(cp, "wsize") && num > 0) {
-                       nfsargsp->wsize = num;
-                       nfsargsp->flags |= NFSMNT_WSIZE;
-               } else if (!strcmp(cp, "timeo") && num > 0) {
-                       nfsargsp->timeo = num;
-                       nfsargsp->flags |= NFSMNT_TIMEO;
-               } else if (!strcmp(cp, "retrans") && num > 0) {
-                       nfsargsp->retrans = num;
-                       nfsargsp->flags |= NFSMNT_RETRANS;
-               }
-               cp = nextcp;
-       }
-}
-
-char *
-getnfsargs(spec)
-       char *spec;
-{
-       extern int errno;
-       register CLIENT *clp;
-       struct hostent *hp;
-       static struct sockaddr_in saddr;
-       struct timeval pertry, try;
-       enum clnt_stat clnt_stat;
-       int so = RPC_ANYSOCK;
-       char *hostp, *delimp;
-       u_short tport;
-       static struct nfhret nfhret;
-       static char nam[MNAMELEN + 1];
-
-       strncpy(nam, spec, MNAMELEN);
-       nam[MNAMELEN] = '\0';
-       if ((delimp = index(spec, '@')) != NULL) {
-               hostp = delimp + 1;
-       } else if ((delimp = index(spec, ':')) != NULL) {
-               hostp = spec;
-               spec = delimp + 1;
-       } else {
-               fprintf(stderr,
-                   "No <host>:<dirpath> or <dirpath>@<host> spec\n");
-               return (0);
-       }
-       *delimp = '\0';
-       if ((hp = gethostbyname(hostp)) == NULL) {
-               fprintf(stderr, "Can't get net id for host\n");
-               return (0);
-       }
-       bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
-       nfhret.stat = EACCES;   /* Mark not yet successful */
-       while (retrycnt > 0) {
-               saddr.sin_family = AF_INET;
-               saddr.sin_port = htons(PMAPPORT);
-               if ((tport = pmap_getport(&saddr, RPCPROG_NFS,
-                   NFS_VER2, IPPROTO_UDP)) == 0) {
-                       if ((opflags & ISBGRND) == 0)
-                               clnt_pcreateerror("NFS Portmap");
-               } else {
-                       saddr.sin_port = 0;
-                       pertry.tv_sec = 10;
-                       pertry.tv_usec = 0;
-                       if ((clp = clntudp_create(&saddr, RPCPROG_MNT,
-                           RPCMNT_VER1, pertry, &so)) == NULL) {
-                               if ((opflags & ISBGRND) == 0)
-                                       clnt_pcreateerror("Cannot MNT PRC");
-                       } else {
-                               clp->cl_auth = authunix_create_default();
-                               try.tv_sec = 10;
-                               try.tv_usec = 0;
-                               clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
-                                   xdr_dir, spec, xdr_fh, &nfhret, try);
-                               if (clnt_stat != RPC_SUCCESS) {
-                                       if ((opflags & ISBGRND) == 0)
-                                               clnt_perror(clp, "Bad MNT RPC");
-                               } else {
-                                       auth_destroy(clp->cl_auth);
-                                       clnt_destroy(clp);
-                                       retrycnt = 0;
-                               }
-                       }
-               }
-               if (--retrycnt > 0) {
-                       if (opflags & BGRND) {
-                               opflags &= ~BGRND;
-                               if (fork())
-                                       return (0);
-                               else
-                                       opflags |= ISBGRND;
-                       } 
-                       sleep(10);
-               }
-       }
-       if (nfhret.stat) {
-               if (opflags & ISBGRND)
-                       exit(1);
-               fprintf(stderr, "Can't access %s: ", spec);
-               errno = nfhret.stat;
-               perror(NULL);
-               return (0);
-       }
-       saddr.sin_port = htons(tport);
-       nfsargs.addr = &saddr;
-       nfsargs.fh = &nfhret.nfh;
-       nfsargs.hostname = nam;
-       return ((caddr_t)&nfsargs);
-}
-
-/*
- * xdr routines for mount rpc's
- */
-xdr_dir(xdrsp, dirp)
-       XDR *xdrsp;
-       char *dirp;
+void
+usage()
 {
 {
-       return (xdr_string(xdrsp, &dirp, RPCMNT_PATHLEN));
-}
 
 
-xdr_fh(xdrsp, np)
-       XDR *xdrsp;
-       struct nfhret *np;
-{
-       if (!xdr_u_long(xdrsp, &(np->stat)))
-               return (0);
-       if (np->stat)
-               return (1);
-       return (xdr_opaque(xdrsp, (caddr_t)&(np->nfh), NFSX_FH));
+       (void)fprintf(stderr,
+               "usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
+               "[ -frwu ] [ -t ufs | external_type ]",
+               "[ -o options ] special node",
+               "[ -afrwu ] [ -t ufs | external_type ]",
+               "[ -frwu ] special | node");
+       exit(1);
 }
 }
-#endif /* NFS */