Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sbin/mount Accept NAME=label for special so that we can wire...



details:   https://anonhg.NetBSD.org/src/rev/84e06ff091a7
branches:  trunk
changeset: 778629:84e06ff091a7
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Apr 07 03:13:32 2012 +0000

description:
Accept NAME=label for special so that we can wire down our wedges.

diffstat:

 sbin/mount/Makefile |    3 +-
 sbin/mount/mount.c  |  159 ++++++++++++++++++++++++++++++++-------------------
 2 files changed, 102 insertions(+), 60 deletions(-)

diffs (truncated from 383 to 300 lines):

diff -r 8aa94c24fa3f -r 84e06ff091a7 sbin/mount/Makefile
--- a/sbin/mount/Makefile       Sat Apr 07 03:08:33 2012 +0000
+++ b/sbin/mount/Makefile       Sat Apr 07 03:13:32 2012 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.29 2004/08/19 23:02:27 christos Exp $
+#      $NetBSD: Makefile,v 1.30 2012/04/07 03:13:32 christos Exp $
 #      @(#)Makefile    8.6 (Berkeley) 5/8/95
 
 .include <bsd.own.mk>
@@ -6,5 +6,6 @@
 PROG=  mount
 MAN=   mount.8
 SRCS=  mount.c vfslist.c
+LDADD+= -lutil
 
 .include <bsd.prog.mk>
diff -r 8aa94c24fa3f -r 84e06ff091a7 sbin/mount/mount.c
--- a/sbin/mount/mount.c        Sat Apr 07 03:08:33 2012 +0000
+++ b/sbin/mount/mount.c        Sat Apr 07 03:13:32 2012 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.c,v 1.93 2011/08/29 14:35:00 joerg Exp $ */
+/*     $NetBSD: mount.c,v 1.94 2012/04/07 03:13:32 christos Exp $      */
 
 /*
  * Copyright (c) 1980, 1989, 1993, 1994
@@ -39,13 +39,15 @@
 #if 0
 static char sccsid[] = "@(#)mount.c    8.25 (Berkeley) 5/8/95";
 #else
-__RCSID("$NetBSD: mount.c,v 1.93 2011/08/29 14:35:00 joerg Exp $");
+__RCSID("$NetBSD: mount.c,v 1.94 2012/04/07 03:13:32 christos Exp $");
 #endif
 #endif /* not lint */
 
 #include <sys/param.h>
 #include <sys/mount.h>
 #include <sys/wait.h>
+#include <sys/disk.h>
+#include <sys/sysctl.h>
 
 #include <fs/puffs/puffs_msgif.h>
 
@@ -58,6 +60,8 @@
 #include <stdlib.h>
 #include <string.h>
 #include <unistd.h>
+#include <util.h>
+#include <vis.h>
 
 #define MOUNTNAMES
 #include <fcntl.h>
@@ -76,6 +80,8 @@
 static struct statvfs *
                getmntpt(const char *);
 static int     getmntargs(struct statvfs *, char *, size_t);
+static const char *
+               getspec(char *, size_t, const char *);
 static int     hasopt(const char *, const char *);
 static void    mangle(char *, int *, const char ** volatile *, int *);
 static int     mountfs(const char *, const char *, const char *,
@@ -93,7 +99,7 @@
        __MNT_FLAGS
 };
 
-static char ffs_fstype[] = "ffs";
+static const char ffs_fstype[] = "ffs";
 
 int
 main(int argc, char *argv[])
@@ -107,7 +113,7 @@
        int all, ch, forceall, i, init_flags, mntsize, rval;
        char *options;
        const char *mountopts, *fstypename;
-       char canonical_path_buf[MAXPATHLEN];
+       char canonical_path_buf[MAXPATHLEN], buf[MAXPATHLEN];
        char *canonical_path;
 
        /* started as "mount" */
@@ -138,8 +144,8 @@
                        break;
                case 't':
                        if (vfslist != NULL)
-                               errx(1,
-                                   "only one -t option may be specified.");
+                               errx(EXIT_FAILURE,
+                                   "Only one -t option may be specified.");
                        vfslist = makevfslist(optarg);
                        vfstype = optarg;
                        break;
