]> xenbits.xensource.com Git - people/royger/freebsd.git/commitdiff
Use nmount(2) rather than the obsolete mount(2).
authorbrooks <brooks@FreeBSD.org>
Wed, 14 Dec 2016 21:30:44 +0000 (21:30 +0000)
committerbrooks <brooks@FreeBSD.org>
Wed, 14 Dec 2016 21:30:44 +0000 (21:30 +0000)
Reviewed by: cem
MFC after: 1 week
Sponsored by: DARPA, AFRL
Differential Revision: https://reviews.freebsd.org/D8513

bin/df/Makefile
bin/df/df.c

index c0f2f07b73e1e605a12d55e53b83e92e6d4e8e07..c054d29a27e879ed3b29c9e234f20338259cd525 100644 (file)
@@ -9,7 +9,9 @@ PROG=   df
 SRCS=  df.c vfslist.c
 
 CFLAGS+= -I${MOUNT}
+
 CFLAGS+= -DMOUNT_CHAR_DEVS
+SRCS+= getmntopts.c
 
 LIBADD=        xo util
 
index 3ed7c1e8f49cf1cd6ef5bd847bbdbc8b244bab60..9ecff3586eb0401e9f37029a7e9740f70d1a945e 100644 (file)
@@ -56,6 +56,9 @@ __FBSDID("$FreeBSD$");
 #include <err.h>
 #include <libutil.h>
 #include <locale.h>
+#ifdef MOUNT_CHAR_DEVS
+#include <mntopts.h>
+#endif
 #include <stdint.h>
 #include <stdio.h>
 #include <stdlib.h>
@@ -111,14 +114,21 @@ main(int argc, char *argv[])
        struct statfs statfsbuf, totalbuf;
        struct maxwidths maxwidths;
        struct statfs *mntbuf;
+#ifdef MOUNT_CHAR_DEVS
+       struct iovec *iov = NULL;
+#endif
        const char *fstype;
 #ifdef MOUNT_CHAR_DEVS
        char *mntpath;
+       char errmsg[255] = {0};
 #endif
        char *mntpt;
        const char **vfslist;
        int i, mntsize;
        int ch, rv;
+#ifdef MOUNT_CHAR_DEVS
+       int iovlen = 0;
+#endif
 
        fstype = "ufs";
        (void)setlocale(LC_ALL, "");
@@ -251,9 +261,23 @@ main(int argc, char *argv[])
                                        free(mntpath);
                                        continue;
                                }
-                               if (mount(fstype, mntpt, MNT_RDONLY|MNT_NOEXEC,
-                                   &mdev) != 0) {
-                                       xo_warn("%s", *argv);
+                               if (iov != NULL)
+                                       free_iovec(&iov, &iovlen);
+                               build_iovec_argf(&iov, &iovlen, "fstype", "%s",
+                                   fstype);
+                               build_iovec_argf(&iov, &iovlen, "fspath", "%s",
+                                   mntpath);
+                               build_iovec_argf(&iov, &iovlen, "from", "%s",
+                                   *argv);
+                               build_iovec(&iov, &iovlen, "errmsg", errmsg,
+                                   sizeof(errmsg));
+                               if (nmount(iov, iovlen,
+                                   MNT_RDONLY|MNT_NOEXEC) < 0) {
+                                       if (errmsg[0])
+                                               xo_warn("%s: %s", *argv,
+                                                   errmsg);
+                                       else
+                                               xo_warn("%s", *argv);
                                        rv = 1;
                                        (void)rmdir(mntpt);
                                        free(mntpath);