diff options
author | rodrigc <rodrigc@FreeBSD.org> | 2005-11-13 01:27:57 +0000 |
---|---|---|
committer | rodrigc <rodrigc@FreeBSD.org> | 2005-11-13 01:27:57 +0000 |
commit | cad3062c68ed314c50469ae467580e125182db35 (patch) | |
tree | 077796e9e14320ad6f899ca9a21cd18bccad56cd /sbin | |
parent | f63f109c0bfa1b21d8d5360a6bcf0e0f2e86b7ee (diff) | |
download | FreeBSD-src-cad3062c68ed314c50469ae467580e125182db35.zip FreeBSD-src-cad3062c68ed314c50469ae467580e125182db35.tar.gz |
- Make size parameter to build_iovec() a size_t, not an int
- Add build_iovec_argf() helper function, for help converting old
mount options which used the mount_argf() function for the mount() syscall.
Discussed with: phk
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/mount/getmntopts.c | 28 | ||||
-rw-r--r-- | sbin/mount/mntopts.h | 3 | ||||
-rw-r--r-- | sbin/mount/mount_fs.c | 8 |
3 files changed, 31 insertions, 8 deletions
diff --git a/sbin/mount/getmntopts.c b/sbin/mount/getmntopts.c index ba35b3e..f0026f4 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 <sys/param.h> +#include <sys/mount.h> #include <sys/stat.h> #include <sys/uio.h> +#include <assert.h> #include <err.h> #include <errno.h> +#include <stdarg.h> +#include <stdio.h> #include <stdlib.h> #include <string.h> #include <sysexits.h> @@ -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 17674da..13a3b53 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 d56891f..d9b0b3c 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) |