man-pages/man3/getmntent.3.html
2021-03-31 01:06:50 +01:00

366 lines
8.1 KiB
HTML

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<HTML><HEAD><TITLE>Man page of GETMNTENT</TITLE>
</HEAD><BODY>
<H1>GETMNTENT</H1>
Section: Linux Programmer's Manual (3)<BR>Updated: 2019-03-06<BR><A HREF="#index">Index</A>
<A HREF="/cgi-bin/man/man2html">Return to Main Contents</A><HR>
<A NAME="lbAB">&nbsp;</A>
<H2>NAME</H2>
getmntent, setmntent, addmntent, endmntent, hasmntopt,
getmntent_r - get filesystem descriptor file entry
<A NAME="lbAC">&nbsp;</A>
<H2>SYNOPSIS</H2>
<PRE>
<B>#include &lt;<A HREF="file:///usr/include/stdio.h">stdio.h</A>&gt;</B>
<B>#include &lt;<A HREF="file:///usr/include/mntent.h">mntent.h</A>&gt;</B>
<B>FILE *setmntent(const char *</B><I>filename</I><B>, const char *</B><I>type</I><B>);</B>
<B>struct mntent *getmntent(FILE *</B><I>stream</I><B>);</B>
<B>int addmntent(FILE *</B><I>stream</I><B>, const struct mntent *</B><I>mnt</I><B>);</B>
<B>int endmntent(FILE *</B><I>streamp</I><B>);</B>
<B>char *hasmntopt(const struct mntent *</B><I>mnt</I><B>, const char *</B><I>opt</I><B>);</B>
/* GNU extension */
<B>#include &lt;<A HREF="file:///usr/include/mntent.h">mntent.h</A>&gt;</B>
<B>struct mntent *getmntent_r(FILE *</B><I>streamp</I><B>, struct mntent *</B><I>mntbuf</I><B>,</B>
<B> char *</B><I>buf</I><B>, int </B><I>buflen</I><B>);</B>
</PRE>
<P>
Feature Test Macro Requirements for glibc (see
<B><A HREF="/cgi-bin/man/man2html?7+feature_test_macros">feature_test_macros</A></B>(7)):
<P>
<B>getmntent_r</B>():
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Since&nbsp;glibc&nbsp;2.19:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_DEFAULT_SOURCE
<BR>&nbsp;&nbsp;&nbsp;&nbsp;Glibc&nbsp;2.19&nbsp;and&nbsp;earlier:
<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;_BSD_SOURCE&nbsp;||&nbsp;_SVID_SOURCE
<A NAME="lbAD">&nbsp;</A>
<H2>DESCRIPTION</H2>
These routines are used to access the filesystem description file
<I>/etc/fstab</I>
and the mounted filesystem description file
<I>/etc/mtab</I>.
<P>
The
<B>setmntent</B>()
function opens the filesystem description file
<I>filename</I>
and returns a file pointer which can be used by
<B>getmntent</B>().
The argument
<I>type</I>
is the type of access
required and can take the same values as the
<I>mode</I>
argument of
<B><A HREF="/cgi-bin/man/man2html?3+fopen">fopen</A></B>(3).
The returned stream should be closed using
<B>endmntent</B>()
rather than
<B><A HREF="/cgi-bin/man/man2html?3+fclose">fclose</A></B>(3).
<P>
The
<B>getmntent</B>()
function reads the next line of the filesystem
description file from
<I>stream</I>
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
<B>getmntent</B>().
<P>
The
<B>addmntent</B>()
function adds the
<I>mntent</I>
structure
<I>mnt</I>
to
the end of the open
<I>stream</I>.
<P>
The
<B>endmntent</B>()
function closes the
<I>stream</I>
associated with the filesystem description file.
<P>
The
<B>hasmntopt</B>()
function scans the
<I>mnt_opts</I>
field (see below)
of the
<I>mntent</I>
structure
<I>mnt</I>
for a substring that matches
<I>opt</I>.
See
<I>&lt;<A HREF="file:///usr/include/mntent.h">mntent.h</A>&gt;</I>
and
<B><A HREF="/cgi-bin/man/man2html?8+mount">mount</A></B>(8)
for valid mount options.
<P>
The reentrant
<B>getmntent_r</B>()
function is similar to
<B>getmntent</B>(),
but stores the
<I>struct mount</I>
in the provided
<I>*mntbuf</I>
and stores the strings pointed to by the entries in that struct
in the provided array
<I>buf</I>
of size
<I>buflen</I>.
<P>
The
<I>mntent</I>
structure is defined in
<I>&lt;<A HREF="file:///usr/include/mntent.h">mntent.h</A>&gt;</I>
as follows:
<P>
struct mntent {
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*mnt_fsname;&nbsp;&nbsp;&nbsp;/*&nbsp;name&nbsp;of&nbsp;mounted&nbsp;filesystem&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*mnt_dir;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;filesystem&nbsp;path&nbsp;prefix&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*mnt_type;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;mount&nbsp;type&nbsp;(see&nbsp;mntent.h)&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;char&nbsp;*mnt_opts;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;mount&nbsp;options&nbsp;(see&nbsp;mntent.h)&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;mnt_freq;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*&nbsp;dump&nbsp;frequency&nbsp;in&nbsp;days&nbsp;*/
<BR>&nbsp;&nbsp;&nbsp;&nbsp;int&nbsp;&nbsp;&nbsp;mnt_passno;&nbsp;&nbsp;&nbsp;/*&nbsp;pass&nbsp;number&nbsp;on&nbsp;parallel&nbsp;fsck&nbsp;*/
};
<P>
Since fields in the mtab and fstab files are separated by whitespace,
octal escapes are used to represent the characters space (\040),
tab (\011), newline (\012), and backslash (\\) in those files
when they occur in one of the four strings in a
<I>mntent</I>
structure.
The routines
<B>addmntent</B>()
and
<B>getmntent</B>()
will convert
from string representation to escaped representation and back.
When converting from escaped representation, the sequence \134 is
also converted to a backslash.
<A NAME="lbAE">&nbsp;</A>
<H2>RETURN VALUE</H2>
The
<B>getmntent</B>()
and
<B>getmntent_r</B>()
functions return
a pointer to the
<I>mntent</I>
structure or NULL on failure.
<P>
The
<B>addmntent</B>()
function returns 0 on success and 1 on failure.
<P>
The
<B>endmntent</B>()
function always returns 1.
<P>
The
<B>hasmntopt</B>()
function returns the address of the substring if
a match is found and NULL otherwise.
<A NAME="lbAF">&nbsp;</A>
<H2>FILES</H2>
<DL COMPACT>
<DT id="1"><I>/etc/fstab</I>
<DD>
filesystem description file
<DT id="2"><I>/etc/mtab</I>
<DD>
mounted filesystem description file
</DL>
<A NAME="lbAG">&nbsp;</A>
<H2>ATTRIBUTES</H2>
For an explanation of the terms used in this section, see
<B><A HREF="/cgi-bin/man/man2html?7+attributes">attributes</A></B>(7).
<TABLE BORDER>
<TR VALIGN=top><TD><B>Interface</B></TD><TD><B>Attribute</B></TD><TD><B>Value</B><BR></TD></TR>
<TR VALIGN=top><TD>
<B>setmntent</B>(),
<B>endmntent</B>(),
<B>hasmntopt</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe<BR></TD></TR>
<TR VALIGN=top><TD>
<B>getmntent</B>()
</TD><TD>Thread safety</TD><TD>MT-Unsafe race:mntentbuf locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>addmntent</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe race:stream locale<BR></TD></TR>
<TR VALIGN=top><TD>
<B>getmntent_r</B>()
</TD><TD>Thread safety</TD><TD>MT-Safe locale<BR></TD></TR>
</TABLE>
<A NAME="lbAH">&nbsp;</A>
<H2>CONFORMING TO</H2>
The nonreentrant functions are from SunOS 4.1.3.
A routine
<B>getmntent_r</B>()
was introduced in HP-UX 10, but it returns an int.
The prototype shown above is glibc-only.
<A NAME="lbAI">&nbsp;</A>
<H2>NOTES</H2>
System V also has a
<B>getmntent</B>()
function but the calling sequence
differs, and the returned structure is different.
Under System V
<I>/etc/mnttab</I>
is used.
4.4BSD and Digital UNIX have a routine
<B>getmntinfo</B>(),
a wrapper around the system call
<B>getfsstat</B>().
<A NAME="lbAJ">&nbsp;</A>
<H2>SEE ALSO</H2>
<B><A HREF="/cgi-bin/man/man2html?3+fopen">fopen</A></B>(3),
<B><A HREF="/cgi-bin/man/man2html?5+fstab">fstab</A></B>(5),
<B><A HREF="/cgi-bin/man/man2html?8+mount">mount</A></B>(8)
<A NAME="lbAK">&nbsp;</A>
<H2>COLOPHON</H2>
This page is part of release 5.05 of the Linux
<I>man-pages</I>
project.
A description of the project,
information about reporting bugs,
and the latest version of this page,
can be found at
<A HREF="https://www.kernel.org/doc/man-pages/.">https://www.kernel.org/doc/man-pages/.</A>
<P>
<HR>
<A NAME="index">&nbsp;</A><H2>Index</H2>
<DL>
<DT id="3"><A HREF="#lbAB">NAME</A><DD>
<DT id="4"><A HREF="#lbAC">SYNOPSIS</A><DD>
<DT id="5"><A HREF="#lbAD">DESCRIPTION</A><DD>
<DT id="6"><A HREF="#lbAE">RETURN VALUE</A><DD>
<DT id="7"><A HREF="#lbAF">FILES</A><DD>
<DT id="8"><A HREF="#lbAG">ATTRIBUTES</A><DD>
<DT id="9"><A HREF="#lbAH">CONFORMING TO</A><DD>
<DT id="10"><A HREF="#lbAI">NOTES</A><DD>
<DT id="11"><A HREF="#lbAJ">SEE ALSO</A><DD>
<DT id="12"><A HREF="#lbAK">COLOPHON</A><DD>
</DL>
<HR>
This document was created by
<A HREF="/cgi-bin/man/man2html">man2html</A>,
using the manual pages.<BR>
Time: 00:05:44 GMT, March 31, 2021
</BODY>
</HTML>