BSD 4_3_Reno release
[unix-history] / usr / src / sbin / mount / mount.c
index 8048467..f3456c7 100644 (file)
@@ -2,17 +2,19 @@
  * Copyright (c) 1980, 1989 The Regents of the University of California.
  * All rights reserved.
  *
  * Copyright (c) 1980, 1989 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.
+ * Redistribution and use in source and binary forms are permitted provided
+ * that: (1) source distributions retain this entire copyright notice and
+ * comment, and (2) distributions including binaries display the following
+ * acknowledgement:  ``This product includes software developed by the
+ * University of California, Berkeley and its contributors'' in the
+ * documentation or other materials provided with the distribution and in
+ * all advertising materials mentioning features or use of this software.
+ * 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
+ * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -22,7 +24,7 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mount.c    5.33 (Berkeley) %G%";
+static char sccsid[] = "@(#)mount.c    5.39 (Berkeley) 6/22/90";
 #endif /* not lint */
 
 #include "pathnames.h"
 #endif /* not lint */
 
 #include "pathnames.h"
@@ -34,7 +36,7 @@ static char sccsid[] = "@(#)mount.c   5.33 (Berkeley) %G%";
 #include <errno.h>
 #include <stdio.h>
 #include <signal.h>
 #include <errno.h>
 #include <stdio.h>
 #include <signal.h>
-#include <strings.h>
+#include <string.h>
 #include <sys/mount.h>
 #ifdef NFS
 #include <sys/socket.h>
 #include <sys/mount.h>
 #ifdef NFS
 #include <sys/socket.h>
@@ -63,8 +65,10 @@ char **vfslist, **makevfslist();
 #ifdef NFS
 int xdr_dir(), xdr_fh();
 char *getnfsargs();
 #ifdef NFS
 int xdr_dir(), xdr_fh();
 char *getnfsargs();
