Debian Codegraph @

upstream/debian-trixie/man3/getmntent.3

raw
1 '\" t
2 .\" Copyright 1993 David Metcalfe ([email protected])
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 ([email protected])
11 .\" Modified 961109, 031115, aeb
12 .\"
13 .TH getmntent 3 2024-06-15 "Linux man-pages 6.9.1"
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>
24 .P
25 .BI "FILE *setmntent(const char *" filename ", const char *" type );
26 .P
27 .BI "struct mntent *getmntent(FILE *" stream );
28 .P
29 .BI "int addmntent(FILE *restrict " stream ,
30 .BI " const struct mntent *restrict " mnt );
31 .P
32 .BI "int endmntent(FILE *" streamp );
33 .P
34 .BI "char *hasmntopt(const struct mntent *" mnt ", const char *" opt );
35 .P
36 /* GNU extension */
37 .B #include <mntent.h>
38 .P
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
43 .P
44 .RS -4
45 Feature Test Macro Requirements for glibc (see
46 .BR feature_test_macros (7)):
47 .RE
48 .P
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 .
61 .P
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).
79 .P
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 ().
91 .P
92 The
93 .BR addmntent ()
94 function adds the
95 .I mntent
96 structure
97 .I mnt
98 to
99 the end of the open
100 .IR stream .
101 .P
102 The
103 .BR endmntent ()
104 function closes the
105 .I stream
106 associated with the filesystem description file.
107 .P
108 The
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 .
119 See
120 .I <mntent.h>
121 and
122 .BR mount (8)
123 for valid mount options.
124 .P
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 .
139 .P
140 The
141 .I mntent
142 structure is defined in
143 .I <mntent.h>
144 as follows:
145 .P
146 .in +4n
147 .EX
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 */
155 };
156 .EE
157 .in
158 .P
159 Since fields in the mtab and fstab files are separated by whitespace,
160 octal escapes are used to represent the characters space (\[rs]040),
161 tab (\[rs]011), newline (\[rs]012), and backslash (\[rs]\[rs]) 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 ()
167 and
168 .BR getmntent ()
169 will convert
170 from string representation to escaped representation and back.
171 When converting from escaped representation, the sequence \[rs]134 is
172 also converted to a backslash.
173 .SH RETURN VALUE
174 The
175 .BR getmntent ()
176 and
177 .BR getmntent_r ()
178 functions return
179 a pointer to the
180 .I mntent
181 structure or NULL on failure.
182 .P
183 The
184 .BR addmntent ()
185 function returns 0 on success and 1 on failure.
186 .P
187 The
188 .BR endmntent ()
189 function always returns 1.
190 .P
191 The
192 .BR hasmntopt ()
193 function returns the address of the substring if
194 a match is found and NULL otherwise.
195 .SH FILES
196 .TP
197 .I /etc/fstab
198 filesystem description file
199 .TP
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).
205 .TS
206 allbox;
207 lb lb lbx
208 l l l.
209 Interface Attribute Value
210 T{
211 .na
212 .nh
213 .BR setmntent (),
214 .BR endmntent (),
215 .BR hasmntopt ()
216 T} Thread safety MT-Safe
217 T{
218 .na
219 .nh
220 .BR getmntent ()
221 T} Thread safety T{
222 .na
223 .nh
224 MT-Unsafe race:mntentbuf locale
225 T}
226 T{
227 .na
228 .nh
229 .BR addmntent ()
230 T} Thread safety T{
231 .na
232 .nh
233 MT-Safe race:stream locale
234 T}
235 T{
236 .na
237 .nh
238 .BR getmntent_r ()
239 T} Thread safety MT-Safe locale
240 .TE
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.
250 .P
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)