@@ -176,13 +182,16 @@
                                if (hasopt(fs->fs_mntops, "noauto"))
                                        continue;
                                if (strcmp(fs->fs_spec, "from_mount") == 0) {
-                                       if ((mntbuf = getmntpt(fs->fs_file)) == NULL)
-                                               errx(1,
-                                                   "unknown file system %s.",
+                                       if ((mntbuf = getmntpt(fs->fs_file))
+                                           == NULL)
+                                               errx(EXIT_FAILURE,
+                                                   "Unknown file system %s",
                                                    fs->fs_file);
                                        mntfromname = mntbuf->f_mntfromname;
                                } else
                                        mntfromname = fs->fs_spec;
+                               mntfromname =
+                                   getspec(buf, sizeof(buf), mntfromname);
                                if (mountfs(fs->fs_vfstype, mntfromname,
                                    fs->fs_file, init_flags, options,
                                    fs->fs_mntops, !forceall, NULL, 0))
@@ -190,7 +199,7 @@
                        }
                else {
                        if ((mntsize = getmntinfo(&mntbuf, MNT_NOWAIT)) == 0)
-                               err(1, "getmntinfo");
+                               err(EXIT_FAILURE, "getmntinfo");
                        for (i = 0; i < mntsize; i++) {
                                if (checkvfsname(mntbuf[i].f_fstypename,
                                    vfslist))
@@ -219,12 +228,11 @@
                         * then try exactly what the user entered.
                         */
                        if ((canonical_path == NULL ||
-                            (mntbuf = getmntpt(canonical_path)) == NULL) &&
-                           (mntbuf = getmntpt(*argv)) == NULL
-                          )
-                       {
-                               errx(1,
-                                   "unknown special file or file system %s.",
+                           (mntbuf = getmntpt(canonical_path)) == NULL) &&
+                           (mntbuf = getmntpt(*argv)) == NULL) {
+out:
+                               errx(EXIT_FAILURE,
+                                   "Unknown special file or file system `%s'",
                                    *argv);
                        }
                        mntfromname = mntbuf->f_mntfromname;
@@ -247,26 +255,20 @@
                             (fs = getfsspec(canonical_path)) == NULL))
                        {
                                if ((fs = getfsfile(*argv)) == NULL &&
-                                   (fs = getfsspec(*argv)) == NULL)
-                               {
-                                       errx(1,
-                                           "%s: unknown special file or file system.",
-                                           *argv);
+                                   (fs = getfsspec(*argv)) == NULL) {
+                                       goto out;
                                }
                        }
                        if (BADTYPE(fs->fs_type))
-                               errx(1, "%s has unknown file system type.",
+                               errx(EXIT_FAILURE,
+                                   "Unknown file system type for `%s'",
                                    *argv);
                        if (strcmp(fs->fs_spec, "from_mount") == 0) {
                                if ((canonical_path == NULL ||
-                                    (mntbuf = getmntpt(canonical_path)) == NULL) &&
-                                   (mntbuf = getmntpt(*argv)) == NULL
-                                  )
-                               {
-                                       errx(1,
-                                           "unknown special file or file system %s.",
-                                           *argv);
-                               }
+                                   (mntbuf = getmntpt(canonical_path))
+                                    == NULL) &&
+                                   (mntbuf = getmntpt(*argv)) == NULL)
+                                       goto out;
                                mntfromname = mntbuf->f_mntfromname;
                        } else
                                mntfromname = fs->fs_spec;
@@ -274,6 +276,7 @@
                        fstypename  = fs->fs_vfstype;
                        mountopts   = fs->fs_mntops;
                }
+               mntfromname = getspec(buf, sizeof(buf), mntfromname);
                rval = mountfs(fstypename, mntfromname,
                    mntonname, init_flags, options, mountopts, 0, NULL, 0);
                break;
@@ -283,6 +286,7 @@
                 * a ':' or a '@' then assume that an NFS filesystem is being
                 * specified ala Sun.
                 */
