Node:mtab, Next:Other Mount Information, Previous:fstab, Up:Mount Information
mtab
fileThe following functions and data structure access the mtab
file.
struct mntent | Data Type |
This structure is used with the getmntent , getmntent_t ,
addmntent , and hasmntopt functions.
|
For accessing the mtab
file there is again a set of three
functions to access all entries in a row. Unlike the functions to
handle fstab
these functions do not access a fixed file and there
is even a thread safe variant of the get function. Beside this the GNU
libc contains functions to alter the file and test for specific options.
FILE * setmntent (const char *file, const char *mode) | Function |
The setmntent function prepares the file named FILE which
must be in the format of a fstab and mtab file for the
upcoming processing through the other functions of the family. The
mode parameter can be chosen in the way the opentype
parameter for fopen (see Opening Streams) can be chosen. If
the file is opened for writing the file is also allowed to be empty.
If the file was successfully opened |
int endmntent (FILE *stream) | Function |
This function takes for the stream parameter a file handle which
previously was returned from the setmntent call.
endmntent closes the stream and frees all resources.
The return value is 1 unless an error occurred in which case it is 0. |
struct mntent * getmntent (FILE *stream) | Function |
The getmntent function takes as the parameter a file handle
previously returned by successful call to setmntent . It returns
a pointer to a static variable of type struct mntent which is
filled with the information from the next entry from the file currently
read.
The file format used prescribes the use of spaces or tab characters to
separate the fields. This makes it harder to use name containing one of
these characters (e.g., mount points using spaces). Therefore these
characters are encoded in the files and the If there was an error or the end of the file is reached the return value
is This function is not thread-safe since all calls to this function return
a pointer to the same static variable. |
struct mntent * getmntent_r (FILE *stream, struct mentent *result, char *buffer, int bufsize) | Function |
The getmntent_r function is the reentrant variant of
getmntent . It also returns the next entry from the file and
returns a pointer. The actual variable the values are stored in is not
static, though. Instead the function stores the values in the variable
pointed to by the result parameter. Additional information (e.g.,
the strings pointed to by the elements of the result) are kept in the
buffer of size bufsize pointed to by buffer.
Escaped characters (space, tab, backslash) are converted back in the
same way as it happens for The function returns a
|
int addmntent (FILE *stream, const struct mntent *mnt) | Function |
The addmntent function allows adding a new entry to the file
previously opened with setmntent . The new entries are always
appended. I.e., even if the position of the file descriptor is not at
the end of the file this function does not overwrite an existing entry
following the current position.
The implication of this is that to remove an entry from a file one has to create a new file while leaving out the entry to be removed and after closing the file remove the old one and rename the new file to the chosen name. This function takes care of spaces and tab characters in the names to be
written to the file. It converts them and the backslash character into
the format describe in the This function returns 0 in case the operation was successful.
Otherwise the return value is 1 and |
char * hasmntopt (const struct mntent *mnt, const char *opt) | Function |
This function can be used to check whether the string pointed to by the
mnt_opts element of the variable pointed to by mnt contains
the option opt. If this is true a pointer to the beginning of the
option in the mnt_opts element is returned. If no such option
exists the function returns NULL .
This function is useful to test whether a specific option is present but
when all options have to be processed one is better off with using the
|