我正在尝试打印当前 linux 分区的磁盘状态。使用以下 C 代码:
#include <stdio.h>
#include <stdlib.h>
#include <sys/statfs.h>
struct statfs S;
int main(int argc,char *argv[]){
int i = statfs("/dev/sda3",&S);
if (i!=0){
printf("File path error!!\n");
exit(0);
}
if(S.f_type == 0xEF53){
printf("The file system is ext_fs");
}
if (S.f_type == 0x4d44)
printf("The Partition is MS DOS super magic\n");
else
printf("Some other partition\n");
printf("Optimum transfer Blocks: %ld\n",S.f_bsize);
return 0;
**问题是 if(S.f_type == 0xEF53)
行无法正常工作,即即使我通过 /dev/sda4
条件也返回 false分区(我的 linux 分区 ext4)。
我搜索了很多但无法解决问题。请在这里指导我....
编辑 S.f_type
的值是16914836
最佳答案
The
statfs()
system call returns information about a mounted filesystem. path is the pathname of any file within the mounted filesystem.
相反,您是在设备上使用它,因此您获取的不是关于它的信息,而是关于 /dev
所在的文件系统的信息(编辑:您报告的魔数(Magic Number)对应于 TMPFS_MAGIC
,因此您的 /dev
是一个 tmpfs
文件系统)。
您必须先挂载 /dev/sda3
(如果尚未挂载),然后在挂载点或其下方的任何文件上调用 statfs
以获取有关该文件的信息系统通过这个系统调用。
关于c - 为什么无法识别文件系统?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35546937/