blob: 4b63ca52ca3b90a1ef13ee24e040de5c2f0930e4 [file] [log] [blame]
.\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk)
.\"
.\" %%%LICENSE_START(VERBATIM)
.\" Permission is granted to make and distribute verbatim copies of this
.\" manual provided the copyright notice and this permission notice are
.\" preserved on all copies.
.\"
.\" Permission is granted to copy and distribute modified versions of this
.\" manual under the conditions for verbatim copying, provided that the
.\" entire resulting derived work is distributed under the terms of a
.\" permission notice identical to this one.
.\"
.\" Since the Linux kernel and libraries are constantly changing, this
.\" manual page may be incorrect or out-of-date. The author(s) assume no
.\" responsibility for errors or omissions, or for damages resulting from
.\" the use of the information contained herein. The author(s) may not
.\" have taken the same level of care in the production of this manual,
.\" which is licensed free of charge, as they might when working
.\" professionally.
.\"
.\" Formatted or processed versions of this manual, if unaccompanied by
.\" the source, must acknowledge the copyright and authors of this work.
.\" %%%LICENSE_END
.\"
.\" References consulted:
.\" Linux libc source code
.\" Lewine's _POSIX Programmer's Guide_ (O'Reilly & Associates, 1991)
.\" 386BSD man pages
.\" Modified Sat Jul 24 21:46:57 1993 by Rik Faith (faith@cs.unc.edu)
.\" Modified 961109, 031115, aeb
.\"
.TH GETMNTENT 3 2021-03-22 "" "Linux Programmer's Manual"
.SH NAME
getmntent, setmntent, addmntent, endmntent, hasmntopt,
getmntent_r \- get filesystem descriptor file entry
.SH SYNOPSIS
.nf
.B #include <stdio.h>
.B #include <mntent.h>
.PP
.BI "FILE *setmntent(const char *" filename ", const char *" type );
.PP
.BI "struct mntent *getmntent(FILE *" stream );
.PP
.BI "int addmntent(FILE *restrict " stream ,
.BI " const struct mntent *restrict " mnt );
.PP
.BI "int endmntent(FILE *" streamp );
.PP
.BI "char *hasmntopt(const struct mntent *" mnt ", const char *" opt );
.PP
/* GNU extension */
.B #include <mntent.h>
.PP
.BI "struct mntent *getmntent_r(FILE *restrict " streamp ,
.BI " struct mntent *restrict " mntbuf ,
.BI " char *restrict " buf ", int " buflen );
.fi
.PP
.RS -4
Feature Test Macro Requirements for glibc (see
.BR feature_test_macros (7)):
.RE
.PP
.BR getmntent_r ():
.nf
Since glibc 2.19:
_DEFAULT_SOURCE
Glibc 2.19 and earlier:
_BSD_SOURCE || _SVID_SOURCE
.fi
.SH DESCRIPTION
These routines are used to access the filesystem description file
.I /etc/fstab
and the mounted filesystem description file
.IR /etc/mtab .
.PP
The
.BR setmntent ()
function opens the filesystem description file
.I filename
and returns a file pointer which can be used by
.BR getmntent ().
The argument
.I type
is the type of access
required and can take the same values as the
.I mode
argument of
.BR fopen (3).
The returned stream should be closed using
.BR endmntent ()
rather than
.BR fclose (3).
.PP
The
.BR getmntent ()
function reads the next line of the filesystem
description file from
.I stream
and returns a pointer to a structure
containing the broken out fields from a line in the file.
The pointer
points to a static area of memory which is overwritten by subsequent
calls to
.BR getmntent ().
.PP
The
.BR addmntent ()
function adds the
.I mntent
structure
.I mnt
to
the end of the open
.IR stream .
.PP
The
.BR endmntent ()
function closes the
.IR stream
associated with the filesystem description file.
.PP
The
.BR hasmntopt ()
function scans the
.I mnt_opts
field (see below)
of the
.I mntent
structure
.I mnt
for a substring that matches
.IR opt .
See
.I <mntent.h>
and
.BR mount (8)
for valid mount options.
.PP
The reentrant
.BR getmntent_r ()
function is similar to
.BR getmntent (),
but stores the
.IR "struct mount"
in the provided
.I *mntbuf
and stores the strings pointed to by the entries in that struct
in the provided array
.I buf
of size
.IR buflen .
.PP
The
.I mntent
structure is defined in
.I <mntent.h>
as follows:
.PP
.in +4n
.EX
struct mntent {
char *mnt_fsname; /* name of mounted filesystem */
char *mnt_dir; /* filesystem path prefix */
char *mnt_type; /* mount type (see mntent.h) */
char *mnt_opts; /* mount options (see mntent.h) */
int mnt_freq; /* dump frequency in days */
int mnt_passno; /* pass number on parallel fsck */
};
.EE
.in
.PP
Since fields in the mtab and fstab files are separated by whitespace,
octal escapes are used to represent the characters space (\e040),
tab (\e011), newline (\e012), and backslash (\e\e) in those files
when they occur in one of the four strings in a
.I mntent
structure.
The routines
.BR addmntent ()
and
.BR getmntent ()
will convert
from string representation to escaped representation and back.
When converting from escaped representation, the sequence \e134 is
also converted to a backslash.
.SH RETURN VALUE
The
.BR getmntent ()
and
.BR getmntent_r ()
functions return
a pointer to the
.I mntent
structure or NULL on failure.
.PP
The
.BR addmntent ()
function returns 0 on success and 1 on failure.
.PP
The
.BR endmntent ()
function always returns 1.
.PP
The
.BR hasmntopt ()
function returns the address of the substring if
a match is found and NULL otherwise.
.SH FILES
.TP
.I /etc/fstab
filesystem description file
.TP
.I /etc/mtab
mounted filesystem description file
.SH ATTRIBUTES
For an explanation of the terms used in this section, see
.BR attributes (7).
.ad l
.nh
.TS
allbox;
lb lb lbx
l l l.
Interface Attribute Value
T{
.BR setmntent (),
.BR endmntent (),
.BR hasmntopt ()
T} Thread safety MT-Safe
T{
.BR getmntent ()
T} Thread safety T{
MT-Unsafe race:mntentbuf locale
T}
T{
.BR addmntent ()
T} Thread safety T{
MT-Safe race:stream locale
T}
T{
.BR getmntent_r ()
T} Thread safety MT-Safe locale
.TE
.hy
.ad
.sp 1
.SH CONFORMING TO
The nonreentrant functions are from SunOS 4.1.3.
A routine
.BR getmntent_r ()
was introduced in HP-UX 10, but it returns an
.IR int .
The prototype shown above is glibc-only.
.SH NOTES
System V also has a
.BR getmntent ()
function but the calling sequence
differs, and the returned structure is different.
Under System V
.I /etc/mnttab
is used.
4.4BSD and Digital UNIX have a routine
.BR getmntinfo (),
a wrapper around the system call
.BR getfsstat ().
.SH SEE ALSO
.BR fopen (3),
.BR fstab (5),
.BR mount (8)