1GETMNTENT(3) Linux Programmer's Manual GETMNTENT(3)
2
3
4
6 getmntent, setmntent, addmntent, endmntent, hasmntopt, getmntent_r -
7 get filesystem descriptor file entry
8
10 #include <stdio.h>
11 #include <mntent.h>
12
13 FILE *setmntent(const char *filename, const char *type);
14
15 struct mntent *getmntent(FILE *stream);
16
17 int addmntent(FILE *stream, const struct mntent *mnt);
18
19 int endmntent(FILE *streamp);
20
21 char *hasmntopt(const struct mntent *mnt, const char *opt);
22
23 /* GNU extension */
24 #include <mntent.h>
25
26 struct mntent *getmntent_r(FILE *streamp, struct mntent *mntbuf,
27 char *buf, int buflen);
28
29 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
30
31 getmntent_r():
32 Since glibc 2.19:
33 _DEFAULT_SOURCE
34 Glibc 2.19 and earlier:
35 _BSD_SOURCE || _SVID_SOURCE
36
38 These routines are used to access the filesystem description file
39 /etc/fstab and the mounted filesystem description file /etc/mtab.
40
41 The setmntent() function opens the filesystem description file filename
42 and returns a file pointer which can be used by getmntent(). The argu‐
43 ment type is the type of access required and can take the same values
44 as the mode argument of fopen(3).
45
46 The getmntent() function reads the next line of the filesystem descrip‐
47 tion file from stream and returns a pointer to a structure containing
48 the broken out fields from a line in the file. The pointer points to a
49 static area of memory which is overwritten by subsequent calls to getm‐
50 ntent().
51
52 The addmntent() function adds the mntent structure mnt to the end of
53 the open stream.
54
55 The endmntent() function closes the stream associated with the filesys‐
56 tem description file.
57
58 The hasmntopt() function scans the mnt_opts field (see below) of the
59 mntent structure mnt for a substring that matches opt. See <mntent.h>
60 and mount(8) for valid mount options.
61
62 The reentrant getmntent_r() function is similar to getmntent(), but
63 stores the struct mount in the provided *mntbuf and stores the strings
64 pointed to by the entries in that struct in the provided array buf of
65 size buflen.
66
67 The mntent structure is defined in <mntent.h> as follows:
68
69 struct mntent {
70 char *mnt_fsname; /* name of mounted filesystem */
71 char *mnt_dir; /* filesystem path prefix */
72 char *mnt_type; /* mount type (see mntent.h) */
73 char *mnt_opts; /* mount options (see mntent.h) */
74 int mnt_freq; /* dump frequency in days */
75 int mnt_passno; /* pass number on parallel fsck */
76 };
77
78 Since fields in the mtab and fstab files are separated by whitespace,
79 octal escapes are used to represent the characters space (\040), tab
80 (\011), newline (\012), and backslash (\\) in those files when they
81 occur in one of the four strings in a mntent structure. The routines
82 addmntent() and getmntent() will convert from string representation to
83 escaped representation and back. When converting from escaped repre‐
84 sentation, the sequence \134 is also converted to a backslash.
85
87 The getmntent() and getmntent_r() functions return a pointer to the
88 mntent structure or NULL on failure.
89
90 The addmntent() function returns 0 on success and 1 on failure.
91
92 The endmntent() function always returns 1.
93
94 The hasmntopt() function returns the address of the substring if a
95 match is found and NULL otherwise.
96
98 /etc/fstab
99 filesystem description file
100
101 /etc/mtab
102 mounted filesystem description file
103
105 For an explanation of the terms used in this section, see
106 attributes(7).
107
108 ┌──────────────┬───────────────┬─────────────────────────────────┐
109 │Interface │ Attribute │ Value │
110 ├──────────────┼───────────────┼─────────────────────────────────┤
111 │setmntent(), │ Thread safety │ MT-Safe │
112 │endmntent(), │ │ │
113 │hasmntopt() │ │ │
114 ├──────────────┼───────────────┼─────────────────────────────────┤
115 │getmntent() │ Thread safety │ MT-Unsafe race:mntentbuf locale │
116 ├──────────────┼───────────────┼─────────────────────────────────┤
117 │addmntent() │ Thread safety │ MT-Safe race:stream locale │
118 ├──────────────┼───────────────┼─────────────────────────────────┤
119 │getmntent_r() │ Thread safety │ MT-Safe locale │
120 └──────────────┴───────────────┴─────────────────────────────────┘
122 The nonreentrant functions are from SunOS 4.1.3. A routine getmn‐
123 tent_r() was introduced in HP-UX 10, but it returns an int. The proto‐
124 type shown above is glibc-only.
125
127 System V also has a getmntent() function but the calling sequence dif‐
128 fers, and the returned structure is different. Under System V
129 /etc/mnttab is used. 4.4BSD and Digital UNIX have a routine getm‐
130 ntinfo(), a wrapper around the system call getfsstat().
131
133 fopen(3), fstab(5), mount(8)
134
136 This page is part of release 4.16 of the Linux man-pages project. A
137 description of the project, information about reporting bugs, and the
138 latest version of this page, can be found at
139 https://www.kernel.org/doc/man-pages/.
140
141
142
143 2017-09-15 GETMNTENT(3)