]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: add option to override fs-type with mount-type
authorKarel Zak <kzak@redhat.com>
Tue, 9 Dec 2025 12:02:11 +0000 (13:02 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 9 Dec 2025 12:02:11 +0000 (13:02 +0100)
This patch introduces an internal libmount method to convert fs-type
(as provided by libblkid or udevd) to mount-type to specify a different
mount driver.

Currently, the mapping from fs-type to mount-type is hardcoded in
libmount as a temporary solution. The final implementation should
provide configuration files (e.g., /etc/mount/fs.d/<name>) for these
mappings.

The current default mapping is implemented only for NTFS. It can be
modified during compilation with:

 ./configure --with-ntfs-mounttype=TYPE
or
 meson setup build -D ntfs-mounttype=TYPE

The default is "ntfs3".

Addresses: https://github.com/util-linux/util-linux/pull/3618
Addresses: https://github.com/systemd/systemd/pull/39982
Signed-off-by: Karel Zak <kzak@redhat.com>
configure.ac
libmount/src/context.c
libmount/src/context_umount.c
libmount/src/mountP.h
libmount/src/utils.c
meson.build
meson_options.txt

index 93ad3a38b12d4e227ee719cafcd62e7e7c3c8c8b..a424e09476bb1350b762d2132fcac149b7a735f3 100644 (file)
@@ -2760,6 +2760,16 @@ AS_IF([test "x$with_sysusersdir" != "xno"], [
   AC_SUBST([sysusersdir], [$with_sysusersdir])
 ])
 
+
+AC_ARG_WITH([ntfs-mounttype],
+  AS_HELP_STRING([--with-ntfs-mounttype=TYPE], [overwrite default ntfs3 mount type for NTFS]),
+  [], [with_ntfs_mounttype=no]
+)
+AS_IF([test "x$with_ntfs_mounttype" != "xno"], [
+  AC_DEFINE_UNQUOTED([CONFIG_UL_NTFS_MOUNTTYPE], ["$with_ntfs_mounttype"], [NTFS mounttype])
+])
+
+
 AC_ARG_WITH([smack],
   AS_HELP_STRING([--with-smack], [build with SMACK support]),
   [], [with_smack=no]
index 66b5c2d8f1b31f423c521ec02b2e8b53112057a1..6dfc5913dfd509656e2235a49d7c8ef4b260f754 100644 (file)
@@ -2090,6 +2090,17 @@ int mnt_context_guess_srcpath_fstype(struct libmnt_context *cxt, char **type)
                }
        }
 
+       if (rc == 0 && *type) {
+               const char *x = mnt_fstype_to_mounttype(*type);
+
+               if (x) {
+                       free(*type);
+                       *type = strdup(x);
+                       if (!*type)
+                               rc = -ENOMEM;
+               }
+       }
+
        return rc;
 }
 
index 8fbd662ab4894fd1ed7bebc44c83acdda2369222..854b704b05a714363e947ecf2062dc8163ec0671 100644 (file)
@@ -298,7 +298,9 @@ static int lookup_umount_fs_by_statfs(struct libmnt_context *cxt, const char *tg
                        close(fd);
                }
                if (type) {
-                       int rc = mnt_fs_set_fstype(cxt->fs, type);
+                       const char *x = mnt_fstype_to_mounttype(type);
+                       int rc = mnt_fs_set_fstype(cxt->fs, x ? x : type);
+
                        if (rc)
                                return rc;
                }
index fb01041f6b157aa107f6bec95e583f20ec91f47a..02b86585cd6dd027219fd8718cb5e6632ebee3f1 100644 (file)
@@ -109,6 +109,7 @@ struct libmnt_listmnt;
 extern int mnt_valid_tagname(const char *tagname);
 
 extern const char *mnt_statfs_get_fstype(struct statfs *vfs);
+extern const char *mnt_fstype_to_mounttype(const char *fstype);
 extern int is_file_empty(const char *name);
 
 extern int mnt_is_readonly(const char *path)
index 7626b6f91ee412e97f40e1f81db8e407a9b8777f..16c5e8a9853cd02851b7b9acd762577f70d96cd0 100644 (file)
@@ -506,7 +506,7 @@ const char *mnt_statfs_get_fstype(struct statfs *vfs)
        case STATFS_NCP_MAGIC:          return "ncp";
        case STATFS_NFS_MAGIC:          return "nfs";
        case STATFS_NILFS_MAGIC:        return "nilfs2";
-       case STATFS_NTFS_MAGIC:         return "ntfs3";
+       case STATFS_NTFS_MAGIC:         return "ntfs";
        case STATFS_OCFS2_MAGIC:        return "ocfs2";
        case STATFS_OMFS_MAGIC:         return "omfs";
        case STATFS_OPENPROMFS_MAGIC:   return "openpromfs";
@@ -541,6 +541,31 @@ const char *mnt_statfs_get_fstype(struct statfs *vfs)
        return NULL;
 }
 
+/*
+ * Default NTFS mount type (used by libmount and libblkid)
+ */
+#ifndef CONFIG_UL_NTFS_MOUNTTYPE
+# define CONFIG_UL_NTFS_MOUNTTYPE "ntfs3"
+#endif
+
+/*
+ * Convert FS-type (as provided by libblkid or udev) to the preferred
+ * kernel FS driver (type used to mount the FS).
+ *
+ * This is a temporary solution; the final solution should be
+ * based on config files like /etc/mount/fs.d/<name> (from lib/configs.c).
+ */
+const char *mnt_fstype_to_mounttype(const char *fstype)
+{
+       if (!fstype)
+               return NULL;
+
+       if (strcmp(fstype, "ntfs") == 0)
+               return CONFIG_UL_NTFS_MOUNTTYPE;
+
+       return NULL;
+}
+
 /**
  * mnt_match_fstype:
  * @type: filesystem type
index 2f4e66feff03bab5a88ecd92d93de2486ef8fe61..8b7880e465d7c5cbbe69310664c4d0a21726649a 100644 (file)
@@ -918,6 +918,11 @@ if fs_search_path_extra != ''
 endif
 conf.set_quoted('FS_SEARCH_PATH', fs_search_path)
 
+ntfs_mounttype = get_option('ntfs-mounttype')
+if ntfs_mounttype != ''
+  conf.set_quoted('CONFIG_UL_NTFS_MOUNTTYPE', ntfs_mounttype)
+endif
+
 systemdsystemunitdir = ''
 if systemd.found()
   systemdsystemunitdir = systemd.get_variable(pkgconfig : 'systemdsystemunitdir')
index c03de17ff9cdde5ed7ad840d0cf379ab12c76482..b764b56fbb2bfa1a14b1dae602db0719f2417651 100644 (file)
@@ -308,6 +308,10 @@ option('build-libmount-udev-support',
        type : 'feature',
        description : 'support reading from udev in libmount')
 
+option('ntfs-mounttype',
+       type : 'string',
+       description : 'overwrite default ntfs3 mount type for NTFS')
+
 option('vendordir',
        type: 'string',
        description : 'directory for distribution provided econf files')