+               mntfromname = getspec(buf, sizeof(buf), argv[0]);
                if (vfslist == NULL) {
                        if (strpbrk(argv[0], ":@") != NULL) {
                                fprintf(stderr, "WARNING: autoselecting nfs "
@@ -292,17 +296,16 @@
                                    "in a future release\n");
                                vfstype = "nfs";
                        } else {
-                               vfstype = getfslab(argv[0]);
+                               vfstype = getfslab(mntfromname);
                                if (vfstype == NULL)
                                        vfstype = ffs_fstype;
                        }
                }
-               rval = mountfs(vfstype,
-                   argv[0], argv[1], init_flags, options, NULL, 0, NULL, 0);
+               rval = mountfs(vfstype, mntfromname, argv[1], init_flags,
+                   options, NULL, 0, NULL, 0);
                break;
        default:
                usage();
-               /* NOTREACHED */
        }
 
 #if 0  /* disabled because it interferes the service. */
@@ -316,13 +319,12 @@
 
                if (fscanf(mountdfp, "%d", &pid) == 1 &&
                    pid > 0 && kill(pid, SIGHUP) == -1 && errno != ESRCH)
-                       err(1, "signal mountd");
+                       err(EXIT_FAILURE, "signal mountd");
                (void)fclose(mountdfp);
        }
 #endif
 
-       exit(rval);
-       /* NOTREACHED */
+       return 0;
 }
 
 int
@@ -336,7 +338,7 @@
                option += 2;
        } else
                negative = 0;
-       optbuf = strdup(mntopts);
+       optbuf = estrdup(mntopts);
        found = 0;
        for (opt = optbuf; (opt = strtok(opt, ",")) != NULL; opt = NULL) {
                if (opt[0] == 'n' && opt[1] == 'o') {
@@ -351,8 +353,8 @@
 
 static int
 mountfs(const char *vfstype, const char *spec, const char *name, 
-       int flags, const char *options, const char *mntopts,
-       int skipmounted, char *buf, size_t buflen)
+    int flags, const char *options, const char *mntopts,
+    int skipmounted, char *buf, size_t buflen)
 {
        /* List of directories containing mount_xxx subcommands. */
        static const char *edirs[] = {
@@ -373,7 +375,7 @@
        volatile int getargs;
 
        if (realpath(name, mntpath) == NULL) {
-               warn("realpath %s", name);
+               warn("realpath `%s'", name);
                return (1);
        }
 
@@ -442,9 +444,7 @@
        }
 
        maxargc = 64;
-       argv = malloc(sizeof(char *) * maxargc);
-       if (argv == NULL)
-               err(1, "malloc");
+       argv = ecalloc(maxargc, sizeof(*argv));
 
        if (getargs &&
            strncmp(vfstype, PUFFS_TYPEPREFIX, sizeof(PUFFS_TYPEPREFIX)-1) == 0)
@@ -538,7 +538,7 @@
                                (void)fprintf(stdout, "%s", tbuf);
                }
 
-               if (waitpid(pid, &status, 0) < 0) {
+               if (waitpid(pid, &status, 0) == -1) {
                        warn("waitpid");
                        return (1);
                }
@@ -553,7 +553,7 @@
 
                if (buf == NULL) {
                        if (verbose) {
-                               if (statvfs(name, &sf) < 0) {
+                               if (statvfs(name, &sf) == -1) {
                                        warn("statvfs %s", name);
                                        return (1);
                                }
@@ -656,12 +656,11 @@
 
        s = *sp;
        if (s) {
-               if (asprintf(&n, "%s,%s", s, o) < 0)
-                       err(1, "asprintf");
+               easprintf(&n, "%s,%s", s, o);
                free(s);
                s = n;
        } else
-               s = strdup(o);
+               s = estrdup(o);
        *sp = s;
 }
 
@@ -679,9 +678,7 @@
        for (s = options; (p = strsep(&s, ",")) != NULL;) {
                /* Always leave space for one more argument and the NULL. */



Home | Main Index | Thread Index | Old Index