linux中的mount系统调用无法通过df命令显示文件系统的挂载点 [英] mount system call in linux cannot display the mountpoint of file system by df command
问题描述
我正在尝试在程序中使用mount()
而不是mount
命令,我成功使用了以下mount()
,结果返回了成功,而不是Invalid Argument
.
I am trying to use mount()
instead of mount
command in my program, I use the following mount()
successfully, the result returned success instead of Invalid Argument
.
int rc = mount("172.16.74.20:/data/redun/snmp","/mnt/data/redun/snmp",
"nfs",0,"soft,timeo=2,addr=172.16.74.20");
if (rc != 0)
{
printf("mount failed, errCode=%d, reason=%s\n",errno, strerror(errno));
}
但是当我使用df -h
检查安装点时,没有任何显示.
我发现相关设备尚未安装.发生了什么?真的成功安装了吗?如何在Linux中通过df
命令显示已安装的设备?
But when I use df -h
to check the mountpoint, there are nothing displayed.
I found the related device was not mounted yet. What happened? Is it really mounted successfully? How can I display the mounted device by df
command in Linux?
推荐答案
问题在于,与mount
命令不同,mount()
syscall不会更新/etc/mtab
文件,而df
命令会解析/etc/mtab
列出挂载点.
The problem is that mount()
syscall, unlike mount
command, doesn't update /etc/mtab
file, while df
command parses /etc/mtab
to list mount points.
但是,安装点的最新列表始终在/proc/mounts
文件中可用.与/etc/mtab
不同,/proc/mounts
不是常规文件,而是内核提供的虚拟文件.
However, uptodate list of mount points is always available in /proc/mounts
file. Unlike /etc/mtab
, /proc/mounts
is not a regular file, but instead a virtual file provided by kernel.
在某些发行版中,/etc/mtab
是指向/proc/mounts
的符号链接.如果不是,并且您希望df
工作,则可以执行以下操作:
On some distributions, /etc/mtab
is a symlink to /proc/mounts
. If it's not, and you want df
to work, you can do the following:
cat /proc/mounts > /etc/mtab
每次mount()
或umount()
调用后
.
您也可以将/etc/mtab
链接到/proc/mounts
或更好的/proc/self/mounts
,但是要您自担风险(也许某些应用程序依赖它,但这可能只是发行版中的错误).
You can also make /etc/mtab
a symlink to /proc/mounts
or better /proc/self/mounts
, but do it on your own risk (maybe some applications depend on it, but maybe it's just a bug in your distro).
另请参见 查看全文