【发布时间】:2020-02-01 19:08:02
【问题描述】:
我正在尝试使用 c++ 执行挂载,但我想排除一个正在挂载的特定文件,因为我不希望该文件被任何其他进程触及。
以下是我的源代码:
#include <sys/mount.h>
#define DROOT "/rd/daemon-root"
if (mkdir(DROOT, 0744) && errno != EEXIST)
cout<<endl<<"Can't create "<<DROOT <<" (" << strerror(errno) << ")";
int r = mount("/", DROOT, "ext4", MS_BIND, NULL);
if (r == -1)
cout<<endl<<"Mounting of " DROOT " failed (" << strerror(errno) << ")";
else
cout<<endl<<DROOT<<" mounted successfully";
现在我的系统根目录包含 /etc 目录,我不希望它被挂载,因为使用挂载的进程会更改它。
有什么办法可以避免挂载特定目录,或者让它以一种方式改变,这样挂载上的更改就不会影响实际。
PS - 已经尝试过https://www.gnu.org/software/libc/manual/html_node/Mount_002dUnmount_002dRemount.html 列出的选项,但没有任何帮助。甚至没有 MS_ReadOnly
【问题讨论】: