1getmntent(3C) Standard C Library Functions getmntent(3C)
2
3
4
6 getmntent, getmntany, getextmntent, hasmntopt, putmntent, resetmnttab -
7 get mounted device information
8
10 #include <stdio.h>
11 #include <sys/mnttab.h>
12
13 int getmntent(FILE *fp, struct mnttab *mp);
14
15
16 int getmntany(FILE *fp, struct mnttab *mp, struct mnttab *mpref);
17
18
19 int getextmntent(FILE *fp, struct extmnttab *mp, int len);
20
21
22 char *hasmntopt(struct mnttab *mnt, char *opt);
23
24
25 int putmntent(FILE *iop, struct mnttab *mp);
26
27
28 void resetmnttab(FILE *fp);
29
30
32 getmntent() and getmntany()
33 The getmntent() and getmntany() functions each fill in the structure
34 pointed to by mp with the broken-out fields of a line in the mnttab
35 file. Each line read from the file contains a mnttab structure, which
36 is defined in the <sys/mnttab.h> header. The structure contains the
37 following members, which correspond to the broken-out fields from a
38 line in /etc/mnttab (see mnttab(4)).
39
40 char *mnt_special; /* name of mounted resource */
41 char *mnt_mountp; /* mount point */
42 char *mnt_fstype; /* type of file system mounted */
43 char *mnt_mntopts; /* options for this mount */
44 char *mnt_time; /* time file system mounted */
45
46
47
48 Fields with no actual content in /etc/mnttab are represented in the
49 file as "-". To clearly distinguish empty fields, getmntent() set the
50 corresponding field in mp to NULL.
51
52
53 Each getmntent() call causes a new line to be read from the mnttab
54 file. Successive calls can be used to search the entire list. The getm‐
55 ntany() function searches the file referenced by fp until a match is
56 found between a line in the file and mpref. A match occurs if all non-
57 null entries in mpref match the corresponding fields in the file. These
58 functions do not open, close, or rewind the file.
59
60 getextmntent()
61 The getextmntent() function is an extended version of the getmntent()
62 function that returns, in addition to the information that getmntent()
63 returns, the major and minor number of the mounted resource to which
64 the line in mnttab corresponds. The getextmntent() function also fills
65 in the extmntent structure defined in the <sys/mnttab.h> header. For
66 getextmntent() to function properly, it must be notified when the mnt‐
67 tab file has been reopened or rewound since a previous getextmntent()
68 call. This notification is accomplished by calling resetmnttab(). Oth‐
69 erwise, it behaves exactly as getmntent() described above
70
71
72 The data pointed to by the mnttab structure members are stored in a
73 static area and must be copied to be saved between successive calls.
74
75 hasmntopt()
76 The hasmntopt() function scans the mnt_mntopts member of the mnttab
77 structure mnt for a substring that matches opt. It returns the address
78 of the substring if a match is found; otherwise it returns 0. Sub‐
79 strings are delimited by commas and the end of the mnt_mntopts string.
80
81 putmntent()
82 The putmntent() function is obsolete and no longer has any effect.
83 Entries appear in mnttab as a side effect of a mount(2) call. The func‐
84 tion name is still defined for transition purposes.
85
86 resetmnttab()
87 The resetmnttab() function notifies getextmntent() to reload from the
88 kernel the device information that corresponds to the new snapshot of
89 the mnttab information (see mnttab(4)). Subsequent getextmntent() calls
90 then return correct extmnttab information. This function should be
91 called whenever the mnttab file is either rewound or closed and
92 reopened before any calls are made to getextmntent().
93
95 getmntent() and getmntany()
96 If the next entry is successfully read by getmntent() or a match is
97 found with getmntany(), 0 is returned. If an EOF is encountered on
98 reading, these functions return −1. If an error is encountered, a value
99 greater than 0 is returned. The following error values are defined in
100 <sys/mnttab.h>:
101
102 MNT_TOOLONG A line in the file exceeded the internal buffer size of
103 MNT_LINE_MAX.
104
105
106 MNT_TOOMANY A line in the file contains too many fields.
107
108
109 MNT_TOOFEW A line in the file contains too few fields.
110
111
112 hasmntopt()
113 Upon successful completion, hasmntopt() returns the address of the sub‐
114 string if a match is found. Otherwise, it returns 0.
115
116 putmntent()
117 The putmntent() is obsolete and always returns −1.
118
120 See attributes(5) for descriptions of the following attributes:
121
122
123
124
125 ┌─────────────────────────────┬─────────────────────────────┐
126 │ ATTRIBUTE TYPE │ ATTRIBUTE VALUE │
127 ├─────────────────────────────┼─────────────────────────────┤
128 │MT-Level │Safe │
129 └─────────────────────────────┴─────────────────────────────┘
130
132 mount(2), mnttab(4), attributes(5)
133
134
135
136SunOS 5.11 22 Mar 2004 getmntent(3C)