c - 为什么无法识别文件系统?

标签 c linux partition

我正在尝试打印当前 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/

相关文章:

c++ - 数组下标的无效类型 ‘unsigned char[int]’

c - 在 C 中对 double 数组进行排序

c++ - 在 Windows x64 中检查内存泄漏的免费应用程序?

select - hive QL : How do I extract info from "show partitions table' and use it in a query?

c - 将字符分配给在 C 中使用 malloc 声明的二维数组时收到警告

从 shell 调用 python 脚本时不执行

linux - 项目 Clearwater Sprout 更新后无法正常工作

android - adb 不显示 nexus 5 设备

google-bigquery - 超出 Bigquery 分区限制

C 数组分区