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
64 * fs-independent mount flags (built-in MNT_LINUX_MAP)
66 static const struct libmnt_optmap linux_flags_map
[] =
68 { "ro", MS_RDONLY
}, /* read-only */
69 { "rw", MS_RDONLY
, MNT_INVERT
}, /* read-write */
70 { "exec", MS_NOEXEC
, MNT_INVERT
}, /* permit execution of binaries */
71 { "noexec", MS_NOEXEC
}, /* don't execute binaries */
72 { "suid", MS_NOSUID
, MNT_INVERT
}, /* honor suid executables */
73 { "nosuid", MS_NOSUID
}, /* don't honor suid executables */
74 { "dev", MS_NODEV
, MNT_INVERT
}, /* interpret device files */
75 { "nodev", MS_NODEV
}, /* don't interpret devices */
77 { "sync", MS_SYNCHRONOUS
}, /* synchronous I/O */
78 { "async", MS_SYNCHRONOUS
, MNT_INVERT
},/* asynchronous I/O */
80 { "dirsync", MS_DIRSYNC
}, /* synchronous directory modifications */
81 { "remount", MS_REMOUNT
, MNT_NOMTAB
}, /* alter flags of mounted FS */
82 { "bind", MS_BIND
}, /* Remount part of the tree elsewhere */
83 { "rbind", MS_BIND
| MS_REC
}, /* Idem, plus mounted subtrees */
85 { "sub", MS_NOSUB
, MNT_INVERT
}, /* allow submounts */
86 { "nosub", MS_NOSUB
}, /* don't allow submounts */
89 { "silent", MS_SILENT
}, /* be quiet */
90 { "loud", MS_SILENT
, MNT_INVERT
}, /* print out messages. */
93 { "mand", MS_MANDLOCK
}, /* Allow mandatory locks on this FS */
94 { "nomand", MS_MANDLOCK
, MNT_INVERT
}, /* Forbid mandatory locks on this FS */
97 { "atime", MS_NOATIME
, MNT_INVERT
}, /* Update access time */
98 { "noatime", MS_NOATIME
}, /* Do not update access time */
101 { "iversion", MS_I_VERSION
}, /* Update inode I_version time */
102 { "noiversion", MS_I_VERSION
, MNT_INVERT
},/* Don't update inode I_version time */
105 { "diratime", MS_NODIRATIME
, MNT_INVERT
}, /* Update dir access times */
106 { "nodiratime", MS_NODIRATIME
}, /* Do not update dir access times */
109 { "relatime", MS_RELATIME
}, /* Update access times relative to mtime/ctime */
110 { "norelatime", MS_RELATIME
, MNT_INVERT
}, /* Update access time without regard to mtime/ctime */
112 #ifdef MS_STRICTATIME
113 { "strictatime", MS_STRICTATIME
}, /* Strict atime semantics */
114 { "nostrictatime", MS_STRICTATIME
, MNT_INVERT
}, /* kernel default atime */
117 { "lazytime", MS_LAZYTIME
}, /* Update {a,m,c}time on the in-memory inode only */
118 { "nolazytime", MS_LAZYTIME
, MNT_INVERT
},
120 #ifdef MS_PROPAGATION
121 { "unbindable", MS_UNBINDABLE
, MNT_NOHLPS
| MNT_NOMTAB
}, /* Unbindable */
122 { "runbindable", MS_UNBINDABLE
| MS_REC
, MNT_NOHLPS
| MNT_NOMTAB
},
123 { "private", MS_PRIVATE
, MNT_NOHLPS
| MNT_NOMTAB
}, /* Private */
124 { "rprivate", MS_PRIVATE
| MS_REC
, MNT_NOHLPS
| MNT_NOMTAB
},
125 { "slave", MS_SLAVE
, MNT_NOHLPS
| MNT_NOMTAB
}, /* Slave */
126 { "rslave", MS_SLAVE
| MS_REC
, MNT_NOHLPS
| MNT_NOMTAB
},
127 { "shared", MS_SHARED
, MNT_NOHLPS
| MNT_NOMTAB
}, /* Shared */
128 { "rshared", MS_SHARED
| MS_REC
, MNT_NOHLPS
| MNT_NOMTAB
},
134 * userspace mount option (built-in MNT_USERSPACE_MAP)
136 static const struct libmnt_optmap userspace_opts_map
[] =
138 { "defaults", 0, 0 }, /* default options */
140 { "auto", MNT_MS_NOAUTO
, MNT_NOHLPS
| MNT_INVERT
| MNT_NOMTAB
}, /* Can be mounted using -a */
141 { "noauto", MNT_MS_NOAUTO
, MNT_NOHLPS
| MNT_NOMTAB
}, /* Can only be mounted explicitly */
143 { "user[=]", MNT_MS_USER
}, /* Allow ordinary user to mount (mtab) */
144 { "nouser", MNT_MS_USER
, MNT_INVERT
| MNT_NOMTAB
}, /* Forbid ordinary user to mount */
146 { "users", MNT_MS_USERS
, MNT_NOMTAB
}, /* Allow ordinary users to mount */
147 { "nousers", MNT_MS_USERS
, MNT_INVERT
| MNT_NOMTAB
}, /* Forbid ordinary users to mount */
149 { "owner", MNT_MS_OWNER
, MNT_NOMTAB
}, /* Let the owner of the device mount */
150 { "noowner", MNT_MS_OWNER
, MNT_INVERT
| MNT_NOMTAB
}, /* Device owner has no special privs */
152 { "group", MNT_MS_GROUP
, MNT_NOMTAB
}, /* Let the group of the device mount */
153 { "nogroup", MNT_MS_GROUP
, MNT_INVERT
| MNT_NOMTAB
}, /* Device group has no special privs */
156 * Note that traditional init scripts assume the _netdev option in /etc/mtab to
157 * umount network block devices on shutdown.
159 { "_netdev", MNT_MS_NETDEV
}, /* Device requires network */
161 { "comment=", MNT_MS_COMMENT
, MNT_NOHLPS
| MNT_NOMTAB
},/* fstab comment only */
162 { "x-", MNT_MS_XCOMMENT
, MNT_NOHLPS
| MNT_NOMTAB
| MNT_PREFIX
}, /* x- options */
164 { "loop[=]", MNT_MS_LOOP
, MNT_NOHLPS
}, /* use the loop device */
165 { "offset=", MNT_MS_OFFSET
, MNT_NOHLPS
| MNT_NOMTAB
}, /* loop device offset */
166 { "sizelimit=", MNT_MS_SIZELIMIT
, MNT_NOHLPS
| MNT_NOMTAB
}, /* loop device size limit */
167 { "encryption=", MNT_MS_ENCRYPTION
, MNT_NOHLPS
| MNT_NOMTAB
}, /* loop device encryption */
169 { "nofail", MNT_MS_NOFAIL
, MNT_NOMTAB
}, /* Do not fail if ENOENT on dev */
171 { "uhelper=", MNT_MS_UHELPER
}, /* /sbin/umount.<helper> */
173 { "helper=", MNT_MS_HELPER
}, /* /sbin/mount.<helper> */
179 * mnt_get_builtin_map:
180 * @id: map id -- MNT_LINUX_MAP or MNT_USERSPACE_MAP
182 * MNT_LINUX_MAP - Linux kernel fs-independent mount options
183 * (usually MS_* flags, see linux/fs.h)
185 * MNT_USERSPACE_MAP - userpace mount(8) specific mount options
186 * (e.g user=, _netdev, ...)
188 * Returns: static built-in libmount map.
190 const struct libmnt_optmap
*mnt_get_builtin_optmap(int id
)
194 if (id
== MNT_LINUX_MAP
)
195 return linux_flags_map
;
196 else if (id
== MNT_USERSPACE_MAP
)
197 return userspace_opts_map
;
202 * Looks up the @name in @maps and returns a map and in @mapent
203 * returns the map entry
205 const struct libmnt_optmap
*mnt_optmap_get_entry(
206 struct libmnt_optmap
const **maps
,
210 const struct libmnt_optmap
**mapent
)
222 for (i
= 0; i
< nmaps
; i
++) {
223 const struct libmnt_optmap
*map
= maps
[i
];
224 const struct libmnt_optmap
*ent
;
227 for (ent
= map
; ent
&& ent
->name
; ent
++) {
228 if (ent
->mask
& MNT_PREFIX
) {
229 if (startswith(name
, ent
->name
)) {
236 if (strncmp(ent
->name
, name
, namelen
))
238 p
= ent
->name
+ namelen
;
239 if (*p
== '\0' || *p
== '=' || *p
== '[') {