summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorbrooks <brooks@FreeBSD.org>2016-12-21 23:59:58 +0000
committerbrooks <brooks@FreeBSD.org>2016-12-21 23:59:58 +0000
commit3da535c57bb49c6358142724612703ba7299610c (patch)
tree908d220484e14befbf083345d3643a9500e3a977 /bin
parent073d345401228e7f0fc7dc371f8bc8f0d63d5562 (diff)
downloadFreeBSD-src-3da535c57bb49c6358142724612703ba7299610c.zip
FreeBSD-src-3da535c57bb49c6358142724612703ba7299610c.tar.gz
MFC r310088, r310090, r310095
r310088: Put the undocumented df feature of mounting filesystems from device nodes under an ifdef. Leave enabled. Reviewed by: cem Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D8513 r310090: Mount filesystems without executable permissions since they should never be used. Reviewed by: cem Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D8513 r310095: Use nmount(2) rather than the obsolete mount(2). Reviewed by: cem Sponsored by: DARPA, AFRL Differential Revision: https://reviews.freebsd.org/D8513
Diffstat (limited to 'bin')
-rw-r--r--bin/df/Makefile3
-rw-r--r--bin/df/df.c41
2 files changed, 40 insertions, 4 deletions
diff --git a/bin/df/Makefile b/bin/df/Makefile
index df6574c..2dde4cc 100644
--- a/bin/df/Makefile
+++ b/bin/df/Makefile
@@ -9,6 +9,9 @@ SRCS= df.c vfslist.c
CFLAGS+= -I${MOUNT}
+CFLAGS+= -DMOUNT_CHAR_DEVS
+SRCS+= getmntopts.c
+
DPADD= ${LIBUTIL}
LDADD= -lutil
diff --git a/bin/df/df.c b/bin/df/df.c
index ba87055..3c10878 100644
--- a/bin/df/df.c
+++ b/bin/df/df.c
@@ -50,10 +50,15 @@ __FBSDID("$FreeBSD$");
#include <sys/stat.h>
#include <sys/mount.h>
#include <sys/sysctl.h>
+#ifdef MOUNT_CHAR_DEVS
#include <ufs/ufs/ufsmount.h>
+#endif
#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>
@@ -97,7 +102,9 @@ imax(int a, int b)
static int aflag = 0, cflag, hflag, iflag, kflag, lflag = 0, nflag, Tflag;
static int thousands;
+#ifdef MOUNT_CHAR_DEVS
static struct ufs_args mdev;
+#endif
int
main(int argc, char *argv[])
@@ -106,11 +113,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;
- char *mntpath, *mntpt;
+#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, "");
@@ -215,6 +232,7 @@ main(int argc, char *argv[])
rv = 1;
continue;
}
+#ifdef MOUNT_CHAR_DEVS
} else if (S_ISCHR(stbuf.st_mode)) {
if ((mntpt = getmntpt(*argv)) == NULL) {
mdev.fspec = *argv;
@@ -231,9 +249,23 @@ main(int argc, char *argv[])
free(mntpath);
continue;
}
- if (mount(fstype, mntpt, MNT_RDONLY,
- &mdev) != 0) {
- 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])
+ warn("%s: %s", *argv,
+ errmsg);
+ else
+ warn("%s", *argv);
rv = 1;
(void)rmdir(mntpt);
free(mntpath);
@@ -252,6 +284,7 @@ main(int argc, char *argv[])
free(mntpath);
continue;
}
+#endif
} else
mntpt = *argv;
OpenPOWER on IntegriCloud