]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: implement X-mount.auto-fstypes
authorKarel Zak <kzak@redhat.com>
Mon, 9 Jan 2023 13:22:06 +0000 (14:22 +0100)
committerKarel Zak <kzak@redhat.com>
Mon, 9 Jan 2023 13:22:06 +0000 (14:22 +0100)
Fixes: https://github.com/util-linux/util-linux/issues/1969
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/src/context.c
libmount/src/context_mount.c
sys-utils/mount.8.adoc

index 96f43d58dcb400e31a48089d6842e52b4ceea45c..b1b08ae63a2bd50d739e1cc6b9879b4021d142cd 100644 (file)
@@ -39,6 +39,7 @@
 #include "mountP.h"
 #include "strutils.h"
 #include "namespace.h"
+#include "match.h"
 
 #include <sys/wait.h>
 
@@ -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;
 }
 
index 743f253838030ba6341cae33a487046519a47c65..d81741ea5cce96a7722b9700890050bd29c72fe1 100644 (file)
@@ -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)
index 9936e2f925a6e653068518d59150eacb64b5ed71..50c10be2b102429cf15ed64bacd13e4bc8603ecd 100644 (file)
@@ -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.