From fdac580358e7a1f7ab9fa2b0e330247872fa6979 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 9 Dec 2025 13:02:11 +0100 Subject: [PATCH] libmount: add option to override fs-type with mount-type 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/) 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 --- configure.ac | 10 ++++++++++ libmount/src/context.c | 11 +++++++++++ libmount/src/context_umount.c | 4 +++- libmount/src/mountP.h | 1 + libmount/src/utils.c | 27 ++++++++++++++++++++++++++- meson.build | 5 +++++ meson_options.txt | 4 ++++ 7 files changed, 60 insertions(+), 2 deletions(-) diff --git a/configure.ac b/configure.ac index 93ad3a38b..a424e0947 100644 --- a/configure.ac +++ b/configure.ac @@ -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] diff --git a/libmount/src/context.c b/libmount/src/context.c index 66b5c2d8f..6dfc5913d 100644 --- a/libmount/src/context.c +++ b/libmount/src/context.c @@ -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; } diff --git a/libmount/src/context_umount.c b/libmount/src/context_umount.c index 8fbd662ab..854b704b0 100644 --- a/libmount/src/context_umount.c +++ b/libmount/src/context_umount.c @@ -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; } diff --git a/libmount/src/mountP.h b/libmount/src/mountP.h index fb01041f6..02b86585c 100644 --- a/libmount/src/mountP.h +++ b/libmount/src/mountP.h @@ -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) diff --git a/libmount/src/utils.c b/libmount/src/utils.c index 7626b6f91..16c5e8a98 100644 --- a/libmount/src/utils.c +++ b/libmount/src/utils.c @@ -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/ (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 diff --git a/meson.build b/meson.build index 2f4e66fef..8b7880e46 100644 --- a/meson.build +++ b/meson.build @@ -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') diff --git a/meson_options.txt b/meson_options.txt index c03de17ff..b764b56fb 100644 --- a/meson_options.txt +++ b/meson_options.txt @@ -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') -- 2.47.3