BSD 4_3_Net_2 release
[unix-history] / usr / src / sbin / mount / mount.c
index f3456c7..9c561b2 100644 (file)
@@ -2,19 +2,33 @@
  * 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: (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.
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the University of
+ *     California, Berkeley and its contributors.
+ * 4. Neither the name of the University nor the names of its contributors
+ *    may be used to endorse or promote products derived from this software
+ *    without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
  */
 
 #ifndef lint
  */
 
 #ifndef lint
@@ -24,19 +38,15 @@ char copyright[] =
 #endif /* not lint */
 
 #ifndef lint
 #endif /* not lint */
 
 #ifndef lint
-static char sccsid[] = "@(#)mount.c    5.39 (Berkeley) 6/22/90";
+static char sccsid[] = "@(#)mount.c    5.44 (Berkeley) 2/26/91";
 #endif /* not lint */
 
 #endif /* not lint */
 
-#include "pathnames.h"
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/wait.h>
 #include <sys/param.h>
 #include <sys/file.h>
 #include <sys/time.h>
 #include <sys/wait.h>
-#include <fstab.h>
-#include <errno.h>
-#include <stdio.h>
-#include <signal.h>
-#include <string.h>
+#include <sys/errno.h>
+#include <sys/signal.h>
 #include <sys/mount.h>
 #ifdef NFS
 #include <sys/socket.h>
 #include <sys/mount.h>
 #ifdef NFS
 #include <sys/socket.h>
@@ -49,6 +59,11 @@ static char sccsid[] = "@(#)mount.c  5.39 (Berkeley) 6/22/90";
 #include <nfs/nfsv2.h>
 #include <nfs/nfs.h>
 #endif
 #include <nfs/nfsv2.h>
 #include <nfs/nfs.h>
 #endif
+#include <fstab.h>
+#include <string.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include "pathnames.h"
 
 #define DEFAULT_ROOTUID        -2
 
 
 #define DEFAULT_ROOTUID        -2
 
@@ -61,6 +76,7 @@ static char sccsid[] = "@(#)mount.c   5.39 (Berkeley) 6/22/90";
 int fake, verbose, updateflg, mnttype;
 char *mntname, **envp;
 char **vfslist, **makevfslist();
 int fake, verbose, updateflg, mnttype;
 char *mntname, **envp;
 char **vfslist, **makevfslist();
+static void prmount();
 
 #ifdef NFS
 int xdr_dir(), xdr_fh();
 
 #ifdef NFS
 int xdr_dir(), xdr_fh();
@@ -168,7 +184,7 @@ main(argc, argv, arge)
                if (verbose || fake || type)
                        usage();
                if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
                if (verbose || fake || type)
                        usage();
                if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0) {
-                       fprintf(stderr,
+                       (void) fprintf(stderr,
                                "mount: cannot get mount information\n");
                        exit(1);
                }
                                "mount: cannot get mount information\n");
                        exit(1);
                }
@@ -183,7 +199,7 @@ main(argc, argv, arge)
 
        if (argc == 1 && updateflg) {
                if ((mntbuf = getmntpt(*argv)) == NULL) {
 
        if (argc == 1 && updateflg) {
                if ((mntbuf = getmntpt(*argv)) == NULL) {
-                       fprintf(stderr,
+                       (void) fprintf(stderr,
                            "mount: unknown special file or file system %s.\n",
                            *argv);
                        exit(1);
                            "mount: unknown special file or file system %s.\n",
                            *argv);
                        exit(1);
@@ -197,13 +213,13 @@ main(argc, argv, arge)
                    updateflg, type, options, (char *)NULL);
        } else if (argc == 1) {
                if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
                    updateflg, type, options, (char *)NULL);
        } else if (argc == 1) {
                if (!(fs = getfsfile(*argv)) && !(fs = getfsspec(*argv))) {
-                       fprintf(stderr,
+                       (void) fprintf(stderr,
                            "mount: unknown special file or file system %s.\n",
                            *argv);
                        exit(1);
                }
                if (BADTYPE(fs->fs_type)) {
                            "mount: unknown special file or file system %s.\n",
                            *argv);
                        exit(1);
                }
                if (BADTYPE(fs->fs_type)) {
-                       fprintf(stderr,
+                       (void) fprintf(stderr,
                            "mount: %s has unknown file system type.\n", *argv);
                        exit(1);
                }
                            "mount: %s has unknown file system type.\n", *argv);
                        exit(1);
                }
@@ -239,7 +255,6 @@ mountfs(spec, name, flags, type, options, mntopts)
        char *spec, *name, *type, *options, *mntopts;
        int flags;
 {
        char *spec, *name, *type, *options, *mntopts;
        int flags;
 {
-       extern int errno;
        union wait status;
        pid_t pid;
        int argc, i;
        union wait status;
        pid_t pid;
        int argc, i;
@@ -312,7 +327,7 @@ mountfs(spec, name, flags, type, options, mntopts)
                                perror("mount: vfork starting file system");
                                return (1);
                        }
                                perror("mount: vfork starting file system");
                                return (1);
                        }
-                       if (waitpid(pid, &status, 0) != -1 &&
+                       if (waitpid(pid, (int *)&status, 0) != -1 &&
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
                            WIFEXITED(status) &&
                            WEXITSTATUS(status) != 0)
                                return (WEXITSTATUS(status));
@@ -320,7 +335,7 @@ mountfs(spec, name, flags, type, options, mntopts)
                        goto out;
                }
                execve(execname, argv, envp);
                        goto out;
                }
                execve(execname, argv, envp);
