From 1592425a0a1472db3168cd9247f001d7c5dd84b6 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 9 Jan 2023 14:22:06 +0100 Subject: [PATCH] libmount: implement X-mount.auto-fstypes Fixes: https://github.com/util-linux/util-linux/issues/1969 Signed-off-by: Karel Zak --- libmount/src/context.c | 23 +++++++++++++++++++++++ libmount/src/context_mount.c | 2 +- sys-utils/mount.8.adoc | 24 ++++++++++++++++++++++++ 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/libmount/src/context.c b/libmount/src/context.c index 96f43d58dc..b1b08ae63a 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -39,6 +39,7 @@ #include "mountP.h" #include "strutils.h" #include "namespace.h" +#include "match.h" #include @@ -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", + *type, allowed)); + free(*type); + *type = NULL; + rc = -MNT_ERR_NOFSTYPE; + } + } + return rc; } diff --git a/libmount/src/context_mount.c b/libmount/src/context_mount.c index 743f253838..d81741ea5c 100644 --- a/libmount/src/context_mount.c +++ b/libmount/src/context_mount.c @@ -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) diff --git a/sys-utils/mount.8.adoc b/sys-utils/mount.8.adoc index 9936e2f925..50c10be2b1 100644 --- a/sys-utils/mount.8.adoc +++ b/sys-utils/mount.8.adoc @@ -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. -- 2.47.3