[Midnightbsd-cvs] src [8611] trunk/sbin/mount_nullfs/mount_nullfs.c: allow to specify cache/nocache options in mount_nullfs(8)
laffer1 at midnightbsd.org
laffer1 at midnightbsd.org
Sun Sep 25 13:35:48 EDT 2016
Revision: 8611
http://svnweb.midnightbsd.org/src/?rev=8611
Author: laffer1
Date: 2016-09-25 13:35:48 -0400 (Sun, 25 Sep 2016)
Log Message:
-----------
allow to specify cache/nocache options in mount_nullfs(8)
Modified Paths:
--------------
trunk/sbin/mount_nullfs/mount_nullfs.c
Modified: trunk/sbin/mount_nullfs/mount_nullfs.c
===================================================================
--- trunk/sbin/mount_nullfs/mount_nullfs.c 2016-09-25 17:35:08 UTC (rev 8610)
+++ trunk/sbin/mount_nullfs/mount_nullfs.c 2016-09-25 17:35:48 UTC (rev 8611)
@@ -57,11 +57,6 @@
#include "mntopts.h"
-struct mntopt mopts[] = {
- MOPT_STDOPTS,
- MOPT_END
-};
-
int subdir(const char *, const char *);
static void usage(void) __dead2;
@@ -68,16 +63,29 @@
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:
@@ -97,21 +105,16 @@
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);
}
More information about the Midnightbsd-cvs
mailing list