【问题标题】:What is the equivalent of getfsstat() on Linux?Linux 上的 getfsstat() 等价物是什么?
【发布时间】:2010-12-28 10:14:26
【问题描述】:

问题说明了一切。我想要 C 函数调用,它返回已安装文件系统的列表以及文件系统类型等相关信息。

【问题讨论】:

    标签: linux filesystems mount


    【解决方案1】:

    您正在寻找getmntent 和其他*mntent 函数系列。如需进一步参考,请参阅manpage

    取自here 的代码示例并稍作修改。 /etc/mtab 是一个包含已安装文件系统列表的文件。

    mounts = setmntent("/etc/mtab", "r");
    while ( (ent = getmntent(mounts)) != NULL ){
        if (strcmp(ent->mnt_type, "iso9660") == 0)
           /* copy mount point to output */
           strcpy(retval[cd_count - 1], ent->mnt_dir);
        } /* if */
    } /* while */
    endmntent(mounts);
    

    不幸的是,这些函数不在 POSIX 中。但是它们是在 glibc 中进行联机和实现的,所以我认为它们是比解析 /proc 更好的选择。

    【讨论】:

    • 这为您提供了/etc/fstab 文件中条目中的信息,而不是内核中实际安装的文件系统(如FreeBSD 的getfsstat())FreeBSD 有它,但linux 似乎没有实现它.
    【解决方案2】:

    你可以解析/proc/filesystems

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-10
      • 1970-01-01
      • 2017-04-03
      • 2011-03-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多