]> git.ipfire.org Git - thirdparty/man-pages.git/blob - man3/getmntent.3
Many pages: Use correct letter case in page titles (TH)
[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 (date) "Linux man-pages (unreleased)"
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 .I 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 .I mntent
130 structure
131 in the provided
132 .IR *mntbuf ,
133 and stores the strings pointed to by the entries in that structure
134 in the provided array
135 .I buf
136 of size
137 .IR buflen .
138 .PP
139 The
140 .I mntent
141 structure is defined in
142 .I <mntent.h>
143 as follows:
144 .PP
145 .in +4n
146 .EX
147 struct mntent {
148 char *mnt_fsname; /* name of mounted filesystem */
149 char *mnt_dir; /* filesystem path prefix */
150 char *mnt_type; /* mount type (see mntent.h) */
151 char *mnt_opts; /* mount options (see mntent.h) */
152 int mnt_freq; /* dump frequency in days */
153 int mnt_passno; /* pass number on parallel fsck */
154 };
155 .EE
156 .in
157 .PP
158 Since fields in the mtab and fstab files are separated by whitespace,
159 octal escapes are used to represent the characters space (\e040),
160 tab (\e011), newline (\e012), and backslash (\e\e) in those files
161 when they occur in one of the four strings in a
162 .I mntent
163 structure.
164 The routines
165 .BR addmntent ()
166 and
167 .BR getmntent ()
168 will convert
169 from string representation to escaped representation and back.
170 When converting from escaped representation, the sequence \e134 is
171 also converted to a backslash.
172 .SH RETURN VALUE
173 The
174 .BR getmntent ()
175 and
176 .BR getmntent_r ()
177 functions return
178 a pointer to the
179 .I mntent
180 structure or NULL on failure.
181 .PP
182 The
183 .BR addmntent ()
184 function returns 0 on success and 1 on failure.
185 .PP
186 The
187 .BR endmntent ()
188 function always returns 1.
189 .PP
190 The
191 .BR hasmntopt ()
192 function returns the address of the substring if
193 a match is found and NULL otherwise.
194 .SH FILES
195 .TP
196 .I /etc/fstab
197 filesystem description file
198 .TP
199 .I /etc/mtab
200 mounted filesystem description file
201 .SH ATTRIBUTES
202 For an explanation of the terms used in this section, see
203 .BR attributes (7).
204 .ad l
205 .nh
206 .TS
207 allbox;
208 lb lb lbx
209 l l l.
210 Interface Attribute Value
211 T{
212 .BR setmntent (),
213 .BR endmntent (),
214 .BR hasmntopt ()
215 T} Thread safety MT-Safe
216 T{
217 .BR getmntent ()
218 T} Thread safety T{
219 MT-Unsafe race:mntentbuf locale
220 T}
221 T{
222 .BR addmntent ()
223 T} Thread safety T{
224 MT-Safe race:stream locale
225 T}
226 T{
227 .BR getmntent_r ()
228 T} Thread safety MT-Safe locale
229 .TE
230 .hy
231 .ad
232 .sp 1
233 .SH STANDARDS
234 The nonreentrant functions are from SunOS 4.1.3.
235 A routine
236 .BR getmntent_r ()
237 was introduced in HP-UX 10, but it returns an
238 .IR int .
239 The prototype shown above is glibc-only.
240 .SH NOTES
241 System V also has a
242 .BR getmntent ()
243 function but the calling sequence
244 differs, and the returned structure is different.
245 Under System V
246 .I /etc/mnttab
247 is used.
248 4.4BSD and Digital UNIX have a routine
249 .BR getmntinfo (),
250 a wrapper around the system call
251 .BR getfsstat ().
252 .SH SEE ALSO
253 .BR fopen (3),
254 .BR fstab (5),
255 .BR mount (8)