我想实现"mount -t ecryptfs /test /test"用mount的api来写
代码:
#include
#include
#include
#include
struct DO_MOUNT_t{
char *target;
char *source;
char *ftype;
char *mount_data;
unsigned long mountflags;
};
struct DO_MOUNT_t do_mount = {
.target = "/home/hb/workspace/hb_ecryptfs/src/mountecryptfs",
.source = "/home/hb/workspace/hb_ecryptfs/src/mountecryptfs",
.ftype = "ecryptfs",
.mount_data = "ecryptfs_sig=a72b681d8911efa9,"
"ecryptfs_cipher=aes,"
"ecryptfs_key_bytes=16",
//"ecryptfs_opt_passthrough=n,"
//"ecryptfs_enable_filename_crypto=n",
.mountflags = 0,
};
int main(int argc, char *argv[])
{
int ret;
//printf("111:%s\n", do_mount.mount_data);
ret = mount(do_mount.source, do_mount.target, do_mount.ftype, do_mount.mountflags, do_mount.mount_data);
//ret = sys_mount(do_mount.source, do_mount.target, do_mount.ftype, do_mount.mountflags, do_mount.mount_data);
if( ret < 0 ){
//if(EBUSY == errno){
printf("mount failed! error:%s\n", strerror(errno));
//}
return -1;
}
printf("111\n");
//printf("mount %s -> %s success\n", do_mount.source, do_mount.target);
return 0;
}
执行完提示:error:No such file or directory,我猜测是do_mount.data里面的参数没有写对,但是我不知道怎么完善它