getmntent(3X)getmntent(3X)NAMEgetmntent(), getmntent_r(), setmntent(), addmntent(), delmntent(),
endmntent(), hasmntopt() - get file system descriptor file entry
SYNOPSISDESCRIPTION
These routines replace the obsolete routines (see getfsent(3X)) for
accessing the file system description file They are also used to access
the mounted file system description file
Opens a file system description file and returns
a file pointer which can then be used with or The
type argument is the same as in
Reads the next line from
stream and returns a pointer to an object with the
following structure containing the broken-out
fields of a line in the file-system description
file, The fields have meanings described in
fstab(4).
Uses three extra parameters to provide results equivalent to those
produced by The extra parameters are:
1. The address of a where the result will be stored.
2. A buffer to store character strings to which fields in the
will point.
3. The length of the user-supplied buffer. A buffer length of
1025 is recommended.
Adds the
structure mnt to the end of the open file stream. Note that
stream must be opened for writing. Upon return from the call to
the file position indicator for the stream will point to EOF.
Deletes all entries from the file
stream opened with that match both mnt_fsname and mnt_dir in
structure mnt. If mnt_fsname is a null pointer, all entries
that match mnt_dir will be deleted. If mnt_dir is a null
pointer, all entries that match mnt_fsname will be deleted. It
is an error if both mnt_fsname and mnt_dir are null pointers.
Note that stream must be opened via for reading and writing (r+
or a+). Upon return from the call to the file position indica‐
tor for the stream will point to EOF.
Scans the
field of the structure mnt for a substring that matches opt. It
returns the address of the substring if a match is found. Oth‐
erwise, the return value takes one of the following default
behaviors:
Option String Corresponding Default Behavior
If the does not have the option, is returned. Otherwise, NULL
is returned.
If the does not have the option, is returned. Otherwise, NULL
is returned.
If the does not have the or option, is returned. Otherwise,
NULL is returned.
If the does not have the option and is is returned. Otherwise,
NULL is returned.
If the does not have the option and is is returned. Otherwise,
NULL is returned.
If the does not have the option and is is returned. Otherwise,
NULL is returned.
If the does not have the option and is is returned. Otherwise,
NULL is returned.
If none of the default behaviors occur, NULL is returned.
Note: When the return value is the result of one of the default
behaviors, it is a pseudo option string, and not a pointer in
the field.
Closes the file.
The following definitions are provided in
The following definition is provided for device swap in
The following definitions are provided for file system swap in
NETWORKING FEATURES
NFS
The following definitions are provided in
RETURN VALUE
Returns a null pointer on error.
attempts to establish an exclusive write lock on
the file it is opening; that is, when one of the
following types is passed to to open the file for
write/update: "w", "a", "r+", "w+", or "a+". If
cannot get the lock, it returns a null pointer and
sets errno to either or See below for more informa‐
tion about
Returns a null pointer on error or EOF. Otherwise,
returns a pointer to a structure. Some of the
fields comprising a structure are optional in and
In the supplied structure, such missing character
pointer fields are set to NULL and missing integer
fields are set to −1 for and If the integer field
for is missing, it is set to
Returns a on error or EOF, or if the supplied buffer is of
insufficient length. If the operation is success‐
ful, is returned.
Returns on error.
Returns on error. Sets errno to if stream or mnt are null
pointers, or if both mnt_fsname and mnt_dir in
structure mnt are null pointers. Sets errno to if
stream has been opened for read (r), append (a) or
write (w). If the operation is successful, returns
the number of entries deleted from the file. When
no entries are matched, returns and does not set
errno.
Returns and unlocks the file if it was locked by
EXAMPLES
The following code deletes an entry:
struct mntent mnt_entry;
FILE *fp;
int retval = NOT_DELETED;
mnt_entry.mnt_fsname = "/dev/vg00/lvol7";
mnt_entry.mnt_dir = "/disk7";
if ((fp = setmntent(MNT_MNTTAB, "r+")) != NULL) {
if (delmntent(fp, &mnt_entry) > 0)
retval = DELETED;
(void)endmntent(fp);
}
return(retval);
APPLICATION USAGE
Data integrity is not guaranteed when reading the data because does not
lock the file when opening it with read-only permission. To overcome
this, as one approach, programs may need to loop until the last modifi‐
cation time and file size before and after reading the file are the
same.
The following code achieves the data integrity.
struct stat statbuf;
FILE *fp;
time_t orig_mtime;
off_t orig_size;
int read_status = FALSE;
int retry;
for (retry = 0; retry < NO_OF_RETRIES; retry++){
/*
* If file is empty, do not bother reading it.
* Sleep and then retry the stat().
*/
if (stat(MNT_MNTTAB, &statbuf) != 0){
return (STAT_FAILED);
}
if (statbuf.st_size == 0){
sleep(1);
if (stat(MNT_MNTTAB, &statbuf) != 0){
return(STAT_FAILED);
}
else{
if (statbuf.st_size == 0){
continue;
}
}
}
if ((fp = setmntent(MNT_MNTTAB, "r")) == NULL){
return (SETMNTENT_FAILED);
}
/*
* operation on MNT_MNTTAB goes here...
*/
orig_mtime = statbuf.st_mtime;
orig_size = statbuf.st_size;
if (stat(MNT_MNTTAB, &statbuf) != 0){
return (STAT_FAILED);
}
if ((statbuf.st_mtime == orig_mtime) && (statbuf.st_size == orig_size)){
read_status = TRUE;
break;
}
}
Programs should expect that the file accessed by these APIs may be
write locked by another process because attempts to establish an exclu‐
sive write lock when opening it for write/update.
Use of a text editor to manipulate the file accessed by these APIs is
not supported. and are safe for per process locking. and are not safe
to be called by a child process after but before
AUTHOR
and were developed by The University of California, Berkeley, Sun
Microsystems, Inc., and HP. was developed by HP.
FILESSEE ALSOgetfsent(3X), fstab(4), mnttab(4), thread_safety(5).
getmntent(3X)