]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/getmntent.3
crypt.3: srcfix: rewrap source lines
[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 2017-09-15 "" "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 .PP
88 The
89 .BR getmntent ()
90 function reads the next line of the filesystem
91 description file from
92 .I stream
93 and returns a pointer to a structure
94 containing the broken out fields from a line in the file.
95 The pointer
96 points to a static area of memory which is overwritten by subsequent
97 calls to
98 .BR getmntent ().
99 .PP
100 The
101 .BR addmntent ()
102 function adds the
103 .I mntent
104 structure
105 .I mnt
106 to
107 the end of the open
108 .IR stream .
109 .PP
110 The
111 .BR endmntent ()
112 function closes the
113 .IR stream
114 associated with the filesystem description file.
115 .PP
116 The
117 .BR hasmntopt ()
118 function scans the
119 .I mnt_opts
120 field (see below)
121 of the
122 .I mntent
123 structure
124 .I mnt
125 for a substring that matches
126 .IR opt .
127 See
128 .I <mntent.h>
129 and
130 .BR mount (8)
131 for valid mount options.
132 .PP
133 The reentrant
134 .BR getmntent_r ()
135 function is similar to
136 .BR getmntent (),
137 but stores the
138 .IR "struct mount"
139 in the provided
140 .I *mntbuf
141 and stores the strings pointed to by the entries in that struct
142 in the provided array
143 .I buf
144 of size
145 .IR buflen .
146 .PP
147 The
148 .I mntent
149 structure is defined in
150 .I <mntent.h>
151 as follows:
152 .PP
153 .in +4n
154 .EX
155 struct mntent {
156 char *mnt_fsname; /* name of mounted filesystem */
157 char *mnt_dir; /* filesystem path prefix */
158 char *mnt_type; /* mount type (see mntent.h) */
159 char *mnt_opts; /* mount options (see mntent.h) */
160 int mnt_freq; /* dump frequency in days */
161 int mnt_passno; /* pass number on parallel fsck */
162 };
163 .EE
164 .in
165 .PP
166 Since fields in the mtab and fstab files are separated by whitespace,
167 octal escapes are used to represent the characters space (\e040),
168 tab (\e011), newline (\e012), and backslash (\e\e) in those files
169 when they occur in one of the four strings in a
170 .I mntent
171 structure.
172 The routines
173 .BR addmntent ()
174 and
175 .BR getmntent ()
176 will convert
177 from string representation to escaped representation and back.
178 When converting from escaped representation, the sequence \e134 is
179 also converted to a backslash.
180 .SH RETURN VALUE
181 The
182 .BR getmntent ()
183 and
184 .BR getmntent_r ()
185 functions return
186 a pointer to the
187 .I mntent
188 structure or NULL on failure.
189 .PP
190 The
191 .BR addmntent ()
192 function returns 0 on success and 1 on failure.
193 .PP
194 The
195 .BR endmntent ()
196 function always returns 1.
197 .PP
198 The
199 .BR hasmntopt ()
200 function returns the address of the substring if
201 a match is found and NULL otherwise.
202 .SH FILES
203 .TP
204 .I /etc/fstab
205 filesystem description file
206 .TP
207 .I /etc/mtab
208 mounted filesystem description file
209 .fi
210 .SH ATTRIBUTES
211 For an explanation of the terms used in this section, see
212 .BR attributes (7).
213 .ad l
214 .TS
215 allbox;
216 lbw13 lb lbw31
217 l l l.
218 Interface Attribute Value
219 T{
220 .BR setmntent (),
221 .BR endmntent (),
222 .BR hasmntopt ()
223 T} Thread safety MT-Safe
224 T{
225 .BR getmntent ()
226 T} Thread safety MT-Unsafe race:mntentbuf locale
227 T{
228 .BR addmntent ()
229 T} Thread safety MT-Safe race:stream locale
230 T{
231 .BR getmntent_r ()
232 T} Thread safety MT-Safe locale
233 .TE
234 .ad
235 .SH CONFORMING TO
236 The nonreentrant functions are from SunOS 4.1.3.
237 A routine
238 .BR getmntent_r ()
239 was introduced in HP-UX 10, but it returns an int.
240 The prototype shown above is glibc-only.
241 .SH NOTES
242 System V also has a
243 .BR getmntent ()
244 function but the calling sequence
245 differs, and the returned structure is different.
246 Under System V
247 .I /etc/mnttab
248 is used.
249 4.4BSD and Digital UNIX have a routine
250 .BR getmntinfo (),
251 a wrapper around the system call
252 .BR getfsstat ().
253 .SH SEE ALSO
254 .BR fopen (3),
255 .BR fstab (5),
256 .BR mount (8)