1GETMNTENT(3)               Linux Programmer's Manual              GETMNTENT(3)
2
3
4

NAME

6       getmntent,  setmntent,  addmntent,  endmntent, hasmntopt, getmntent_r -
7       get filesystem descriptor file entry
8

SYNOPSIS

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

DESCRIPTION

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).  The returned stream should be closed
45       using endmntent() rather than fclose(3).
46
47       The getmntent() function reads the next line of the filesystem descrip‐
48       tion file from stream and returns a pointer to a  structure  containing
49       the broken out fields from a line in the file.  The pointer points to a
50       static area of memory which is overwritten by subsequent calls to getm‐
51       ntent().
52
53       The  addmntent()  function  adds the mntent structure mnt to the end of
54       the open stream.
55
56       The endmntent() function closes the stream associated with the filesys‐
57       tem description file.
58
59       The  hasmntopt()  function  scans the mnt_opts field (see below) of the
60       mntent structure mnt for a substring that matches opt.  See  <mntent.h>
61       and mount(8) for valid mount options.
62
63       The  reentrant  getmntent_r()  function  is similar to getmntent(), but
64       stores the struct mount in the provided *mntbuf and stores the  strings
65       pointed  to  by the entries in that struct in the provided array buf of
66       size buflen.
67
68       The mntent structure is defined in <mntent.h> as follows:
69
70           struct mntent {
71               char *mnt_fsname;   /* name of mounted filesystem */
72               char *mnt_dir;      /* filesystem path prefix */
73               char *mnt_type;     /* mount type (see mntent.h) */
74               char *mnt_opts;     /* mount options (see mntent.h) */
75               int   mnt_freq;     /* dump frequency in days */
76               int   mnt_passno;   /* pass number on parallel fsck */
77           };
78
79       Since fields in the mtab and fstab files are separated  by  whitespace,
80       octal  escapes  are  used to represent the characters space (\040), tab
81       (\011), newline (\012), and backslash (\\) in  those  files  when  they
82       occur  in  one of the four strings in a mntent structure.  The routines
83       addmntent() and getmntent() will convert from string representation  to
84       escaped  representation  and back.  When converting from escaped repre‐
85       sentation, the sequence \134 is also converted to a backslash.
86

RETURN VALUE

88       The getmntent() and getmntent_r() functions return  a  pointer  to  the
89       mntent structure or NULL on failure.
90
91       The addmntent() function returns 0 on success and 1 on failure.
92
93       The endmntent() function always returns 1.
94
95       The  hasmntopt()  function  returns  the  address of the substring if a
96       match is found and NULL otherwise.
97

FILES

99       /etc/fstab
100              filesystem description file
101
102       /etc/mtab
103              mounted filesystem description file
104

ATTRIBUTES

106       For  an  explanation  of  the  terms  used   in   this   section,   see
107       attributes(7).
108
109       ┌──────────────┬───────────────┬─────────────────────────────────┐
110Interface     Attribute     Value                           
111       ├──────────────┼───────────────┼─────────────────────────────────┤
112setmntent(),  │ Thread safety │ MT-Safe                         │
113endmntent(),  │               │                                 │
114hasmntopt()   │               │                                 │
115       ├──────────────┼───────────────┼─────────────────────────────────┤
116getmntent()   │ Thread safety │ MT-Unsafe race:mntentbuf locale │
117       ├──────────────┼───────────────┼─────────────────────────────────┤
118addmntent()   │ Thread safety │ MT-Safe race:stream locale      │
119       ├──────────────┼───────────────┼─────────────────────────────────┤
120getmntent_r() │ Thread safety │ MT-Safe locale                  │
121       └──────────────┴───────────────┴─────────────────────────────────┘

CONFORMING TO

123       The  nonreentrant  functions  are  from  SunOS 4.1.3.  A routine getmn‐
124       tent_r() was introduced in HP-UX 10, but it returns an int.  The proto‐
125       type shown above is glibc-only.
126

NOTES

128       System  V also has a getmntent() function but the calling sequence dif‐
129       fers,  and  the  returned  structure  is  different.   Under  System  V
130       /etc/mnttab  is  used.   4.4BSD  and  Digital UNIX have a routine getm‐
131       ntinfo(), a wrapper around the system call getfsstat().
132

SEE ALSO

134       fopen(3), fstab(5), mount(8)
135

COLOPHON

137       This page is part of release 5.04 of the Linux  man-pages  project.   A
138       description  of  the project, information about reporting bugs, and the
139       latest    version    of    this    page,    can     be     found     at
140       https://www.kernel.org/doc/man-pages/.
141
142
143
144                                  2019-03-06                      GETMNTENT(3)
Impressum