请问linux /proc/self/(mountinfo、mountstats、mounts),用哪个文件拿挂载点信息?

需求是拿到linux fliesystem相关信息。

我的做法是先通过/proc/self/(mountinfo、mountstats、mounts) 这三个中任意一个文件拿到挂载点信息,然后通过挂载点来调用statfs函数获取其他信息。

但是我发现,这个三个文件记录的文件记录的挂载点居然有少部分不一样,我想问问大家应该拿哪个?

阅读 5k
1 个回答

建议是使用 mountinfo

在proc的文档中有简单提到,mountinfo 最新,linux 2.6.26引入,它是为了替代mounts(linux 2.4.19引入) 而出现的,同时也解决了mounts存在的一些问题

It supplies various information (e.g.,  propaga‐
              tion  state, root of mount for bind mounts, identifier for each mount and its parent) that is missing from the (older) /proc/[pid]/mounts file, and fixes vari‐
              ous other problems with that file (e.g., nonextensibility, failure to distinguish per-mount versus per-superblock options).

而mountstats则更多的目的是暴露一些统计信息和配置信息?文档中提到只有NFS有这些信息暴露,其他文件系统只有普通的类型和挂载点记录,它在 Linux 2.6.17引入,略早于mountinfo,信息详细程度没有 mountinfo 多。

从文档来看,我盲猜:
1、挂载点的数量:mountinfo = mountstats >= mounts
2、挂载点信息的详细程度:mountinfo > mounts > mountstats

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题