diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c index ba35b3e68006..f0026f48cd2b 100644 --- a/sbin/mount/getmntopts.c +++ b/sbin/mount/getmntopts.c @@ -36,11 +36,15 @@ static char sccsid[] = "@(#)getmntopts.c 8.3 (Berkeley) 3/29/95"; __FBSDID("$FreeBSD$"); #include +#include #include #include +#include #include #include +#include +#include #include #include #include @@ -134,7 +138,8 @@ checkpath(const char *path, char *resolved) } void -build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len) +build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, + size_t len) { int i; @@ -150,8 +155,25 @@ build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int le (*iov)[i].iov_len = strlen(name) + 1; i++; (*iov)[i].iov_base = val; - if (len < 0) + if (len == (size_t)-1) len = strlen(val) + 1; - (*iov)[i].iov_len = len; + (*iov)[i].iov_len = (int)len; *iovlen = ++i; } + +/* + * This function is needed for compatibility with parameters + * which used to use the mount_argf() command for the old mount() syscall. + */ +void +build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, + const char *fmt, ...) +{ + va_list ap; + char val[255] = { 0 }; + + va_start(ap, fmt); + vsnprintf(val, sizeof(val), fmt, ap); + va_end(ap); + build_iovec(iov, iovlen, name, strdup(val), (size_t)-1); +} diff --git a/sbin/mount/mntopts.h b/sbin/mount/mntopts.h index 17674da1b600..13a3b532664f 100644 --- a/sbin/mount/mntopts.h +++ b/sbin/mount/mntopts.h @@ -95,4 +95,5 @@ void getmntopts(const char *, const struct mntopt *, int *, int *); void rmslashes(char *, char *); void checkpath(const char *, char resolved_path[]); extern int getmnt_silent; -void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, int len); +void build_iovec(struct iovec **iov, int *iovlen, const char *name, void *val, size_t len); +void build_iovec_argf(struct iovec **iov, int *iovlen, const char *name, const char *fmt, ...); diff --git a/sbin/mount/mount_fs.c b/sbin/mount/mount_fs.c index d56891fcf965..d9b0b3cae307 100644 --- a/sbin/mount/mount_fs.c +++ b/sbin/mount/mount_fs.c @@ -104,7 +104,7 @@ mount_fs(const char *vfstype, int argc, char *argv[]) *p = '\0'; val = p + 1; } - build_iovec(&iov, &iovlen, optarg, val, -1); + build_iovec(&iov, &iovlen, optarg, val, (size_t)-1); break; case '?': default: @@ -123,9 +123,9 @@ mount_fs(const char *vfstype, int argc, char *argv[]) (void)checkpath(dir, mntpath); (void)rmslashes(dev, dev); - build_iovec(&iov, &iovlen, "fstype", fstype, -1); - build_iovec(&iov, &iovlen, "fspath", mntpath, -1); - build_iovec(&iov, &iovlen, "from", dev, -1); + build_iovec(&iov, &iovlen, "fstype", fstype, (size_t)-1); + build_iovec(&iov, &iovlen, "fspath", mntpath, (size_t)-1); + build_iovec(&iov, &iovlen, "from", dev, (size_t)-1); ret = nmount(iov, iovlen, mntflags); if (ret < 0)