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 #define _GNU_SOURCE /* or _SVID_SOURCE or _BSD_SOURCE */
25 #include <mntent.h>
26
27 struct mntent *getmntent_r(FILE *fp, struct mntent *mntbuf,
28 char *buf, int buflen);
29
31 These routines are used to access the file system description file
32 /etc/fstab and the mounted file system description file /etc/mtab.
33
34 The setmntent() function opens the file system description file fp and
35 returns a file pointer which can be used by getmntent(). The argument
36 type is the type of access required and can take the same values as the
37 mode argument of fopen(3).
38
39 The getmntent() function reads the next line from the file system
40 description file fp and returns a pointer to a structure containing the
41 broken out fields from a line in the file. The pointer points to a
42 static area of memory which is overwritten by subsequent calls to getm‐
43 ntent().
44
45 The addmntent() function adds the mntent structure mnt to the end of
46 the open file fp.
47
48 The endmntent() function closes the file system description file fp.
49
50 The hasmntopt() function scans the mnt_opts field (see below) of the
51 mntent structure mnt for a substring that matches opt. See <mntent.h>
52 and mount(8) for valid mount options.
53
54 The reentrant getmntent_r() function is similar to getmntent(), but
55 stores the struct mount in the provided *mntbuf and stores the strings
56 pointed to by the entries in that struct in the provided array buf of
57 size buflen.
58
59 The mntent structure is defined in <mntent.h> as follows:
60
61 struct mntent {
62 char *mnt_fsname; /* name of mounted file system */
63 char *mnt_dir; /* file system path prefix */
64 char *mnt_type; /* mount type (see mntent.h) */
65 char *mnt_opts; /* mount options (see mntent.h) */
66 int mnt_freq; /* dump frequency in days */
67 int mnt_passno; /* pass number on parallel fsck */
68 };
69
70 Since fields in the mtab and fstab files are separated by whitespace,
71 octal escapes are used to represent the four characters space (\040),
72 tab (\011), newline (\012) and backslash (\134) in those files when
73 they occur in one of the four strings in a mntent structure. The rou‐
74 tines addmntent() and getmntent() will convert from string representa‐
75 tion to escaped representation and back.
76
78 The getmntent() and getmntent_r() functions return a pointer to the
79 mntent structure or NULL on failure.
80
81 The addmntent() function returns 0 on success and 1 on failure.
82
83 The endmntent() function always returns 1.
84
85 The hasmntopt() function returns the address of the substring if a
86 match is found and NULL otherwise.
87
89 /etc/fstab file system description file
90 /etc/mtab mounted file system description file
91
93 The non-reentrant functions are from SunOS 4.1.3. A routine getmn‐
94 tent_r() was introduced in HP-UX 10, but it returns an int. The proto‐
95 type shown above is glibc-only. LSB deprecates the functions endhos‐
96 tent(), sethostent() and setmntent().
97
99 System V also has a getmntent() function but the calling sequence dif‐
100 fers, and the returned structure is different. Under System V /etc/mnt‐
101 tab is used. 4.4BSD and Digital Unix have a routine getmntinfo(), a
102 wrapper around the system call getfsstat().
103
105 fopen(3), fstab(5), feature_test_macros(7), mount(8)
106
107
108
109 2003-11-15 GETMNTENT(3)