1
我正在使用statvfs來收集特定文件的信息。我想獲得磁盤名稱/分區(如/dev/sdb1
,/dev/media
等)。但是statvfs
結構似乎不提供這樣的數據。我在哪裏可以找到它?如何使用statvfs查找磁盤名稱?
我正在使用statvfs來收集特定文件的信息。我想獲得磁盤名稱/分區(如/dev/sdb1
,/dev/media
等)。但是statvfs
結構似乎不提供這樣的數據。我在哪裏可以找到它?如何使用statvfs查找磁盤名稱?
使用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);
給定一個文件名,你就必須做一些編碼的文件名匹配的文件系統安裝點。最簡單的方法可能是通過對由getmntent()
返回struct mntent
文件系統的安裝點調用statvfs()
從struct statvfs
的f_fsid
場從文件裝載的文件系統中獲得的f_fsid
匹配。