我正在實現一個容器,該容器使用包括mount,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
似乎與源字符串沒有任何關係。即使使用::mount(nullptr, "/tmp", "tmpfs", 0, NULL)
,我仍然可以在新的名稱空間下看到新的/tmp
文件夾。我錯過了什麼嗎?