- 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
This commit is contained in:
Craig Rodrigues 2005-11-13 01:27:57 +00:00
parent 25efbfb212
commit b19e74ca20
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=152354
3 changed files with 31 additions and 8 deletions

View File

@ -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);
}

View File

@ -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, ...);

View File

@ -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)