From facc3cb0ff89079cca9ce320be9954ee349ad979 Mon Sep 17 00:00:00 2001 From: Brooks Davis Date: Wed, 14 Dec 2016 21:30:44 +0000 Subject: [PATCH] Use nmount(2) rather than the obsolete mount(2). Reviewed by: cem MFC after: 1 week Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D8513 --- bin/df/Makefile | 2 ++ bin/df/df.c | 30 +++++++++++++++++++++++++++--- 2 files changed, 29 insertions(+), 3 deletions(-) diff --git a/bin/df/Makefile b/bin/df/Makefile index c0f2f07b73e1..c054d29a27e8 100644 --- a/bin/df/Makefile +++ b/bin/df/Makefile @@ -9,7 +9,9 @@ PROG= df SRCS= df.c vfslist.c CFLAGS+= -I${MOUNT} + CFLAGS+= -DMOUNT_CHAR_DEVS +SRCS+= getmntopts.c LIBADD= xo util diff --git a/bin/df/df.c b/bin/df/df.c index 3ed7c1e8f49c..9ecff3586eb0 100644 --- a/bin/df/df.c +++ b/bin/df/df.c @@ -56,6 +56,9 @@ __FBSDID("$FreeBSD$"); #include #include #include +#ifdef MOUNT_CHAR_DEVS +#include +#endif #include #include #include @@ -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);