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 *restrict stream,
18                     const struct mntent *restrict mnt);
19
20       int endmntent(FILE *streamp);
21
22       char *hasmntopt(const struct mntent *mnt, const char *opt);
23
24       /* GNU extension */
25       #include <mntent.h>
26
27       struct mntent *getmntent_r(FILE *restrict streamp,
28                     struct mntent *restrict mntbuf,
29                     char *restrict buf, int buflen);
30
31   Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
32
33       getmntent_r():
34           Since glibc 2.19:
35               _DEFAULT_SOURCE
36           Glibc 2.19 and earlier:
37               _BSD_SOURCE || _SVID_SOURCE
38

DESCRIPTION

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

RETURN VALUE

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

FILES

101       /etc/fstab
102              filesystem description file
103
104       /etc/mtab
105              mounted filesystem description file
106

ATTRIBUTES

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

CONFORMING TO

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

NOTES

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

SEE ALSO

137       fopen(3), fstab(5), mount(8)
138

COLOPHON

140       This page is part of release 5.13 of the Linux  man-pages  project.   A
141       description  of  the project, information about reporting bugs, and the
142       latest    version    of    this    page,    can     be     found     at
143       https://www.kernel.org/doc/man-pages/.
144
145
146
147                                  2021-03-22                      GETMNTENT(3)
Impressum