Skip to content

Commit

Permalink
libmount: implement X-mount.auto-fstypes
Browse files Browse the repository at this point in the history
Fixes: #1969
Signed-off-by: Karel Zak <kzak@redhat.com>
  • Loading branch information
karelzak committed Jan 9, 2023
1 parent 10dd071 commit 1592425
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
23 changes: 23 additions & 0 deletions libmount/src/context.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "mountP.h"
#include "strutils.h"
#include "namespace.h"
#include "match.h"

#include <sys/wait.h>

Expand Down Expand Up @@ -1903,6 +1904,28 @@ int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type)
if (!mnt_context_switch_ns(cxt, ns_old))
return -MNT_ERR_NAMESPACE;

if (rc == 0 && *type) {
struct libmnt_optlist *ol = mnt_context_get_optlist(cxt);
struct libmnt_opt *opt;
const char *allowed;

if (!ol)
return -ENOMEM;

opt = mnt_optlist_get_named(ol,
"X-mount.auto-fstypes", cxt->map_userspace);

if (opt
&& (allowed = mnt_opt_get_value(opt))
&& !match_fstype(*type, allowed)) {
DBG(CXT, ul_debugobj(cxt, "%s is not allowd by auto-fstypes=%s",

This comment has been minimized.

Copy link
@poettering

poettering Jan 9, 2023

Contributor

typo: allowd → allowed

*type, allowed));
free(*type);
*type = NULL;
rc = -MNT_ERR_NOFSTYPE;
}
}

return rc;
}

Expand Down
2 changes: 1 addition & 1 deletion libmount/src/context_mount.c
Original file line number Diff line number Diff line change
Expand Up @@ -1484,7 +1484,7 @@ int mnt_context_get_mount_excode(
if (buf)
snprintf(buf, bufsz, restricted ?
_("failed to determine filesystem type") :
_("no filesystem type specified"));
_("no valid filesystem type specified"));
return MNT_EX_USAGE;
case -MNT_ERR_NOSOURCE:
if (uflags & MNT_MS_NOFAIL)
Expand Down
24 changes: 24 additions & 0 deletions sys-utils/mount.8.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,30 @@ The same as *X-** options, but stored permanently in user space. This means the
+
Note that before util-linux v2.30 the x-* options have not been maintained by libmount and stored in user space (functionality was the same as for X-* now), but due to the growing number of use-cases (in initrd, systemd etc.) the functionality has been extended to keep existing _fstab_ configurations usable without a change.

*X-mount.auto-fstypes*=_list_::
Specifies allowed or forbidden filesystem types for automatic filesystem
detection.
+
The _list_ is a comma-separated list of the filesystem names. The
automatic filesystem detection is triggered by the "auto" filesystem type or
when the filesystem type is not specified.
+
Thy _list_ follows how mount
evaluates type patterns (see *-t* for more details). Only specified filesystem
types are allowed, or all specified types are forbidden if the list is prefixed
by "no".
+
For example, X-mount.auto-fstypes="ext4,btrfs" accepts only ext4 and
btrfs, and X-mount.auto-fstypes="novfat,xfs" accepts all filesystems except vfat
and xfs.
+
Note that comma is used as a separator between mount options, it means
that auto-fstypes values have to be properly quoted, don’t forget that the shell
strips off quotes and thus double quoting is required. For example:
____
mount -t auto -o'X-mount.auto-fstypes="noext2,ext3"' /dev/sdc1 /mnt/test
____

*X-mount.mkdir*[=_mode_]::
Allow to make a target directory (mountpoint) if it does not exist yet. The optional argument _mode_ specifies the filesystem access mode used for *mkdir*(2) in octal notation. The default mode is 0755. This functionality is supported only for root users or when *mount* is executed without suid permissions. The option is also supported as *x-mount.mkdir*, but this notation is deprecated since v2.30. See also *--mkdir* command line option.

Expand Down

0 comments on commit 1592425

Please sign in to comment.