GETMNTENT(3)GETMNTENT(3)NAME
setmntent, getmntent, addmntent, getmntany, endmntent, hasmntopt - get
file system descriptor file entry
SYNOPSIS
#include <stdio.h>
#include <mntent.h>
FILE *setmntent(char *filep, char *type);
struct mntent *getmntent(FILE *filep);
int addmntent(FILE *filep, struct mntent *mnt);
int getmntany (FILE *filep, struct mntent *mp, struct mntent *mpref);
char *hasmntopt(struct mntent *mnt, char *opt);
int endmntent(FILE *filep);
DESCRIPTION
These routines replace the getfsent routines for accessing the file
system description file /etc/fstab. They are also used to access the
mounted file system description file /etc/mtab.
Setmntent opens a file system description file and returns a file pointer
which can then be used with getmntent, addmntent, getmntany, or
endmntent. The type argument is the same as in fopen(3S).
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(4).
struct mntent {
char *mnt_fsname; /* file system name */
char *mnt_dir; /* file system path prefix */
char *mnt_type; /* dbg, efs, nfs */
char *mnt_opts; /* ro, hide, 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.
Addmntent returns 0 if successful, otherwise it returns 1.
Getmntany searches the file referenced by fp until a match is found
between a line in the file and mpref. Mpref matches the line if all
non-null entries in mpref match the corresponding fields in the file.
Note that option string matching is performed by matching the entire
Page 1
GETMNTENT(3)GETMNTENT(3)
option string, not by matching indivudual option substrings. If a match
is found, the matching entry is copied to the area pointed by by mp, and
getmntany returns 0. Otherwise, -1 is returned.
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 and always returns 1.
FILES
/etc/fstab
/etc/mtab
SEE ALSOdelmntent(3), fstab(4)BUGS
The returned mntent structure points to static information that is
overwritten in each call.
Page 2