| 1 |
'\" t |
| 2 |
.\" Copyright 1993, David Metcalfe <[email protected]> |
| 3 |
.\" Copyright, the authors of the Linux man-pages project |
| 4 |
.\" |
| 5 |
.\" SPDX-License-Identifier: Linux-man-pages-copyleft |
| 6 |
.\" |
| 7 |
.TH getmntent 3 2026-02-08 "Linux man-pages 6.18" |
| 8 |
.SH NAME |
| 9 |
getmntent, setmntent, addmntent, endmntent, hasmntopt, |
| 10 |
getmntent_r \- get filesystem descriptor file entry |
| 11 |
.SH LIBRARY |
| 12 |
Standard C library |
| 13 |
.RI ( libc ,\~ \-lc ) |
| 14 |
.SH SYNOPSIS |
| 15 |
.nf |
| 16 |
.B #include <stdio.h> |
| 17 |
.B #include <mntent.h> |
| 18 |
.P |
| 19 |
.BI "FILE *setmntent(const char *" path ", const char *" type ); |
| 20 |
.P |
| 21 |
.BI "struct mntent *getmntent(FILE *" stream ); |
| 22 |
.P |
| 23 |
.BI "int addmntent(FILE *restrict " stream , |
| 24 |
.BI " const struct mntent *restrict " mnt ); |
| 25 |
.P |
| 26 |
.BI "int endmntent(FILE *" streamp ); |
| 27 |
.P |
| 28 |
.BI "char *hasmntopt(const struct mntent *" mnt ", const char *" opt ); |
| 29 |
.P |
| 30 |
/* GNU extension */ |
| 31 |
.B #include <mntent.h> |
| 32 |
.P |
| 33 |
.BR "struct mntent *getmntent_r(" "int size;" |
| 34 |
.BI " FILE *restrict " streamp , |
| 35 |
.BI " struct mntent *restrict " mntbuf , |
| 36 |
.BI " char " buf "[restrict " size "], int " size ); |
| 37 |
.fi |
| 38 |
.P |
| 39 |
.RS -4 |
| 40 |
Feature Test Macro Requirements for glibc (see |
| 41 |
.BR feature_test_macros (7)): |
| 42 |
.RE |
| 43 |
.P |
| 44 |
.BR getmntent_r (): |
| 45 |
.nf |
| 46 |
Since glibc 2.19: |
| 47 |
_DEFAULT_SOURCE |
| 48 |
glibc 2.19 and earlier: |
| 49 |
_BSD_SOURCE || _SVID_SOURCE |
| 50 |
.fi |
| 51 |
.SH DESCRIPTION |
| 52 |
These routines are used to access the filesystem description file |
| 53 |
.I /etc/fstab |
| 54 |
and the mounted filesystem description file |
| 55 |
.IR /etc/mtab . |
| 56 |
.P |
| 57 |
The |
| 58 |
.BR setmntent () |
| 59 |
function opens the filesystem description file |
| 60 |
.I path |
| 61 |
and returns a file pointer which can be used by |
| 62 |
.BR getmntent (). |
| 63 |
The argument |
| 64 |
.I type |
| 65 |
is the type of access |
| 66 |
required and can take the same values as the |
| 67 |
.I mode |
| 68 |
argument of |
| 69 |
.BR fopen (3). |
| 70 |
The returned stream should be closed using |
| 71 |
.BR endmntent () |
| 72 |
rather than |
| 73 |
.BR fclose (3). |
| 74 |
.P |
| 75 |
The |
| 76 |
.BR getmntent () |
| 77 |
function reads the next line of the filesystem |
| 78 |
description file from |
| 79 |
.I stream |
| 80 |
and returns a pointer to a structure |
| 81 |
containing the broken out fields from a line in the file. |
| 82 |
The pointer |
| 83 |
points to a static area of memory which is overwritten by subsequent |
| 84 |
calls to |
| 85 |
.BR getmntent (). |
| 86 |
.P |
| 87 |
The |
| 88 |
.BR addmntent () |
| 89 |
function adds the |
| 90 |
.I mntent |
| 91 |
structure |
| 92 |
.I mnt |
| 93 |
to |
| 94 |
the end of the open |
| 95 |
.IR stream . |
| 96 |
.P |
| 97 |
The |
| 98 |
.BR endmntent () |
| 99 |
function closes the |
| 100 |
.I stream |
| 101 |
associated with the filesystem description file. |
| 102 |
.P |
| 103 |
The |
| 104 |
.BR hasmntopt () |
| 105 |
function scans the |
| 106 |
.I mnt_opts |
| 107 |
field (see below) |
| 108 |
of the |
| 109 |
.I mntent |
| 110 |
structure |
| 111 |
.I mnt |
| 112 |
for a substring that matches |
| 113 |
.IR opt . |
| 114 |
See |
| 115 |
.I <mntent.h> |
| 116 |
and |
| 117 |
.BR mount (8) |
| 118 |
for valid mount options. |
| 119 |
.P |
| 120 |
The reentrant |
| 121 |
.BR getmntent_r () |
| 122 |
function is similar to |
| 123 |
.BR getmntent (), |
| 124 |
but stores the |
| 125 |
.I mntent |
| 126 |
structure |
| 127 |
in the provided |
| 128 |
.IR *mntbuf , |
| 129 |
and stores the strings pointed to by the entries in that structure |
| 130 |
in the provided array |
| 131 |
.I buf |
| 132 |
of size |
| 133 |
.IR size . |
| 134 |
.P |
| 135 |
The |
| 136 |
.I mntent |
| 137 |
structure is defined in |
| 138 |
.I <mntent.h> |
| 139 |
as follows: |
| 140 |
.P |
| 141 |
.in +4n |
| 142 |
.EX |
| 143 |
struct mntent { |
| 144 |
char *mnt_fsname; /* name of mounted filesystem */ |
| 145 |
char *mnt_dir; /* filesystem path prefix */ |
| 146 |
char *mnt_type; /* mount type (see mntent.h) */ |
| 147 |
char *mnt_opts; /* mount options (see mntent.h) */ |
| 148 |
int mnt_freq; /* dump frequency in days */ |
| 149 |
int mnt_passno; /* pass number on parallel fsck */ |
| 150 |
}; |
| 151 |
.EE |
| 152 |
.in |
| 153 |
.P |
| 154 |
Since fields in the mtab and fstab files are separated by whitespace, |
| 155 |
octal escapes are used to represent the characters space (\[rs]040), |
| 156 |
tab (\[rs]011), newline (\[rs]012), and backslash (\[rs]\[rs]) in those files |
| 157 |
when they occur in one of the four strings in a |
| 158 |
.I mntent |
| 159 |
structure. |
| 160 |
The routines |
| 161 |
.BR addmntent () |
| 162 |
and |
| 163 |
.BR getmntent () |
| 164 |
will convert |
| 165 |
from string representation to escaped representation and back. |
| 166 |
When converting from escaped representation, the sequence \[rs]134 is |
| 167 |
also converted to a backslash. |
| 168 |
.SH RETURN VALUE |
| 169 |
The |
| 170 |
.BR getmntent () |
| 171 |
and |
| 172 |
.BR getmntent_r () |
| 173 |
functions return |
| 174 |
a pointer to the |
| 175 |
.I mntent |
| 176 |
structure or NULL on failure. |
| 177 |
.P |
| 178 |
The |
| 179 |
.BR addmntent () |
| 180 |
function returns 0 on success and 1 on failure. |
| 181 |
.P |
| 182 |
The |
| 183 |
.BR endmntent () |
| 184 |
function always returns 1. |
| 185 |
.P |
| 186 |
The |
| 187 |
.BR hasmntopt () |
| 188 |
function returns the address of the substring if |
| 189 |
a match is found and NULL otherwise. |
| 190 |
.SH FILES |
| 191 |
.TP |
| 192 |
.I /etc/fstab |
| 193 |
filesystem description file |
| 194 |
.TP |
| 195 |
.I /etc/mtab |
| 196 |
mounted filesystem description file |
| 197 |
.SH ATTRIBUTES |
| 198 |
For an explanation of the terms used in this section, see |
| 199 |
.BR attributes (7). |
| 200 |
.TS |
| 201 |
allbox; |
| 202 |
lb lb lbx |
| 203 |
l l l. |
| 204 |
Interface Attribute Value |
| 205 |
T{ |
| 206 |
.na |
| 207 |
.nh |
| 208 |
.BR setmntent (), |
| 209 |
.BR endmntent (), |
| 210 |
.BR hasmntopt () |
| 211 |
T} Thread safety MT-Safe |
| 212 |
T{ |
| 213 |
.na |
| 214 |
.nh |
| 215 |
.BR getmntent () |
| 216 |
T} Thread safety T{ |
| 217 |
.na |
| 218 |
.nh |
| 219 |
MT-Unsafe race:mntentbuf locale |
| 220 |
T} |
| 221 |
T{ |
| 222 |
.na |
| 223 |
.nh |
| 224 |
.BR addmntent () |
| 225 |
T} Thread safety T{ |
| 226 |
.na |
| 227 |
.nh |
| 228 |
MT-Safe race:stream locale |
| 229 |
T} |
| 230 |
T{ |
| 231 |
.na |
| 232 |
.nh |
| 233 |
.BR getmntent_r () |
| 234 |
T} Thread safety MT-Safe locale |
| 235 |
.TE |
| 236 |
.SH STANDARDS |
| 237 |
None. |
| 238 |
.SH HISTORY |
| 239 |
The nonreentrant functions are from SunOS 4.1.3. |
| 240 |
A routine |
| 241 |
.BR getmntent_r () |
| 242 |
was introduced in HP-UX 10, but it returns an |
| 243 |
.IR int . |
| 244 |
The prototype shown above is glibc-only. |
| 245 |
.P |
| 246 |
System V also has a |
| 247 |
.BR getmntent () |
| 248 |
function but the calling sequence |
| 249 |
differs, and the returned structure is different. |
| 250 |
Under System V |
| 251 |
.I /etc/mnttab |
| 252 |
is used. |
| 253 |
4.4BSD and Digital UNIX have a routine |
| 254 |
.BR \%getmntinfo (), |
| 255 |
a wrapper around the system call |
| 256 |
.BR getfsstat (). |
| 257 |
.SH SEE ALSO |
| 258 |
.BR fopen (3), |
| 259 |
.BR fstab (5), |
| 260 |
.BR mount (8) |