【发布时间】:2017-09-16 19:46:03
【问题描述】:
我正在使用statvfs 收集有关特定文件的信息。我也想获取磁盘名称/分区(如/dev/sdb1、/dev/media 等)。但是 statvfs 结构似乎没有提供这样的数据。我在哪里可以找到它?
【问题讨论】:
标签: linux filesystems posix system-calls
我正在使用statvfs 收集有关特定文件的信息。我也想获取磁盘名称/分区(如/dev/sdb1、/dev/media 等)。但是 statvfs 结构似乎没有提供这样的数据。我在哪里可以找到它?
【问题讨论】:
标签: linux filesystems posix system-calls
使用getmntent():
概要
#include <stdio.h> #include <mntent.h> FILE *setmntent(const char *filename, const char *type); struct mntent *getmntent(FILE *stream); int addmntent(FILE *stream, const struct mntent *mnt); int endmntent(FILE *streamp); char *hasmntopt(const struct mntent *mnt, const char *opt);...
描述
...
mntent结构定义如下:
struct mntent { char *mnt_fsname; /* name of mounted filesystem */ char *mnt_dir; /* filesystem path prefix */ char *mnt_type; /* mount type (see mntent.h) */ char *mnt_opts; /* mount options (see mntent.h) */ int mnt_freq; /* dump frequency in days */ int mnt_passno; /* pass number on parallel fsck */ };
例如:
FILE *fp = setmntent( "/etc/mtab", "r" );
for ( ;; )
{
struct mntent *me = getmntent( fp );
if ( NULL == me )
{
break;
}
...
}
endmntent( fp );
给定文件名,您必须进行一些编码以将文件名与文件系统挂载点匹配。最简单的方法可能是将文件中的struct statvfs中的f_fsid字段与通过在文件系统的挂载点上调用statvfs()从@987654331返回的struct mntent获取的挂载文件系统的f_fsid进行匹配@。
【讨论】: