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