OSDN Git Service

(split) LDP: Update original to LDP v3.65
[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  2009-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 .sp
41 .BI "FILE *setmntent(const char *" filename ", const char *" type );
42 .sp
43 .BI "struct mntent *getmntent(FILE *" fp );
44 .sp
45 .BI "int addmntent(FILE *" fp ", const struct mntent *" mnt );
46 .sp
47 .BI "int endmntent(FILE *" fp );
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 *" fp ", 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 from the filesystem
88 description file
89 .I fp
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 file
105 .IR fp .
106 .PP
107 The
108 .BR endmntent ()
109 function closes the filesystem description file
110 .IR fp .
111 .PP
112 The
113 .BR hasmntopt ()
114 function scans the
115 .I mnt_opts
116 field (see below)
117 of the
118 .I mntent
119 structure
120 .I mnt
121 for a substring that matches
122 .IR opt .
123 See
124 .I <mntent.h>
125 and
126 .BR mount (8)
127 for valid mount options.
128 .PP
129 The reentrant
130 .BR getmntent_r ()
131 function is similar to
132 .BR getmntent (),
133 but stores the
134 .IR "struct mount"
135 in the provided
136 .I *mntbuf
137 and stores the strings pointed to by the entries in that struct
138 in the provided array
139 .I buf
140 of size
141 .IR buflen .
142 .PP
143 The
144 .I mntent
145 structure is defined in
146 .I <mntent.h>
147 as follows:
148 .sp
149 .in +4n
150 .nf
151 struct mntent {
152     char *mnt_fsname;   /* name of mounted filesystem */
153     char *mnt_dir;      /* filesystem path prefix */
154     char *mnt_type;     /* mount type (see mntent.h) */
155     char *mnt_opts;     /* mount options (see mntent.h) */
156     int   mnt_freq;     /* dump frequency in days */
157     int   mnt_passno;   /* pass number on parallel fsck */
158 };
159 .fi
160 .in
161
162 Since fields in the mtab and fstab files are separated by whitespace,
163 octal escapes are used to represent the four characters space (\e040),
164 tab (\e011), newline (\e012) and backslash (\e134) in those files
165 when they occur in one of the four strings in a
166 .I mntent
167 structure.
168 The routines
169 .BR addmntent ()
170 and
171 .BR getmntent ()
172 will convert
173 from string representation to escaped representation and back.
174 .SH RETURN VALUE
175 The
176 .BR getmntent ()
177 and
178 .BR getmntent_r ()
179 functions return
180 a pointer to the
181 .I mntent
182 structure or NULL on failure.
183 .PP
184 The
185 .BR addmntent ()
186 function returns 0 on success and 1 on failure.
187 .PP
188 The
189 .BR endmntent ()
190 function always returns 1.
191 .PP
192 The
193 .BR hasmntopt ()
194 function returns the address of the substring if
195 a match is found and NULL otherwise.
196 .SH FILES
197 .nf
198 /etc/fstab          filesystem description file
199 /etc/mtab           mounted filesystem description file
200 .fi
201 .SH CONFORMING TO
202 The nonreentrant functions are from SunOS 4.1.3.
203 A routine
204 .BR getmntent_r ()
205 was introduced in HP-UX 10, but it returns an int.
206 The prototype shown above is glibc-only.
207 .SH NOTES
208 System V also has a
209 .BR getmntent ()
210 function but the calling sequence
211 differs, and the returned structure is different.
212 Under System V
213 .I /etc/mnttab
214 is used.
215 4.4BSD and Digital UNIX have a routine
216 .BR getmntinfo (),
217 a wrapper around the system call
218 .BR getfsstat ().
219 .SH SEE ALSO
220 .BR fopen (3),
221 .BR fstab (5),
222 .BR mount (8)
223 .SH COLOPHON
224 This page is part of release 3.65 of the Linux
225 .I man-pages
226 project.
227 A description of the project,
228 and information about reporting bugs,
229 can be found at
230 \%http://www.kernel.org/doc/man\-pages/.