trh411 said:Does How to use mount function from c help? There are literally tons of c coding examples on the net for those willing to do a bit of Googleing.
int
mount(const char *source, const char *target, const char *filesystemtype, unsigned long mountflags,const void *data);
int
mount(const char *type, const char *dir, int flags, void *data);
#include <iostream>
#include <cstring>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/uio.h>
using namespace std;
void build_iovec(struct iovec **iov,int *iovlen,const char *line,
void *val,size_t len);
int main()
{
iovec *iov = new iovec;
int iovlen = 0;
char fstype[]="ufs";
char fspath[]="/dev/da0a";
char from[]="/media";
build_iovec(&iov,&iovlen,"fstype",fstype,(size_t)-1);
build_iovec(&iov,&iovlen,"fspath",fspath,(size_t)-1);
build_iovec(&iov,&iovlen,"from",from,(size_t)-1);
if(nmount(iov,iovlen,0) < 0)
{
cerr<<"\nFailed ";
return -1;
}
delete [] iov;
return 0;
}
void build_iovec(struct iovec **iov,int *iovlen,const char *line,
void *val,size_t len)
{
int number;
if (*iovlen < 0)
return;
number = *iovlen;
(*iov)[number].iov_base = strdup(line);
(*iov)[number].iov_len = strlen(line);
number++;
(*iov)[number].iov_base = val;
if( len == (size_t) -1)
{
if(val != NULL)
len = strlen((const char *)val) + 1;
else
len = 0;
}
(*iov)[number].iov_len = (int)len;
*iovlen = ++number;
}
#include <iostream>
#include <cstring>
#include <sys/mount.h>
#include <sys/param.h>
#include <sys/uio.h>
using namespace std;
void build_iovec_pair(struct iovec **iov,int *iovlen,const char *name,
void *val,size_t len);
int main()
{
iovec *iov = new iovec[6];
int iovlen = 0;
char fstypeName[]="fstype";
char fstypeValue[]="ufs";
char fspathName[]="fspath";
char fspathValue[]="/media";
char fromName[]="from";
char fromValue[]="/dev/da0a";
build_iovec_pair(&iov,&iovlen,fstypeName,fstypeValue,(size_t)-1);
build_iovec_pair(&iov,&iovlen,fspathName,fspathValue,(size_t)-1);
build_iovec_pair(&iov,&iovlen,fromName,fromValue,(size_t)-1);
if(nmount(iov,iovlen,0) < 0)
{
cerr<<"\nFailed ";
return -1;
}
delete [] iov;
return 0;
}
void build_iovec_pair(struct iovec **iov,int *iovlen,const char *name,
void *val,size_t len)
{
int number;
if (*iovlen < 0)
return;
number = *iovlen;
(*iov)[number].iov_base = (void *)name;
(*iov)[number].iov_len = strlen(name) + 1;
number++;
(*iov)[number].iov_base = val;
if( len == (size_t) -1)
{
if(val != NULL)
len = strlen((const char *)val) + 1;
else
len = 0;
}
(*iov)[number].iov_len = (int)len;
*iovlen = ++number;
}