-struct nfs_args nfsargs = {
-       (struct sockaddr_in *)0,
+struct nfs_args nfsdefargs = {
+       (struct sockaddr *)0,
+       SOCK_DGRAM,
+       0,
        (nfsv2fh_t *)0,
        0,
        NFS_WSIZE,
        (nfsv2fh_t *)0,
        0,
        NFS_WSIZE,
@@ -93,7 +97,6 @@ main(argc, argv, arge)
        extern char *optarg;
        extern int optind;
        register struct fstab *fs;
        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();
        int all, ch, rval, flags, ret, pid, i;
        long mntsize;
        struct statfs *mntbuf, *getmntpt();
@@ -191,7 +194,7 @@ main(argc, argv, arge)
                        strcpy(mntbuf->f_mntfromname, fs->fs_spec);
                }
                ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
                        strcpy(mntbuf->f_mntfromname, fs->fs_spec);
                }
                ret = mountfs(mntbuf->f_mntfromname, mntbuf->f_mntonname,
-                   updateflg, type, options, NULL);
+                   updateflg, type, options, (char *)NULL);
        } else if (argc == 1) {
                if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
                        fprintf(stderr,
        } else if (argc == 1) {
                if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
                        fprintf(stderr,
@@ -211,7 +214,16 @@ main(argc, argv, arge)
                usage();
                ret = 1;
        } else {
                usage();
                ret = 1;
        } else {
-               ret = mountfs(argv[0], argv[1], updateflg, type, options, NULL);
+               /*
+                * 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 == (char **)0 &&
+                   (index(argv[0], ':') || index(argv[0], '@')))
+                       mnttype = MOUNT_NFS;
+               ret = mountfs(argv[0], argv[1], updateflg, type, options,
+                   (char *)NULL);
        }
        if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
                pid = 0;
        }
        if ((pidfile = fopen(_PATH_MOUNTDPID, "r")) != NULL) {
                pid = 0;
@@ -228,12 +240,15 @@ mountfs(spec, name, flags, type, options, mntopts)
        int flags;
 {
        extern int errno;
        int flags;
 {
        extern int errno;
-       register int cnt;
-       int argc, status, i;
+       union wait status;
+       pid_t pid;
+       int argc, i;
        struct ufs_args args;
        struct ufs_args args;
+       struct nfs_args nfsargs;
        char *argp, *argv[50];
        char execname[MAXPATHLEN + 1], flagval[12];
 
        char *argp, *argv[50];
        char execname[MAXPATHLEN + 1], flagval[12];
 
+       nfsargs = nfsdefargs;
        if (mntopts)
                getstdopts(mntopts, &flags);
        if (options)
        if (mntopts)
                getstdopts(mntopts, &flags);
        if (options)
@@ -262,7 +277,7 @@ mountfs(spec, name, flags, type, options, mntopts)
                        getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
                if (options)
                        getnfsopts(options, &nfsargs, &opflags, &retrycnt);
                        getnfsopts(mntopts, &nfsargs, &opflags, &retrycnt);
                if (options)
                        getnfsopts(options, &nfsargs, &opflags, &retrycnt);
-               if (argp = getnfsargs(spec, name, type))
+               if (argp = getnfsargs(spec, &nfsargs))
                        break;
                return (1);
 #endif /* NFS */
                        break;
                return (1);
 #endif /* NFS */
@@ -285,19 +300,19 @@ mountfs(spec, name, flags, type, options, mntopts)
                argv[argc++] = NULL;
                sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
                if (verbose) {
                argv[argc++] = NULL;
                sprintf(execname, "%s/mount_%s", _PATH_EXECDIR, mntname);
                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)
                        break;
                }
                if (fake)
                        break;
-               if (i = vfork()) {
-                       if (i == -1) {
+               if (pid = vfork()) {
+                       if (pid == -1) {
                                perror("mount: vfork starting file system");
                                return (1);
                        }
                                perror("mount: vfork starting file system");
                                return (1);
                        }
-                       if (waitpid(i, &status, 0) != -1 &&
+                       if (waitpid(pid, &status, 0) != -1 &&
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
@@ -307,7 +322,7 @@ mountfs(spec, name, flags, type, options, mntopts)
                execve(execname, argv, envp);
                fprintf(stderr, "mount: cannot exec %s for %s: ",
                        execname, name);
                execve(execname, argv, envp);
                fprintf(stderr, "mount: cannot exec %s for %s: ",
                        execname, name);
-               perror("");
+               perror((char *)NULL);
                exit (1);
                /* NOTREACHED */
 
                exit (1);
                /* NOTREACHED */
 
@@ -342,40 +357,46 @@ out:
                prmount(spec, name, flags);
 
        if (opflags & ISBGRND)
                prmount(spec, name, flags);
 
        if (opflags & ISBGRND)
-               exit();
-       else
-               return(0);
+               exit(1);
+       return(0);
 }
 
 static
 prmount(spec, name, flags)
        char *spec, *name;
 }
 
 static
 prmount(spec, name, flags)
        char *spec, *name;
-       long flags;
+       register short flags;
 {
 {
+       register int first;
 
        if (opflags & ISBGRND)
                return;
 
        if (opflags & ISBGRND)
                return;
-       printf("%s on %s", spec, name);
+       (void)printf("%s on %s", spec, name);
+       if (!(flags & MNT_VISFLAGMASK)) {
+               (void)printf("\n");
+               return;
+       }
+       first = 0;
+#define        PR(msg) (void)printf("%s%s", !first++ ? " (" : ", ", msg)
        if (flags & MNT_RDONLY)
        if (flags & MNT_RDONLY)
-               printf(" (read-only)");
+               PR("read-only");
        if (flags & MNT_NOEXEC)
        if (flags & MNT_NOEXEC)
-               printf(" (noexec)");
+               PR("noexec");
        if (flags & MNT_NOSUID)
        if (flags & MNT_NOSUID)
-               printf(" (nosuid)");
+               PR("nosuid");
        if (flags & MNT_NODEV)
        if (flags & MNT_NODEV)
-               printf(" (nodev)");
+               PR("nodev");
        if (flags & MNT_SYNCHRONOUS)
        if (flags & MNT_SYNCHRONOUS)
-               printf(" (synchronous)");
+               PR("synchronous");
        if (flags & MNT_QUOTA)
        if (flags & MNT_QUOTA)
-               printf(" (with quotas)");
+               PR("with quotas");
        if (flags & MNT_LOCAL)
        if (flags & MNT_LOCAL)
-               printf(" (local)");
+               PR("local");
        if (flags & MNT_EXPORTED)
                if (flags & MNT_EXRDONLY)
        if (flags & MNT_EXPORTED)
                if (flags & MNT_EXRDONLY)
-                       printf(" (NFS exported read-only)");
+                       PR("NFS exported read-only");
                else
                else
-                       printf(" (NFS exported)");
-       printf("\n");
+                       PR("NFS exported");
+       (void)printf(")\n");
 }
 
 getmnttype(fstype)
 }
 
 getmnttype(fstype)
@@ -405,14 +426,14 @@ usage()
 
 getstdopts(options, flagp)
        char *options;
 
 getstdopts(options, flagp)
        char *options;
-       long *flagp;
+       int *flagp;
 {
        register char *opt;
        int negative;
 {
        register char *opt;
        int negative;
-       char *optbuf[BUFSIZ], *strtok();
+       char optbuf[BUFSIZ];
 
 
-       strcpy(optbuf, options);
-       for (opt = strtok(optbuf, ","); opt; opt = strtok(NULL, ",")) {
+       (void)strcpy(optbuf, options);
+       for (opt = strtok(optbuf, ","); opt; opt = strtok((char *)NULL, ",")) {
                if (opt[0] == 'n' && opt[1] == 'o') {
                        negative++;
                        opt += 2;
                if (opt[0] == 'n' && opt[1] == 'o') {
                        negative++;
                        opt += 2;
@@ -458,11 +479,11 @@ getstdopts(options, flagp)
        }
 }
 
        }
 }
 
+/* ARGSUSED */
 getufsopts(options, flagp)
        char *options;
 getufsopts(options, flagp)
        char *options;
-       long *flagp;
+       int *flagp;
 {
 {
-
        return;
 }
 
        return;
 }
 
@@ -472,9 +493,8 @@ getexecopts(options, argv)
 {
        register int argc = 0;
        register char *opt;
 {
        register int argc = 0;
        register char *opt;
-       char *strtok();
 
 
-       for (opt = strtok(options, ","); opt; opt = strtok(NULL, ",")) {
+       for (opt = strtok(options, ","); opt; opt = strtok((char *)NULL, ",")) {
                if (opt[0] != '-')
                        continue;
                argv[argc++] = opt;
                if (opt[0] != '-')
                        continue;
                argv[argc++] = opt;
@@ -506,7 +526,7 @@ getmntpt(name)
 static int skipvfs;
 
 badvfstype(vfstype, vfslist)
 static int skipvfs;
 
 badvfstype(vfstype, vfslist)
-       long vfstype;
+       short vfstype;
        char **vfslist;
 {
 
        char **vfslist;
 {
 
@@ -541,7 +561,6 @@ makevfslist(fslist)
 {
        register char **av, *nextcp;
        register int i;
 {
        register char **av, *nextcp;
        register int i;
-       char *malloc();
 
        if (fslist == NULL)
                return (NULL);
 
        if (fslist == NULL)
                return (NULL);
@@ -552,7 +571,7 @@ 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 = (char **)malloc((size_t)(i+2) * sizeof(char *));
        if (av == NULL)
                return (NULL);
        nextcp = fslist;
        if (av == NULL)
                return (NULL);
        nextcp = fslist;
@@ -596,9 +615,25 @@ getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
                if (!strcmp(cp, "bg")) {
                        *opflagsp |= BGRND;
                } else if (!strcmp(cp, "soft")) {
                if (!strcmp(cp, "bg")) {
                        *opflagsp |= BGRND;
                } else if (!strcmp(cp, "soft")) {
+                       if (nfsargsp->flags & NFSMNT_SPONGY) {
+                               fprintf(stderr,
+                                       "Options soft, spongy mutually exclusive\n");
+                               exit(1);
+                       }
                        nfsargsp->flags |= NFSMNT_SOFT;
                        nfsargsp->flags |= NFSMNT_SOFT;
+               } else if (!strcmp(cp, "spongy")) {
+                       if (nfsargsp->flags & NFSMNT_SOFT) {
+                               fprintf(stderr,
+                                       "Options soft, spongy mutually exclusive\n");
+                               exit(1);
+                       }
+                       nfsargsp->flags |= NFSMNT_SPONGY;
                } else if (!strcmp(cp, "intr")) {
                        nfsargsp->flags |= NFSMNT_INT;
                } else if (!strcmp(cp, "intr")) {
                        nfsargsp->flags |= NFSMNT_INT;
+               } else if (!strcmp(cp, "tcp")) {
+                       nfsargsp->sotype = SOCK_STREAM;
+               } else if (!strcmp(cp, "noconn")) {
+                       nfsargsp->flags |= NFSMNT_NOCONN;
                } else if (!strcmp(cp, "retry") && num > 0) {
                        *retrycntp = num;
                } else if (!strcmp(cp, "rsize") && num > 0) {
                } else if (!strcmp(cp, "retry") && num > 0) {
                        *retrycntp = num;
                } else if (!strcmp(cp, "rsize") && num > 0) {
@@ -616,11 +651,18 @@ getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
                }
                cp = nextcp;
        }
                }
                cp = nextcp;
        }
+       if (nfsargsp->sotype == SOCK_DGRAM) {
+               if (nfsargsp->rsize > NFS_MAXDGRAMDATA)
+                       nfsargsp->rsize = NFS_MAXDGRAMDATA;
+               if (nfsargsp->wsize > NFS_MAXDGRAMDATA)
+                       nfsargsp->wsize = NFS_MAXDGRAMDATA;
+       }
 }
 
 char *
 }
 
 char *
-getnfsargs(spec)
+getnfsargs(spec, nfsargsp)
        char *spec;
        char *spec;
+       struct nfs_args *nfsargsp;
 {
        extern int errno;
        register CLIENT *clp;
 {
        extern int errno;
        register CLIENT *clp;
@@ -700,14 +742,14 @@ getnfsargs(spec)
                        exit(1);
                fprintf(stderr, "Can't access %s: ", spec);
                errno = nfhret.stat;
                        exit(1);
                fprintf(stderr, "Can't access %s: ", spec);
                errno = nfhret.stat;
-               perror(NULL);
+               perror((char *)NULL);
                return (0);
        }
        saddr.sin_port = htons(tport);
                return (0);
        }
        saddr.sin_port = htons(tport);
-       nfsargs.addr = &saddr;
-       nfsargs.fh = &nfhret.nfh;
-       nfsargs.hostname = nam;
-       return ((caddr_t)&nfsargs);
+       nfsargsp->addr = (struct sockaddr *) &saddr;
+       nfsargsp->fh = &nfhret.nfh;
+       nfsargsp->hostname = nam;
+       return ((caddr_t)nfsargsp);
 }
 
 /*
 }
 
 /*