]>
Commit | Line | Data |
---|---|---|
fea681da MK |
1 | .\" Copyright 1993 David Metcalfe (david@prism.demon.co.uk) |
2 | .\" | |
93015253 | 3 | .\" %%%LICENSE_START(VERBATIM) |
fea681da MK |
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. | |
c13182ef | 12 | .\" |
fea681da MK |
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. | |
c13182ef | 20 | .\" |
fea681da MK |
21 | .\" Formatted or processed versions of this manual, if unaccompanied by |
22 | .\" the source, must acknowledge the copyright and authors of this work. | |
4b72fb64 | 23 | .\" %%%LICENSE_END |
fea681da MK |
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 | .\" | |
e8418d6d | 32 | .TH GETMNTENT 3 2009-09-15 "" "Linux Programmer's Manual" |
fea681da MK |
33 | .SH NAME |
34 | getmntent, setmntent, addmntent, endmntent, hasmntopt, | |
35 | getmntent_r \- get file system 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 */ | |
fea681da MK |
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 | |
cc4615cc MK |
57 | .sp |
58 | .in -4n | |
59 | Feature Test Macro Requirements for glibc (see | |
60 | .BR feature_test_macros (7)): | |
61 | .in | |
62 | .sp | |
cd74b428 | 63 | .BR getmntent_r (): |
cc4615cc | 64 | _BSD_SOURCE || _SVID_SOURCE |
fea681da | 65 | .SH DESCRIPTION |
c13182ef | 66 | These routines are used to access the file system description file |
fea681da MK |
67 | \fI/etc/fstab\fP and the mounted file system description file |
68 | \fI/etc/mtab\fP. | |
69 | .PP | |
60a90ecd MK |
70 | The |
71 | .BR setmntent () | |
72 | function opens the file system description file | |
e8418d6d | 73 | \fIfilename\fP and returns a file pointer which can be used by |
60a90ecd | 74 | .BR getmntent (). |
c13182ef MK |
75 | The argument \fItype\fP is the type of access |
76 | required and can take the same values as the \fImode\fP argument of | |
fea681da MK |
77 | .BR fopen (3). |
78 | .PP | |
60a90ecd MK |
79 | The |
80 | .BR getmntent () | |
81 | function reads the next line from the file system | |
fea681da | 82 | description file \fIfp\fP and returns a pointer to a structure |
c13182ef MK |
83 | containing the broken out fields from a line in the file. |
84 | The pointer | |
fea681da | 85 | points to a static area of memory which is overwritten by subsequent |
60a90ecd MK |
86 | calls to |
87 | .BR getmntent (). | |
fea681da | 88 | .PP |
60a90ecd MK |
89 | The |
90 | .BR addmntent () | |
c3022783 MK |
91 | function adds the |
92 | .I mntent | |
93 | structure \fImnt\fP to | |
fea681da MK |
94 | the end of the open file \fIfp\fP. |
95 | .PP | |
60a90ecd MK |
96 | The |
97 | .BR endmntent () | |
98 | function closes the file system description file | |
fea681da MK |
99 | \fIfp\fP. |
100 | .PP | |
60a90ecd MK |
101 | The |
102 | .BR hasmntopt () | |
103 | function scans the \fImnt_opts\fP field (see below) | |
c3022783 MK |
104 | of the |
105 | .I mntent | |
106 | structure \fImnt\fP for a substring that matches \fIopt\fP. | |
fea681da MK |
107 | See \fI<mntent.h>\fP and |
108 | .BR mount (8) | |
109 | for valid mount options. | |
110 | .PP | |
60a90ecd MK |
111 | The reentrant |
112 | .BR getmntent_r () | |
113 | function is similar to | |
114 | .BR getmntent (), | |
0c2ec4f1 | 115 | but stores the \fIstruct mount\fP in the provided |
bd9b2a9c | 116 | .I *mntbuf |
fea681da MK |
117 | and stores the strings pointed to by the entries in that struct |
118 | in the provided array | |
119 | .I buf | |
120 | of size | |
121 | .IR buflen . | |
122 | .PP | |
123 | The \fImntent\fP structure is defined in \fI<mntent.h>\fP as follows: | |
124 | .sp | |
a08ea57c | 125 | .in +4n |
fea681da | 126 | .nf |
fea681da | 127 | struct mntent { |
7295b7ed MK |
128 | char *mnt_fsname; /* name of mounted file system */ |
129 | char *mnt_dir; /* file system path prefix */ | |
130 | char *mnt_type; /* mount type (see mntent.h) */ | |
131 | char *mnt_opts; /* mount options (see mntent.h) */ | |
132 | int mnt_freq; /* dump frequency in days */ | |
133 | int mnt_passno; /* pass number on parallel fsck */ | |
fea681da | 134 | }; |
fea681da | 135 | .fi |
a08ea57c | 136 | .in |
fea681da MK |
137 | |
138 | Since fields in the mtab and fstab files are separated by whitespace, | |
31a6818e MK |
139 | octal escapes are used to represent the four characters space (\e040), |
140 | tab (\e011), newline (\e012) and backslash (\e134) in those files | |
c3022783 MK |
141 | when they occur in one of the four strings in a |
142 | .I mntent | |
143 | structure. | |
60a90ecd MK |
144 | The routines |
145 | .BR addmntent () | |
146 | and | |
147 | .BR getmntent () | |
148 | will convert | |
fea681da | 149 | from string representation to escaped representation and back. |
47297adb | 150 | .SH RETURN VALUE |
60a90ecd MK |
151 | The |
152 | .BR getmntent () | |
153 | and | |
154 | .BR getmntent_r () | |
155 | functions return | |
c3022783 MK |
156 | a pointer to the |
157 | .I mntent | |
158 | structure or NULL on failure. | |
fea681da | 159 | .PP |
60a90ecd MK |
160 | The |
161 | .BR addmntent () | |
162 | function returns 0 on success and 1 on failure. | |
fea681da | 163 | .PP |
60a90ecd MK |
164 | The |
165 | .BR endmntent () | |
166 | function always returns 1. | |
fea681da | 167 | .PP |
60a90ecd MK |
168 | The |
169 | .BR hasmntopt () | |
170 | function returns the address of the substring if | |
fea681da MK |
171 | a match is found and NULL otherwise. |
172 | .SH FILES | |
173 | .nf | |
174 | /etc/fstab file system description file | |
175 | /etc/mtab mounted file system description file | |
176 | .fi | |
47297adb | 177 | .SH CONFORMING TO |
54d75d6c | 178 | The nonreentrant functions are from SunOS 4.1.3. |
fea681da | 179 | A routine |
63aa9df0 | 180 | .BR getmntent_r () |
c13182ef | 181 | was introduced in HP-UX 10, but it returns an int. |
68e1685c | 182 | The prototype shown above is glibc-only. |
fea681da | 183 | .SH NOTES |
60a90ecd MK |
184 | System V also has a |
185 | .BR getmntent () | |
186 | function but the calling sequence | |
c13182ef MK |
187 | differs, and the returned structure is different. |
188 | Under System V | |
fea681da MK |
189 | .I /etc/mnttab |
190 | is used. | |
008f1ecc | 191 | 4.4BSD and Digital UNIX have a routine |
60a90ecd MK |
192 | .BR getmntinfo (), |
193 | a wrapper around the system call | |
194 | .BR getfsstat (). | |
47297adb | 195 | .SH SEE ALSO |
fea681da MK |
196 | .BR fopen (3), |
197 | .BR fstab (5), | |
198 | .BR mount (8) |