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