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