有没有办法判断一个文件是在本地磁盘还是在 C 中的 NFS?代码应该可以跨各种 Linux 发行版移植,并且不应依赖于系统调用(例如 stat -f)。
最佳答案
您想使用 statfs
来自 <sys/vfs.h>
.
int statfs(const char *path, struct statfs *buf); struct statfs { __SWORD_TYPE f_type; /* type of file system (see below) */
使用方法如下:
struct statfs s;
if (statfs("/etc", &s))
perror("statfs");
switch (s->f_type) {
case EXT2_SUPER_MAGIC:
break;
case EXT3_SUPER_MAGIC:
break;
default:
break;
}
还有:
- 你混淆了“外部命令”和“系统调用”。它们是非常不同的东西
- stat(1) 命令在 Linux 发行版之间非常可移植。
关于c - 在C中检测文件系统,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8389482/