我正在实现一个容器,该容器使用新的命名空间进行克隆,包括挂载、pid、用户命名空间等。孩子要做的第一步是挂载几个重要点,例如/proc,/sys和/tmp使用mount系统调用。
if(::mount("proc", "/proc", "proc", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
if(::mount("sysfs", "/sys", "sysfs", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
if(::mount("tmp", "/tmp", "tmpfs", 0, NULL)==-1) {
printf("Failed on mount: %s\n", strerror(errno));
return -1;
}
但是,我对source传递给的参数列表中的字段有点困惑mount。
int mount(const char *source, const char *target,
const char *filesystemtype, unsigned long mountflags,
const void *data);
来源的确切含义是什么?例如,挂载/tmp似乎与源字符字符串无关。即使/tmp使用::mount(nullptr, "/tmp", "tmpfs", 0, NULL). 我错过了什么吗?