#include <stdio.h> #include <sys/mnttab.h>
int getmntent(FILE *fp, struct mnttab *mp);
int getmntany(FILE *fp, struct mnttab *mp, struct mnttab *mpref);
char *hasmntopt(struct mnttab *mnt, char *opt);
int putmntent(FILE *iop, struct mnttab *mp);
Safe
getmntent() and getmntany() each fill in the structure pointed to by mp with the broken-out fields of a line in the /etc/mnttab file. Each line in the file contains a mnttab structure, which is declared in the <sys/mnttab.h> header. The structure contains the following members:
char *mnt_special; char *mnt_mountp; char *mnt_fstype; char *mnt_mntopts; char *mnt_time;
The fields have meanings described in mnttab(4) .
getmntent() returns a pointer to the next mnttab structure in the file; so successive calls can be used to search the entire file. 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 these routines do not open, close, or rewind the file.
hasmntopt() scans the mnt_mntopts field of the mnttab structure mnt for a substring that matches opt. It returns the address of the substring if a match is found, otherwise it returns 0.
The putmntent() macro formats the contents of the mnttab structure according to the layout required for the /etc/mnttab file and writes the entry to the file. Note: the file should be opened in append mode ( fopen(3S) with an "a" mode) so that the entry is appended to the file.
If the next entry is successfully read by getmntent() or a match is found with getmntany(), 0 is returned. If an EOF is encountered on reading, these functions return -1. If an error is encountered, a value greater than 0 is returned. The possible error values are:
- MNT_TOOLONG
- A line in the file exceeded the internal buffer size of MNT_LINE_MAX .
- MNT_TOOMANY
- A line in the file contains too many fields.
- MNT_TOOFEW
- A line in the file contains too few fields.
On success, putmntent() returns the number of bytes printed to the specified file and on failure returns EOF .
The members of the mnttab structure point to information contained in a static area, so it must be copied if it is to be saved.