Linux 上的 getfsstat() 等效项是什么?

发布于 2024-08-15 20:40:45 字数 54 浏览 3 评论 0原文

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

Question says it all. I want C function call that returns the list the mounted filesystems along with associated information such as filesystem type.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

帝王念 2024-08-22 20:40:45

您正在寻找 getmntent 和其他 *mntent 函数系列。请参阅 联机帮助页 以获取更多参考。

代码示例取自此处并稍加修改。 /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 更好的选择。

You're looking for getmntent and other *mntent functions family. See manpage For further reference.

Code example taken from here and slightly modified. /etc/mtab is a file that contains a list of mounted filesystems.

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);

Unfortunately, these functions are not in POSIX. But they're manpaged and implemented in glibc, so I think they're a better alternative than parsing /proc.

零度℉ 2024-08-22 20:40:45

您可以解析/proc/filesystems

You can parse /proc/filesystems.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文