[英]List mount points in C++ on Linux without using /proc/mounts, /etc/fstab, system() or popen()
I am looking for a solution to get the list of all tmpfs
mount points available on my Linux system and I need to get it from a C/C++ program. 我正在寻找一个解决方案来获取我的Linux系统上可用的所有
tmpfs
挂载点的列表,我需要从C / C ++程序中获取它。 I need a generic solution that is not distro dependent. 我需要一个不依赖于发行版的通用解决方案。 I don't want to access
/proc/mounts
or /etc/fstab
. 我不想访问
/proc/mounts
或/etc/fstab
。 I don't want to use a system()
or popen()
. 我不想使用
system()
或popen()
。
Is there another way? 还有另外一种方法吗?
Thanks for your help! 谢谢你的帮助!
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. mount
实现这一点的方法是读取/etc/mtab
- 如果你手边没有源代码, strace mount
是验证这个的最快方法。 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). 但是当
/etc/mtab
由mount / umount更新,并且/proc/mounts
由内核本身管理时, /proc/mounts
是2的更好的想法,并且它在每个linux系统上,独立于发行版(hmm) ,也许我的Suse 4.4.2可以追溯到1996年是一个例外)。
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. 或者,如果你想要移植到非Linux Unix,可以使用getmntent系列函数 - 但是正如手册页所述,其他unix具有相同名称的函数与linux实现不同,所以虽然你的代码可以编译非linux unix,它不会在那里正常工作 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.