1GETMNTENT(3) Linux Programmer's Manual GETMNTENT(3)
2
3
4
6 getmntent, setmntent, addmntent, endmntent, hasmntopt, getmntent_r -
7 get file system 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 *fp);
16
17 int addmntent(FILE *fp, const struct mntent *mnt);
18
19 int endmntent(FILE *fp);
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 *fp, 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(): _BSD_SOURCE || _SVID_SOURCE
32
34 These routines are used to access the file system description file
35 /etc/fstab and the mounted file system description file /etc/mtab.
36
37 The setmntent() function opens the file system description file file‐
38 name and returns a file pointer which can be used by getmntent(). The
39 argument type is the type of access required and can take the same val‐
40 ues as the mode argument of fopen(3).
41
42 The getmntent() function reads the next line from the file system
43 description file fp and returns a pointer to a structure containing the
44 broken out fields from a line in the file. The pointer points to a
45 static area of memory which is overwritten by subsequent calls to getm‐
46 ntent().
47
48 The addmntent() function adds the mntent structure mnt to the end of
49 the open file fp.
50
51 The endmntent() function closes the file system description file fp.
52
53 The hasmntopt() function scans the mnt_opts field (see below) of the
54 mntent structure mnt for a substring that matches opt. See <mntent.h>
55 and mount(8) for valid mount options.
56
57 The reentrant getmntent_r() function is similar to getmntent(), but
58 stores the struct mount in the provided *mntbuf and stores the strings
59 pointed to by the entries in that struct in the provided array buf of
60 size buflen.
61
62 The mntent structure is defined in <mntent.h> as follows:
63
64 struct mntent {
65 char *mnt_fsname; /* name of mounted file system */
66 char *mnt_dir; /* file system path prefix */
67 char *mnt_type; /* mount type (see mntent.h) */
68 char *mnt_opts; /* mount options (see mntent.h) */
69 int mnt_freq; /* dump frequency in days */
70 int mnt_passno; /* pass number on parallel fsck */
71 };
72
73 Since fields in the mtab and fstab files are separated by whitespace,
74 octal escapes are used to represent the four characters space (\040),
75 tab (\011), newline (\012) and backslash (\134) in those files when
76 they occur in one of the four strings in a mntent structure. The rou‐
77 tines addmntent() and getmntent() will convert from string representa‐
78 tion to escaped representation and back.
79
81 The getmntent() and getmntent_r() functions return a pointer to the
82 mntent structure or NULL on failure.
83
84 The addmntent() function returns 0 on success and 1 on failure.
85
86 The endmntent() function always returns 1.
87
88 The hasmntopt() function returns the address of the substring if a
89 match is found and NULL otherwise.
90
92 /etc/fstab file system description file
93 /etc/mtab mounted file system description file
94
96 The nonreentrant functions are from SunOS 4.1.3. A routine getmn‐
97 tent_r() was introduced in HP-UX 10, but it returns an int. The proto‐
98 type shown above is glibc-only.
99
101 System V also has a getmntent() function but the calling sequence dif‐
102 fers, and the returned structure is different. Under System V
103 /etc/mnttab is used. 4.4BSD and Digital Unix have a routine getm‐
104 ntinfo(), a wrapper around the system call getfsstat().
105
107 fopen(3), fstab(5), mount(8)
108
110 This page is part of release 3.25 of the Linux man-pages project. A
111 description of the project, and information about reporting bugs, can
112 be found at http://www.kernel.org/doc/man-pages/.
113
114
115
116 2009-09-15 GETMNTENT(3)