Я хочу использовать функцию монтирования для реализации NFS.способ использования функция крепления c c?
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
можно реализовать с помощью командыmount 172.16.0.144:/tmp/test /tmp/test
например крепление. Но когда я использую функцию mount()
, она не работает. Это мой код здесь.
#include<sys/mount.h>
#include<iostream>
#include<errno.h>
#include<fstream>
#include<string.h>
using namespace std;
int main(int argc, char**argv) {
const char* srcPath = "/tmp/watchman";
const char* targetPath = "172.16.0.144:/tmp/watchman";
if (argc == 3) {
srcPath = argv[1];
targetPath = argv[2];
cerr << "reset the src && target path\n";
} else {
if (argc != 1) {
cerr << "wrong input argument!\n";
return 0;
}
}
cerr << "srcPath = " << srcPath << endl;
cerr << "target = " << targetPath << endl;
int ret_val = mount(srcPath, targetPath, "", MS_SHARED, "");
if (ret_val == 0) {
cerr << "mount succeed\n";
string filename = string(srcPath) + "/" + "tmp.txt";
fstream fin(filename.c_str(), ios::out);
fin << "there is a write test from client\n";
fin.close();
ret_val = umount(srcPath);
if (ret_val == 0) {
cerr << "umount succeed \n";
} else {
cerr << "umount failed \n";
printf("%s/n", strerror(errno));
}
} else {
cout<<"ret_val = "<<ret_val<<endl;
cerr << "mount failed \n";
cerr << strerror(errno) << endl;
}
return 0;
}
Не удалось установить файл с печатью, нет такого файла или каталога. кто-нибудь может мне помочь? пожалуйста !!!
Используйте правильные метки. Это C++, а не C. – Olaf