-               fprintf(stderr, "mount: cannot exec %s for %s: ",
+               (void) fprintf(stderr, "mount: cannot exec %s for %s: ",
                        execname, name);
                perror((char *)NULL);
                exit (1);
                        execname, name);
                perror((char *)NULL);
                exit (1);
@@ -330,20 +345,19 @@ mountfs(spec, name, flags, type, options, mntopts)
        if (!fake && mount(mnttype, name, flags, argp)) {
                if (opflags & ISBGRND)
                        exit(1);
        if (!fake && mount(mnttype, name, flags, argp)) {
                if (opflags & ISBGRND)
                        exit(1);
-               fprintf(stderr, "%s on %s: ", spec, name);
+               (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:
                        if (flags & MNT_UPDATE)
                        break;
                case EINVAL:
                        if (flags & MNT_UPDATE)
-                               fprintf(stderr, "Specified device does %s\n",
-                                       "not match mounted device");
+                               (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((char *)NULL);
                        break;
                default:
                        perror((char *)NULL);
                        break;
                default:
                        perror((char *)NULL);
@@ -361,7 +375,7 @@ out:
        return(0);
 }
 
        return(0);
 }
 
-static
+static void
 prmount(spec, name, flags)
        char *spec, *name;
        register short flags;
 prmount(spec, name, flags)
        char *spec, *name;
        register short flags;
@@ -416,7 +430,8 @@ getmnttype(fstype)
 usage()
 {
 
 usage()
 {
 
-       fprintf(stderr, "usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
+       (void) fprintf(stderr,
+               "usage:\n  mount %s %s\n  mount %s\n  mount %s\n",
                "[ -frwu ] [ -t nfs | ufs | external_type ]",
                "[ -o options ] special node",
                "[ -afrwu ] [ -t nfs | ufs | external_type ]",
                "[ -frwu ] [ -t nfs | ufs | external_type ]",
                "[ -o options ] special node",
                "[ -afrwu ] [ -t nfs | ufs | external_type ]",
@@ -586,13 +601,22 @@ makevfslist(fslist)
 }
 
 #ifdef NFS
 }
 
 #ifdef NFS
+exclusive(a, b)
+       char *a, *b;
+{
+
+       (void) fprintf(stderr, "mount: Options %s, %s mutually exclusive\n",
+           a, b);
+       exit(1);
+}
+
 /*
  * Handle the getoption arg.
  * Essentially update "opflags", "retrycnt" and "nfsargs"
  */
 getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
        char *optarg;
 /*
  * Handle the getoption arg.
  * Essentially update "opflags", "retrycnt" and "nfsargs"
  */
 getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
        char *optarg;
-       struct nfs_args *nfsargsp;
+       register struct nfs_args *nfsargsp;
        int *opflagsp;
        int *retrycntp;
 {
        int *opflagsp;
        int *retrycntp;
 {
@@ -600,8 +624,7 @@ getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
        int num;
        char *nump;
 
        int num;
        char *nump;
 
-       cp = optarg;
-       while (cp != NULL && *cp != '\0') {
+       for (cp = optarg; cp != NULL && *cp != '\0'; cp = nextcp) {
                if ((nextcp = index(cp, ',')) != NULL)
                        *nextcp++ = '\0';
                if ((nump = index(cp, '=')) != NULL) {
                if ((nextcp = index(cp, ',')) != NULL)
                        *nextcp++ = '\0';
                if ((nump = index(cp, '=')) != NULL) {
@@ -615,19 +638,15 @@ 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);
-                       }
+                       if (nfsargsp->flags & NFSMNT_SPONGY)
+                               exclusive("soft, spongy");
                        nfsargsp->flags |= NFSMNT_SOFT;
                } else if (!strcmp(cp, "spongy")) {
                        nfsargsp->flags |= NFSMNT_SOFT;
                } else if (!strcmp(cp, "spongy")) {
-                       if (nfsargsp->flags & NFSMNT_SOFT) {
-                               fprintf(stderr,
-                                       "Options soft, spongy mutually exclusive\n");
-                               exit(1);
-                       }
+                       if (nfsargsp->flags & NFSMNT_SOFT)
+                               exclusive("soft, spongy");
                        nfsargsp->flags |= NFSMNT_SPONGY;
                        nfsargsp->flags |= NFSMNT_SPONGY;
+               } else if (!strcmp(cp, "compress")) {
+                       nfsargsp->flags |= NFSMNT_COMPRESS;
                } else if (!strcmp(cp, "intr")) {
                        nfsargsp->flags |= NFSMNT_INT;
                } else if (!strcmp(cp, "tcp")) {
                } else if (!strcmp(cp, "intr")) {
                        nfsargsp->flags |= NFSMNT_INT;
                } else if (!strcmp(cp, "tcp")) {
@@ -649,7 +668,6 @@ getnfsopts(optarg, nfsargsp, opflagsp, retrycntp)
                        nfsargsp->retrans = num;
                        nfsargsp->flags |= NFSMNT_RETRANS;
                }
                        nfsargsp->retrans = num;
                        nfsargsp->flags |= NFSMNT_RETRANS;
                }
-               cp = nextcp;
        }
        if (nfsargsp->sotype == SOCK_DGRAM) {
                if (nfsargsp->rsize > NFS_MAXDGRAMDATA)
        }
        if (nfsargsp->sotype == SOCK_DGRAM) {
                if (nfsargsp->rsize > NFS_MAXDGRAMDATA)
@@ -664,37 +682,40 @@ getnfsargs(spec, nfsargsp)
        char *spec;
        struct nfs_args *nfsargsp;
 {
        char *spec;
        struct nfs_args *nfsargsp;
 {
-       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;
        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;
+       char *fsp, *hostp, *delimp;
        u_short tport;
        static struct nfhret nfhret;
        static char nam[MNAMELEN + 1];
        u_short tport;
        static struct nfhret nfhret;
        static char nam[MNAMELEN + 1];
+       char buf[MAXPATHLEN + 1];
 
 
+       strncpy(buf, spec, MAXPATHLEN);
+       buf[MAXPATHLEN] = '\0';
        strncpy(nam, spec, MNAMELEN);
        nam[MNAMELEN] = '\0';
        strncpy(nam, spec, MNAMELEN);
        nam[MNAMELEN] = '\0';
-       if ((delimp = index(spec, '@')) != NULL) {
+       if ((delimp = index(buf, '@')) != NULL) {
                hostp = delimp + 1;
                hostp = delimp + 1;
-       } else if ((delimp = index(spec, ':')) != NULL) {
-               hostp = spec;
-               spec = delimp + 1;
+               fsp = buf;
+       } else if ((delimp = index(buf, ':')) != NULL) {
+               hostp = buf;
+               fsp = delimp + 1;
        } else {
        } else {
-               fprintf(stderr,
-                   "No <host>:<dirpath> or <dirpath>@<host> spec\n");
+               (void) fprintf(stderr,
+                   "mount: No <host>:<dirpath> or <dirpath>@<host> spec\n");
                return (0);
        }
        *delimp = '\0';
        if ((hp = gethostbyname(hostp)) == NULL) {
                return (0);
        }
        *delimp = '\0';
        if ((hp = gethostbyname(hostp)) == NULL) {
-               fprintf(stderr, "Can't get net id for host\n");
+               (void) fprintf(stderr, "mount: Can't get net id for host\n");
                return (0);
        }
        bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
                return (0);
        }
        bcopy(hp->h_addr, (caddr_t)&saddr.sin_addr, hp->h_length);
-       nfhret.stat = EACCES;   /* Mark not yet successful */
+       nfhret.stat = ETIMEDOUT;        /* Mark not yet successful */
        while (retrycnt > 0) {
                saddr.sin_family = AF_INET;
                saddr.sin_port = htons(PMAPPORT);
        while (retrycnt > 0) {
                saddr.sin_family = AF_INET;
                saddr.sin_port = htons(PMAPPORT);
@@ -715,7 +736,7 @@ getnfsargs(spec, nfsargsp)
                                try.tv_sec = 10;
                                try.tv_usec = 0;
                                clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
                                try.tv_sec = 10;
                                try.tv_usec = 0;
                                clnt_stat = clnt_call(clp, RPCMNT_MOUNT,
-                                   xdr_dir, spec, xdr_fh, &nfhret, try);
+                                   xdr_dir, fsp, xdr_fh, &nfhret, try);
                                if (clnt_stat != RPC_SUCCESS) {
                                        if ((opflags & ISBGRND) == 0)
                                                clnt_perror(clp, "Bad MNT RPC");
                                if (clnt_stat != RPC_SUCCESS) {
                                        if ((opflags & ISBGRND) == 0)
                                                clnt_perror(clp, "Bad MNT RPC");
@@ -740,7 +761,7 @@ getnfsargs(spec, nfsargsp)
        if (nfhret.stat) {
                if (opflags & ISBGRND)
                        exit(1);
        if (nfhret.stat) {
                if (opflags & ISBGRND)
                        exit(1);
-               fprintf(stderr, "Can't access %s: ", spec);
+               (void) fprintf(stderr, "Mount RPC error on %s: ", spec);
                errno = nfhret.stat;
                perror((char *)NULL);
                return (0);
                errno = nfhret.stat;
                perror((char *)NULL);
                return (0);