Source-Changes-HG archive

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

[src/trunk]: src/sbin MNT_GETARGS support



details:   https://anonhg.NetBSD.org/src/rev/f5861ddeaae4
branches:  trunk
changeset: 536768:f5861ddeaae4
user:      christos <christos%NetBSD.org@localhost>
date:      Sat Sep 21 18:43:31 2002 +0000

description:
MNT_GETARGS support

diffstat:

 sbin/mount/Makefile                  |    5 +-
 sbin/mount/mntopts.h                 |    3 +-
 sbin/mount/mount.8                   |    9 ++-
 sbin/mount/mount.c                   |  102 +++++++++++++++++++++++++++++-----
 sbin/mount_ados/mount_ados.c         |   15 +++-
 sbin/mount_cd9660/Makefile           |    5 +-
 sbin/mount_cd9660/mount_cd9660.c     |   11 +++-
 sbin/mount_ext2fs/mount_ext2fs.c     |    5 +-
 sbin/mount_fdesc/mount_fdesc.c       |    5 +-
 sbin/mount_ffs/mount_ffs.c           |    5 +-
 sbin/mount_filecore/Makefile         |    5 +-
 sbin/mount_filecore/mount_filecore.c |    9 ++-
 sbin/mount_kernfs/mount_kernfs.c     |    5 +-
 sbin/mount_lfs/mount_lfs.c           |    5 +-
 sbin/mount_msdos/Makefile            |    5 +-
 sbin/mount_msdos/mount_msdos.c       |   12 +++-
 sbin/mount_nfs/Makefile              |    9 ++-
 sbin/mount_nfs/mount_nfs.c           |   46 ++++++++++++++-
 sbin/mount_ntfs/Makefile             |    5 +-
 sbin/mount_ntfs/mount_ntfs.c         |   12 +++-
 sbin/mount_null/mount_null.c         |    5 +-
 sbin/mount_overlay/mount_overlay.c   |    5 +-
 sbin/mount_portal/mount_portal.c     |    5 +-
 sbin/mount_procfs/Makefile           |    5 +-
 sbin/mount_procfs/mount_procfs.c     |   11 +++-
 sbin/mount_umap/mount_umap.c         |    8 ++-
 sbin/mount_union/Makefile            |    5 +-
 sbin/mount_union/mount_union.c       |   11 +++-
 sbin/newfs/newfs.c                   |   15 ++++-
 29 files changed, 277 insertions(+), 71 deletions(-)

diffs (truncated from 1101 to 300 lines):

diff -r 20e83ef2d2b3 -r f5861ddeaae4 sbin/mount/Makefile
--- a/sbin/mount/Makefile       Sat Sep 21 18:33:51 2002 +0000
+++ b/sbin/mount/Makefile       Sat Sep 21 18:43:31 2002 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: Makefile,v 1.23 2002/09/01 08:10:53 taca Exp $
+#      $NetBSD: Makefile,v 1.24 2002/09/21 18:43:31 christos Exp $
 #      @(#)Makefile    8.6 (Berkeley) 5/8/95
 
 .include <bsd.own.mk>
@@ -39,6 +39,9 @@
 
 CLEANFILES+=   checkname.c
 
+DPADD+=${LIBUTIL}
+LDADD+=-lutil
+
 # generate checkname.c - code which runs appropriate mount_FOO() routine
 # according to program name
 checkname.c: ${.CURDIR}/Makefile
diff -r 20e83ef2d2b3 -r f5861ddeaae4 sbin/mount/mntopts.h
--- a/sbin/mount/mntopts.h      Sat Sep 21 18:33:51 2002 +0000
+++ b/sbin/mount/mntopts.h      Sat Sep 21 18:43:31 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mntopts.h,v 1.9 2000/06/15 22:36:07 fvdl Exp $ */
+/*     $NetBSD: mntopts.h,v 1.10 2002/09/21 18:43:31 christos Exp $    */
 
 /*-
  * Copyright (c) 1994
@@ -62,6 +62,7 @@
 #define MOPT_FORCE             { "force",      1, MNT_FORCE, 0 }
 #define MOPT_UPDATE            { "update",     0, MNT_UPDATE, 0 }
 #define MOPT_RELOAD            { "reload",     0, MNT_RELOAD, 0 }
+#define MOPT_GETARGS           { "getargs",    0, MNT_GETARGS, 0 }
 
 /* Support for old-style "ro", "rw" flags. */
 #define MOPT_RO                        { "ro",         0, MNT_RDONLY, 0 }
diff -r 20e83ef2d2b3 -r f5861ddeaae4 sbin/mount/mount.8
--- a/sbin/mount/mount.8        Sat Sep 21 18:33:51 2002 +0000
+++ b/sbin/mount/mount.8        Sat Sep 21 18:43:31 2002 +0000
@@ -1,4 +1,4 @@
-.\"    $NetBSD: mount.8,v 1.34 2002/05/21 11:17:57 lukem Exp $
+.\"    $NetBSD: mount.8,v 1.35 2002/09/21 18:43:32 christos Exp $
 .\"
 .\" Copyright (c) 1980, 1989, 1991, 1993
 .\"    The Regents of the University of California.  All rights reserved.
@@ -154,6 +154,9 @@
 .Fl f ;
 forces the revocation of write access when trying to downgrade
 a filesystem mount status from read-write to read-only.
+.It Cm getargs
+Retrieves the filesystem specific mount arguments for the given
+mounted filesystem and prints them.
 .It Cm noatime
 Never update the access time field for files.
 This option is useful for optimizing read performance on filesystems
@@ -314,7 +317,9 @@
 .Fl w
 option.
 .It Fl v
-Verbose mode.
+Verbose mode. If this flag is specified more than once, then the
+filesystem-specific mount arguments are printed for the given mounted
+filesystem.
 .It Fl w
 The file system object is to be read and write.
 .El
