1

我正在寻找一种解决方案来获取tmpfs我的 Linux 系统上所有可用挂载点的列表,我需要从 C/C++ 程序中获取它。我需要一个不依赖于发行版的通用解决方案。我不想访问/proc/mounts/etc/fstab. 我不想使用system()or popen()

还有其他方法吗?

谢谢你的帮助!

4

1 回答 1

3

The way mount implements this is to read /etc/mtab - strace mount is the fastest way to verify this if you don't have the source at hand. But as /etc/mtab is updated by mount/umount, and /proc/mounts is managed by the kernel itself, /proc/mounts is the better idea of the 2, and it's there on every linux system, independent of distro (hmm, maybe my Suse 4.4.2 which dates back to 1996 is an exception).

Or, if you want to be portable to non-linux Unixes, use the getmntent family of functions - but as the manual page states, other unixes have functions with the same name perform differently from the linux implementation, so while your code may compile on non-linux unixes, it won't neccesarily work correctly there.

于 2014-01-23T20:40:31.877 回答