OSDN Git Service

LDP: Update original to LDP v3.79
[linuxjm/LDP_man-pages.git] / original / 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  2015-01-22 "" "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 .sp
41 .BI "FILE *setmntent(const char *" filename ", const char *" type );
42 .sp
43 .BI "struct mntent *getmntent(FILE *" stream );
44 .sp
45 .BI "int addmntent(FILE *" stream ", const struct mntent *" mnt );
46 .sp
47 .BI "int endmntent(FILE *" streamp );
48 .sp
49 .BI "char *hasmntopt(const struct mntent *" mnt ", const char *" opt );
50 .sp
51 /* GNU extension */
52 .B #include <mntent.h>
53 .sp
54 .BI "struct mntent *getmntent_r(FILE *" streamp ", struct mntent *" mntbuf ,
55 .BI "                           char *" buf ", int " buflen );
56 .fi
57 .sp
58 .in -4n
59 Feature Test Macro Requirements for glibc (see
60 .BR feature_test_macros (7)):
61 .in
62 .sp
63 .BR getmntent_r ():
64 _BSD_SOURCE || _SVID_SOURCE
65 .SH DESCRIPTION
66 These routines are used to access the filesystem description file
67 .I /etc/fstab
68 and the mounted filesystem description file
69 .IR /etc/mtab .
70 .PP
71 The
72 .BR setmntent ()
73 function opens the filesystem description file
74 .I filename
75 and returns a file pointer which can be used by
76 .BR getmntent ().
77 The argument
78 .I type
79 is the type of access
80 required and can take the same values as the
81 .I mode
82 argument of
83 .BR fopen (3).
84 .PP
85 The
86 .BR getmntent ()
87 function reads the next line of the filesystem
88 description file from
89 .I stream
90 and returns a pointer to a structure
91 containing the broken out fields from a line in the file.
92 The pointer
93 points to a static area of memory which is overwritten by subsequent
94 calls to
95 .BR getmntent ().
96 .PP
97 The
98 .BR addmntent ()
99 function adds the
100 .I mntent
101 structure
102 .I mnt
103 to
104 the end of the open
105 .IR stream .
106 .PP
107 The
108 .BR endmntent ()
109 function closes the
110 .IR stream
111 associated with the filesystem description file.
112 .PP
113 The
114 .BR hasmntopt ()
115 function scans the
116 .I mnt_opts
117 field (see below)
118 of the
119 .I mntent
120 structure
121 .I mnt
122 for a substring that matches
123 .IR opt .
124 See
125 .I <mntent.h>
126 and
127 .BR mount (8)
128 for valid mount options.
129 .PP
130 The reentrant
131 .BR getmntent_r ()
132 function is similar to
133 .BR getmntent (),
134 but stores the
135 .IR "struct mount"
136 in the provided
137 .I *mntbuf
138 and stores the strings pointed to by the entries in that struct
139 in the provided array
140 .I buf
141 of size
142 .IR buflen .
143 .PP
144 The
145 .I mntent
146 structure is defined in
147 .I <mntent.h>
148 as follows:
149 .sp
150 .in +4n
151 .nf
152 struct mntent {
153     char *mnt_fsname;   /* name of mounted filesystem */
154     char *mnt_dir;      /* filesystem path prefix */
155     char *mnt_type;     /* mount type (see mntent.h) */
156     char *mnt_opts;     /* mount options (see mntent.h) */
157     int   mnt_freq;     /* dump frequency in days */
158     int   mnt_passno;   /* pass number on parallel fsck */
159 };
160 .fi
161 .in
162
163 Since fields in the mtab and fstab files are separated by whitespace,
164 octal escapes are used to represent the four characters space (\e040),
165 tab (\e011), newline (\e012) and backslash (\e134) in those files
166 when they occur in one of the four strings in a
167 .I mntent
168 structure.
169 The routines
170 .BR addmntent ()
171 and
172 .BR getmntent ()
173 will convert
174 from string representation to escaped representation and back.
175 .SH RETURN VALUE
176 The
177 .BR getmntent ()
178 and
179 .BR getmntent_r ()
180 functions return
181 a pointer to the
182 .I mntent
183 structure or NULL on failure.
184 .PP
185 The
186 .BR addmntent ()
187 function returns 0 on success and 1 on failure.
188 .PP
189 The
190 .BR endmntent ()
191 function always returns 1.
192 .PP
193 The
194 .BR hasmntopt ()
195 function returns the address of the substring if
196 a match is found and NULL otherwise.
197 .SH FILES
198 .nf
199 /etc/fstab          filesystem description file
200 /etc/mtab           mounted filesystem description file
201 .fi
202 .SH CONFORMING TO
203 The nonreentrant functions are from SunOS 4.1.3.
204 A routine
205 .BR getmntent_r ()
206 was introduced in HP-UX 10, but it returns an int.
207 The prototype shown above is glibc-only.
208 .SH NOTES
209 System V also has a
210 .BR getmntent ()
211 function but the calling sequence
212 differs, and the returned structure is different.
213 Under System V
214 .I /etc/mnttab
215 is used.
216 4.4BSD and Digital UNIX have a routine
217 .BR getmntinfo (),
218 a wrapper around the system call
219 .BR getfsstat ().
220 .SH SEE ALSO
221 .BR fopen (3),
222 .BR fstab (5),
223 .BR mount (8)
224 .SH COLOPHON
225 This page is part of release 3.79 of the Linux
226 .I man-pages
227 project.
228 A description of the project,
229 information about reporting bugs,
230 and the latest version of this page,
231 can be found at
232 \%http://www.kernel.org/doc/man\-pages/.