aboutsummaryrefslogtreecommitdiff
path: root/sbin/mount_nullfs/mount_nullfs.c
diff options
context:
space:
mode:
authorKonstantin Belousov <kib@FreeBSD.org>2013-01-03 19:18:46 +0000
committerKonstantin Belousov <kib@FreeBSD.org>2013-01-03 19:18:46 +0000
commit73a44978ce60fb1e10b5aa3dd92a2d47fd5ca31e (patch)
tree114f645ffd0284f01f726d4628fb5d61133ce4a2 /sbin/mount_nullfs/mount_nullfs.c
parent9cf4c952caa443733ad3b44fa274a2018a94f5f5 (diff)
Allow to specify "cache" and "nocache" as an option for
mount_nullfs(8). Tested by: pho MFC after: 2 weeks
Notes
Notes: svn path=/head/; revision=245005
Diffstat (limited to 'sbin/mount_nullfs/mount_nullfs.c')
-rw-r--r--sbin/mount_nullfs/mount_nullfs.c49
1 files changed, 26 insertions, 23 deletions
diff --git a/sbin/mount_nullfs/mount_nullfs.c b/sbin/mount_nullfs/mount_nullfs.c
index c88db3d91cb5..aaf66e527ea3 100644
--- a/sbin/mount_nullfs/mount_nullfs.c
+++ b/sbin/mount_nullfs/mount_nullfs.c
@@ -57,27 +57,35 @@ static const char rcsid[] =
#include "mntopts.h"
-static struct mntopt mopts[] = {
- MOPT_STDOPTS,
- MOPT_END
-};
-
int subdir(const char *, const char *);
static void usage(void) __dead2;
int
main(int argc, char *argv[])
{
- struct iovec iov[6];
- int ch, mntflags;
+ struct iovec *iov;
+ char *p, *val;
char source[MAXPATHLEN];
char target[MAXPATHLEN];
+ char errmsg[255];
+ int ch, mntflags, iovlen;
+ char nullfs[] = "nullfs";
+ iov = NULL;
+ iovlen = 0;
mntflags = 0;
+ errmsg[0] = '\0';
while ((ch = getopt(argc, argv, "o:")) != -1)
switch(ch) {
case 'o':
- getmntopts(optarg, mopts, &mntflags, 0);
+ val = strdup("");
+ p = strchr(optarg, '=');
+ if (p != NULL) {
+ free(val);
+ *p = '\0';
+ val = p + 1;
+ }
+ build_iovec(&iov, &iovlen, optarg, val, (size_t)-1);
break;
case '?':
default:
@@ -99,21 +107,16 @@ main(int argc, char *argv[])
errx(EX_USAGE, "%s (%s) and %s are not distinct paths",
argv[0], target, argv[1]);
- iov[0].iov_base = strdup("fstype");
- iov[0].iov_len = sizeof("fstype");
- iov[1].iov_base = strdup("nullfs");
- iov[1].iov_len = strlen(iov[1].iov_base) + 1;
- iov[2].iov_base = strdup("fspath");
- iov[2].iov_len = sizeof("fspath");
- iov[3].iov_base = source;
- iov[3].iov_len = strlen(source) + 1;
- iov[4].iov_base = strdup("target");
- iov[4].iov_len = sizeof("target");
- iov[5].iov_base = target;
- iov[5].iov_len = strlen(target) + 1;
-
- if (nmount(iov, 6, mntflags))
- err(1, NULL);
+ build_iovec(&iov, &iovlen, "fstype", nullfs, (size_t)-1);
+ build_iovec(&iov, &iovlen, "fspath", source, (size_t)-1);
+ build_iovec(&iov, &iovlen, "target", target, (size_t)-1);
+ build_iovec(&iov, &iovlen, "errmsg", errmsg, sizeof(errmsg));
+ if (nmount(iov, iovlen, mntflags) < 0) {
+ if (errmsg[0] != 0)
+ err(1, "%s: %s", source, errmsg);
+ else
+ err(1, "%s", source);
+ }
exit(0);
}