diff -r 20e83ef2d2b3 -r f5861ddeaae4 sbin/mount/mount.c
--- a/sbin/mount/mount.c        Sat Sep 21 18:33:51 2002 +0000
+++ b/sbin/mount/mount.c        Sat Sep 21 18:43:31 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: mount.c,v 1.60 2002/08/23 03:17:19 lukem Exp $ */
+/*     $NetBSD: mount.c,v 1.61 2002/09/21 18:43:32 christos Exp $      */
 
 /*
  * Copyright (c) 1980, 1989, 1993, 1994
@@ -43,7 +43,7 @@
 #if 0
 static char sccsid[] = "@(#)mount.c    8.25 (Berkeley) 5/8/95";
 #else
-__RCSID("$NetBSD: mount.c,v 1.60 2002/08/23 03:17:19 lukem Exp $");
+__RCSID("$NetBSD: mount.c,v 1.61 2002/09/21 18:43:32 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -76,10 +76,11 @@
                getfslab __P((const char *str));
 static struct statfs *
                getmntpt __P((const char *));
+static int     getmntargs __P((struct statfs *, char *, size_t));
 static int     hasopt __P((const char *, const char *));
 static void    mangle __P((char *, int *, const char ***, int *));
 static int     mountfs __P((const char *, const char *, const char *,
-                   int, const char *, const char *, int));
+                   int, const char *, const char *, int, char *, size_t));
 static void    prmount __P((struct statfs *));
 static void    usage __P((void));
 
@@ -154,7 +155,7 @@
                        init_flags |= MNT_UPDATE;
                        break;
                case 'v':
-                       verbose = 1;
+                       verbose++;
                        break;
                case 'w':
                        init_flags &= ~MNT_RDONLY;
@@ -184,7 +185,7 @@
                                        continue;
                                if (mountfs(fs->fs_vfstype, fs->fs_spec,
                                    fs->fs_file, init_flags, options,
-                                   fs->fs_mntops, !forceall))
+                                   fs->fs_mntops, !forceall, NULL, 0))
                                        rval = 1;
                        }
                else {
@@ -234,7 +235,7 @@
                        mountopts   = fs->fs_mntops;
                }
                rval = mountfs(fstypename, mntfromname,
-                   mntonname, init_flags, options, mountopts, 0);
+                   mntonname, init_flags, options, mountopts, 0, NULL, 0);
                break;
        case 2:
                /*
@@ -252,7 +253,7 @@
                        }
                }
                rval = mountfs(vfstype,
-                   argv[0], argv[1], init_flags, options, NULL, 0);
+                   argv[0], argv[1], init_flags, options, NULL, 0, NULL, 0);
                break;
        default:
                usage();
@@ -303,9 +304,11 @@
 }
 
 static int
-mountfs(vfstype, spec, name, flags, options, mntopts, skipmounted)
+mountfs(vfstype, spec, name, flags, options, mntopts, skipmounted, buf, buflen)
        const char *vfstype, *spec, *name, *options, *mntopts;
        int flags, skipmounted;
+       char *buf;
+       size_t buflen;
 {
        /* List of directories containing mount_xxx subcommands. */
        static const char *edirs[] = {
@@ -319,6 +322,7 @@
        const char **argv, **edir;
        struct statfs *sfp, sf;
        pid_t pid;
+       int pfd[2];
        int argc, numfs, i, status, maxargc;
        char *optbuf, execname[MAXPATHLEN + 1], execbase[MAXPATHLEN],
            mntpath[MAXPATHLEN];
@@ -395,13 +399,18 @@
        argv[argc++] = name;
        argv[argc] = NULL;
 
-       if (verbose) {
+       if (verbose && buf == NULL) {
                (void)printf("exec:");
                for (i = 0; i < argc; i++)
                        (void)printf(" %s", argv[i]);
                (void)printf("\n");
        }
 
+       if (buf) {
+               if (pipe(pfd) == -1)
+                       warn("Cannot create pipe");
+       }
+
        switch (pid = vfork()) {
        case -1:                                /* Error. */
                warn("vfork");
@@ -413,6 +422,13 @@
                if (debug)
                        _exit(0);
 
+               if (buf) {
+                       (void)close(pfd[0]);
+                       (void)close(STDOUT_FILENO);
+                       if (dup2(pfd[1], STDOUT_FILENO) == -1)
+                               warn("Cannot open fd to mount program");
+               }
+
                /* Go find an executable. */
                edir = edirs;
                do {
@@ -432,6 +448,31 @@
                if (optbuf)
                        free(optbuf);
 
+               if (buf || strstr(options, "getargs") != NULL) {
+                       char tbuf[1024], *ptr;
+                       int nread;
+                       if (buf == NULL) {
+                               ptr = tbuf;
+                               buflen = sizeof(tbuf) - 1;
+                       } else {
+                               ptr = buf;
+                               buflen--;
+                       }
+                       (void)close(pfd[1]);
+                       (void)signal(SIGPIPE, SIG_IGN);
+                       while ((nread = read(pfd[0], ptr, buflen)) > 0) {
+                               buflen -= nread;
+                               ptr += nread;
+                       }
+                       *ptr = '\0';
+                       if (buflen == 0) {
+                               while (read(pfd[0], &nread, sizeof(nread)) > 0)
+                                       continue;
+                       }
+                       if (buf == NULL)
+                           (void)fprintf(stdout, "%s", tbuf);
+               }
+
                if (waitpid(pid, &status, 0) < 0) {
                        warn("waitpid");
                        return (1);
@@ -445,12 +486,14 @@
                        return (1);
                }
 
-               if (verbose) {
-                       if (statfs(name, &sf) < 0) {
-                               warn("statfs %s", name);
-                               return (1);
+               if (buf == NULL) {
+                       if (verbose) {
+                               if (statfs(name, &sf) < 0) {
+                                       warn("statfs %s", name);
+                                       return (1);
+                               }
+                               prmount(&sf);
                        }
-                       prmount(&sf);
                }
                break;
        }
@@ -489,13 +532,38 @@
                else
                        (void)printf("%d", sfp->f_owner);
        }
-       if (verbose)
-               (void)printf("%swrites: sync %ld async %ld)\n",
+       if (verbose) {
+               (void)printf("%swrites: sync %ld async %ld",
                    !f++ ? " (" : ", ", sfp->f_syncwrites, sfp->f_asyncwrites);
-       else
+               if (verbose > 1) {
+                       char buf[2048];
+                       if (getmntargs(sfp, buf, sizeof(buf)))
+                               printf(", [%s: %s])\n", sfp->f_fstypename, buf);
+                       else
+                               printf(")\n");
+               }
+       } else
                (void)printf("%s", f ? ")\n" : "\n");
 }
 
+static int
+getmntargs(sfs, buf, buflen)
+       struct statfs *sfs;
+       char *buf;
+       size_t buflen;
+{
+       if (mountfs(sfs->f_fstypename, sfs->f_mntfromname, sfs->f_mntonname, 0,
+           "getargs", NULL, 0, buf, buflen))
+               return 0;
+       else {
+               if (*buf == '\0')
+                       return 0;
+               if ((buf = strchr(buf, '\n')) != NULL)
+                       *buf = '\0';
+               return 1;
+       }
+}
+
 static struct statfs *
 getmntpt(name)
        const char *name;
diff -r 20e83ef2d2b3 -r f5861ddeaae4 sbin/mount_ados/mount_ados.c
--- a/sbin/mount_ados/mount_ados.c      Sat Sep 21 18:33:51 2002 +0000
+++ b/sbin/mount_ados/mount_ados.c      Sat Sep 21 18:43:31 2002 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mount_ados.c,v 1.13 2001/02/22 21:34:57 is Exp $ */
+/* $NetBSD: mount_ados.c,v 1.14 2002/09/21 18:43:33 christos Exp $ */
 
 /*
  * Copyright (c) 1994 Christopher G. Demetriou
@@ -36,7 +36,7 @@
 
 #include <sys/cdefs.h>
 #ifndef lint
-__RCSID("$NetBSD: mount_ados.c,v 1.13 2001/02/22 21:34:57 is Exp $");
+__RCSID("$NetBSD: mount_ados.c,v 1.14 2002/09/21 18:43:33 christos Exp $");
 #endif /* not lint */
 
 #include <sys/cdefs.h>



Home | Main Index | Thread Index | Old Index