2017-04-20 19 views

回答

1

使用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 statvfsf_fsid場從文件裝載的文件系統中獲得的f_fsid匹配。