如果 GNU stat实用程序在您的目标平台上可用,那么您可以以不使用statfs调用来检测挂载点的方式调用它,然后在 mount 的输出中搜索它,例如在 Linux 上:
$ mount | grep -F `stat -c %m /boot/grub` | cut -d' ' -f5
ext2
我验证了此stat调用仅使用标准系统调用(请参阅stat(2)手册页中的 CONFORMING TO ):
$ strace stat -c %m /boot/grub/ |& fgrep stat
execve("/usr/bin/stat", ["stat", "-c", "%m", "/boot/grub/"], [/* 65 vars */]) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=218501, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=130224, ...}) = 0
fstat(3, {st_mode=S_IFREG|0755, st_size=1868984, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=456632, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=14608, ...}) = 0
fstat(3, {st_mode=S_IFREG|0755, st_size=138696, ...}) = 0
statfs("/sys/fs/selinux", 0x7ffe62882ff0) = -1 ENOENT (No such file or directory)
statfs("/selinux", 0x7ffe62882ff0) = -1 ENOENT (No such file or directory)
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
fstat(3, {st_mode=S_IFREG|0644, st_size=5152256, ...}) = 0
lstat("/boot/grub/", {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
lstat("/boot", {st_mode=S_IFDIR|0755, st_size=3072, ...}) = 0
lstat("/boot/grub", {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
fstat(3, {st_mode=S_IFREG|0444, st_size=0, ...}) = 0
stat("/boot/grub", {st_mode=S_IFDIR|0755, st_size=1024, ...}) = 0
stat("..", {st_mode=S_IFDIR|0755, st_size=3072, ...}) = 0
stat("..", {st_mode=S_IFDIR|0755, st_size=4096, ...}) = 0
stat("/boot", {st_mode=S_IFDIR|0755, st_size=3072, ...}) = 0
fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0