2
* Copyright (C) 2010 Karel Zak <kzak@redhat.com>
4
* This file may be redistributed under the terms of the
5
* GNU Lesser General Public License.
11
* @short_description: description for mount options
13
* The mount(2) linux syscall uses two arguments for mount options:
15
* @mountflags: (see MS_* macros in linux/fs.h)
17
* @mountdata: (usully a comma separated string of options)
19
* The libmount uses options-map(s) to describe mount options.
21
* The option description (map entry) includes:
23
* @name: and argument name
25
* @id: (in the map unique identifier or a mountflags, e.g MS_RDONLY)
27
* @mask: (MNT_INVERT, MNT_NOMTAB)
29
* The option argument value is defined by:
31
* "=" -- required argument, e.g "comment="
33
* "[=]" -- optional argument, e.g. "loop[=]"
39
* #define MY_MS_FOO (1 << 1)
40
* #define MY_MS_BAR (1 << 2)
42
* libmnt_optmap myoptions[] = {
43
* { "foo", MY_MS_FOO },
44
* { "nofoo", MY_MS_FOO | MNT_INVERT },
45
* { "bar=", MY_MS_BAR },
51
* The libmount defines two basic built-in options maps:
53
* @MNT_LINUX_MAP: fs-independent kernel mount options (usually MS_* flags)
55
* @MNT_USERSPACE_MAP: userspace specific mount options (e.g. "user", "loop")
57
* For more details about option map struct see "struct mnt_optmap" in
69
* fs-independent mount flags (built-in MNT_LINUX_MAP)
71
static const struct libmnt_optmap linux_flags_map[] =
73
{ "ro", MS_RDONLY }, /* read-only */
74
{ "rw", MS_RDONLY, MNT_INVERT }, /* read-write */
75
{ "exec", MS_NOEXEC, MNT_INVERT }, /* permit execution of binaries */
76
{ "noexec", MS_NOEXEC }, /* don't execute binaries */
77
{ "suid", MS_NOSUID, MNT_INVERT }, /* honor suid executables */
78
{ "nosuid", MS_NOSUID }, /* don't honor suid executables */
79
{ "dev", MS_NODEV, MNT_INVERT }, /* interpret device files */
80
{ "nodev", MS_NODEV }, /* don't interpret devices */
82
{ "sync", MS_SYNCHRONOUS }, /* synchronous I/O */
83
{ "async", MS_SYNCHRONOUS, MNT_INVERT },/* asynchronous I/O */
85
{ "dirsync", MS_DIRSYNC }, /* synchronous directory modifications */
86
{ "remount", MS_REMOUNT, MNT_NOMTAB }, /* alter flags of mounted FS */
87
{ "bind", MS_BIND }, /* Remount part of tree elsewhere */
88
{ "rbind", MS_BIND | MS_REC }, /* Idem, plus mounted subtrees */
90
{ "sub", MS_NOSUB, MNT_INVERT }, /* allow submounts */
91
{ "nosub", MS_NOSUB }, /* don't allow submounts */
94
{ "quiet", MS_SILENT }, /* be quiet */
95
{ "loud", MS_SILENT, MNT_INVERT }, /* print out messages. */
98
{ "mand", MS_MANDLOCK }, /* Allow mandatory locks on this FS */
99
{ "nomand", MS_MANDLOCK, MNT_INVERT }, /* Forbid mandatory locks on this FS */
102
{ "atime", MS_NOATIME, MNT_INVERT }, /* Update access time */
103
{ "noatime", MS_NOATIME }, /* Do not update access time */
106
{ "iversion", MS_I_VERSION }, /* Update inode I_version time */
107
{ "noiversion", MS_I_VERSION, MNT_INVERT},/* Don't update inode I_version time */
110
{ "diratime", MS_NODIRATIME, MNT_INVERT }, /* Update dir access times */
111
{ "nodiratime", MS_NODIRATIME }, /* Do not update dir access times */
114
{ "relatime", MS_RELATIME }, /* Update access times relative to mtime/ctime */
115
{ "norelatime", MS_RELATIME, MNT_INVERT }, /* Update access time without regard to mtime/ctime */
117
#ifdef MS_STRICTATIME
118
{ "strictatime", MS_STRICTATIME }, /* Strict atime semantics */
119
{ "nostrictatime", MS_STRICTATIME, MNT_INVERT }, /* kernel default atime */
125
* userspace mount option (built-in MNT_USERSPACE_MAP)
127
* TODO: offset=, sizelimit=, encryption=, vfs=
129
static const struct libmnt_optmap userspace_opts_map[] =
131
{ "defaults", 0, 0 }, /* default options */
133
{ "auto", MNT_MS_NOAUTO, MNT_INVERT | MNT_NOMTAB }, /* Can be mounted using -a */
134
{ "noauto", MNT_MS_NOAUTO, MNT_NOMTAB }, /* Can only be mounted explicitly */
136
{ "user[=]", MNT_MS_USER }, /* Allow ordinary user to mount (mtab) */
137
{ "nouser", MNT_MS_USER, MNT_INVERT | MNT_NOMTAB }, /* Forbid ordinary user to mount */
139
{ "users", MNT_MS_USERS, MNT_NOMTAB }, /* Allow ordinary users to mount */
140
{ "nousers", MNT_MS_USERS, MNT_INVERT | MNT_NOMTAB }, /* Forbid ordinary users to mount */
142
{ "owner", MNT_MS_OWNER, MNT_NOMTAB }, /* Let the owner of the device mount */
143
{ "noowner", MNT_MS_OWNER, MNT_INVERT | MNT_NOMTAB }, /* Device owner has no special privs */
145
{ "group", MNT_MS_GROUP, MNT_NOMTAB }, /* Let the group of the device mount */
146
{ "nogroup", MNT_MS_GROUP, MNT_INVERT | MNT_NOMTAB }, /* Device group has no special privs */
148
{ "_netdev", MNT_MS_NETDEV }, /* Device requires network */
150
{ "comment=", MNT_MS_COMMENT, MNT_NOMTAB }, /* fstab comment only */
152
{ "loop[=]", MNT_MS_LOOP }, /* use the loop device */
154
{ "nofail", MNT_MS_NOFAIL, MNT_NOMTAB }, /* Do not fail if ENOENT on dev */
156
{ "uhelper=", MNT_MS_UHELPER }, /* /sbin/umount.<helper> */
162
* mnt_get_builtin_map:
163
* @id: map id -- MNT_LINUX_MAP or MNT_USERSPACE_MAP
165
* MNT_LINUX_MAP - Linux kernel fs-independent mount options
166
* (usually MS_* flags, see linux/fs.h)
168
* MNT_USERSPACE_MAP - userpace mount(8) specific mount options
169
* (e.g user=, _netdev, ...)
171
* Returns: static built-in libmount map.
173
const struct libmnt_optmap *mnt_get_builtin_optmap(int id)
177
if (id == MNT_LINUX_MAP)
178
return linux_flags_map;
179
else if (id == MNT_USERSPACE_MAP)
180
return userspace_opts_map;
185
* Lookups for the @name in @maps and returns a map and in @mapent
186
* returns the map entry
188
const struct libmnt_optmap *mnt_optmap_get_entry(
189
struct libmnt_optmap const **maps,
193
const struct libmnt_optmap **mapent)
205
for (i = 0; i < nmaps; i++) {
206
const struct libmnt_optmap *map = maps[i];
207
const struct libmnt_optmap *ent;
210
for (ent = map; ent && ent->name; ent++) {
211
if (strncmp(ent->name, name, namelen))
213
p = ent->name + namelen;
214
if (*p == '\0' || *p == '=' || *p == '[') {