#include <stdio.h> #include <mntent.h> FILE *setmntent(filep, type) char *filep; char *type; struct mntent *getmntent(filep) FILE *filep; int addmntent(filep, mnt) FILE *filep; struct mntent *mnt; char *hasmntopt(mnt, opt) struct mntent *mnt; char *opt; int endmntent(filep) FILE *filep;
Setmntent opens a file system description file and returns a file pointer which can then be used with getmntent, addmntent, or endmntent. The type argument is the same as in fopen(3). An argument of NULL signifies that the standard filesystem table should be searched. That is, NetInfo is searched if it is running, otherwise /etc/fstab is searched (if NetInfo is running, setmntent(NULL,type) returns -1). Getmntent reads the next line from filep and returns a pointer to an object with the following structure containing the broken-out fields of a line in the filesystem description file, <mntent.h>. The fields have meanings described in fstab(5).
struct mntent { char *mnt_fsname; /* file system name */ char *mnt_dir; /* file system path prefix */ char *mnt_type; /* 4.2, nfs, swap, or xx */ char *mnt_opts; /* ro, quota, etc. */ int mnt_freq; /* dump frequency, in days */ int mnt_passno; /* pass number on parallel fsck */ };
Addmntent adds the mntent structure mnt to the end of the open file filep. Note that filep has to be opened for writing if this is to work. Hasmntopt scans the mnt_opts field of the mntent structure mnt for a substring that matches opt. It returns the address of the substring if a match is found, 0 otherwise. Endmntent closes the file.