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