util-linux / util-linux

http://en.wikipedia.org/wiki/Util-linux
GNU General Public License v2.0
2.68k stars 1.21k forks source link

Try to use the new `ntfs3` file system preferentially for mounting NTFS partitions #1508

Open ericonr opened 2 years ago

ericonr commented 2 years ago

Hi!

Now that the ntfs3 driver has been merged into Linux, I think it would make for nice UI for it to be preferred when mounting NTFS partitions. This is necessary because the ntfs driver wasn't replaced in the kernel, so mount with "ntfs" as the file system type still chooses the old driver.

To complicate matters, I believe most distros symlink mount.ntfs to ntfs-3g, so mount will prefer to use that to mount a NTFS partition, if available. If ntfs3 is available, I still think that should be preferred, but that would be a more complicated fix, I think.

A suggestion we received was a mount.ntfs helper that does mount -t ntfs3, but that felt rather fragile, and I figured trying to have something upstream would be the best move.

ericonr commented 2 years ago

In case there are plans to remove ntfs from a future kernel and put ntfs3 in its place, this might not be necessary. Though given that 5.15 is a LTS kernel, that wouldn't be very nice :/

marcosfrm commented 2 years ago

https://github.com/storaged-project/udisks/commit/042e19022e10d8fb6a26deee61da747cdcfbe913 https://github.com/storaged-project/udisks/issues/932

mount -t ntfs3,ntfs would work if ntfs3 and ntfs-3g options were compatible... but they are not. Or if ntfs3 ignored unknown options like it did for a while... it does not ignore anymore. A total mess.

karelzak commented 2 years ago

Well, the kernel provides a way how to configure module names and aliases. I don't think it's mount(8) (libblkid) business to select the proper filesystem name to load the right kernel module.

I guess all you need is to modify /lib/modules/$(uname -r)/modules.alias, or /etc/modprobe.d/, or /etc/modprobe.conf and use "alias: ntfs ntfs3".

The same situation is /sbin/mount.* helpers, it's distribution decision.

justinkb commented 2 years ago

just a little warning to everyone not to follow that advice to alias ntfs to ntfs3. led to freezes here (fedora 35 on gnome 41 with kernel 5.15.6), which ended up corrupting my .config/dconf/user file (had to redo all my gnome settings, since I had no backup)

tretter commented 2 years ago

Using a module alias does not work. The kernel finds the file system that shall be used by comparing const char *filesystemtype of mount(2) to the (hard coded) name in struct file_system_type in the file system implementation. Even if the ntfs3 module is loaded correctly (I didn't test this, since I use a built-in ntfs3), mount will still fall back to the ntfs module or fail to mount if ntfs is disabled.

marcosfrm commented 2 years ago

The kernel needs a compile time option to register ntfs as an alias to ntfs3. Something like this, conditioned to CONFIG_NTFS3_AS_DEFAULT or so (conflicting with CONFIG_NTFS_FS):

--- fs/ntfs3/super.c     2022-01-27 08:18:31.937695734 -0300
+++ fs/ntfs3/super.c     2022-01-27 08:20:09.287874467 -0300
@@ -1430,6 +1430,15 @@

 // clang-format off
 static struct file_system_type ntfs_fs_type = {
+        .owner                  = THIS_MODULE,
+        .name                   = "ntfs",
+        .init_fs_context        = ntfs_init_fs_context,
+        .parameters             = ntfs_fs_parameters,
+        .kill_sb                = kill_block_super,
+        .fs_flags               = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+};
+
+static struct file_system_type ntfs3_fs_type = {
        .owner                  = THIS_MODULE,
        .name                   = "ntfs3",
        .init_fs_context        = ntfs_init_fs_context,
@@ -1469,6 +1478,10 @@
        if (err)
                goto out;

+        err = register_filesystem(&ntfs3_fs_type);
+        if (err)
+                goto out;
+
        return 0;
 out:
        kmem_cache_destroy(ntfs_inode_cachep);
@@ -1485,6 +1498,7 @@
        }

        unregister_filesystem(&ntfs_fs_type);
+        unregister_filesystem(&ntfs3_fs_type);
        ntfs3_exit_bitmap();
 }

@@ -1501,6 +1515,7 @@
 #endif

 MODULE_AUTHOR("Konstantin Komarov");
+MODULE_ALIAS_FS("ntfs");
 MODULE_ALIAS_FS("ntfs3");

 module_init(init_ntfs_fs);

(untested)

https://lore.kernel.org/ntfs3/

Unfortunately Paragon's developer is inactive for a while now.

vinceFR7528 commented 2 years ago

pour remplacer ntfs-3g par le module ntfs3 du kernel >=5.15 vérifier que le module ntfs3 est présent par la commande modinfo ntfs3

1) montage automatique d'une partition ntfs le problème vient du fait que udisks utilise par défaut l'option "windows_names" et que le module ntfs3 ne comprend pas cette option donc udisks se retourne vers ntfs-3g pour faire le montage

il suffit de supprimer l'option "windows_names" pour que le module ntfs3 fonctionne, pour cela en tant que root éditer et corriger le fichier /etc/udisks2/mount_options.conf s'il n'existe pas le créer par la commande suivante : cat >>/etc/udisks2/mount_options.conf <<EOF [defaults] ntfs_defaults=uid=\$UID,gid=\$GID EOF

optionnellement supprimer le package ntfs-3g, s'il n'a pas de dépendance

2) montage manuel avec la commande "mount" automatique donc sans l'option -t ntfs3 en tant que root il faut créer le fichier /usr/sbin/mount.ntfs par la commande cat >/usr/sbin/mount.ntfs <<EOF

!/bin/sh

exec mount -t ntfs3 "\$@" EOF chmod 755 /usr/sbin/mount.ntfs

Et voilà!

---------------- English to replace ntfs-3g with the ntfs3 kernel module >=5.15 check that the ntfs3 module is present with the modinfo ntfs3 command

1) automatic mounting of an ntfs partition the problem comes from the fact that udisks uses the "windows_names" option by default and that the ntfs3 module does not understand this option so udisks turns to ntfs-3g to do the mount

just remove the "windows_names" option for the ntfs3 module to work, for that as root edit and correct the file /etc/udisks2/mount_options.conf if it does not exist, create it with the following command: cat >>/etc/udisks2/mount_options.conf <<EOF [defaults] ntfs_defaults=uid=\$UID,gid=\$GID EOF

optionally remove the ntfs-3g package, if it has no dependency

2) manual mounting with the automatic "mount" command so without the -t ntfs3 option as root you must create the file /usr/sbin/mount.ntfs by the command cat >/usr/sbin/mount.ntfs <<EOF

!/bin/sh

exec mount -t ntfs3 "\$@" EOF chmod 755 /usr/sbin/mount.ntfs

Et voilà!

jelly commented 2 years ago

The proposed kernel module alias as modprobe.conf does not work as expected, so I still think util-linux mount should have a special fallback to ntfs3 when ntfs cannot be loaded see for example:

[jelle@thing linux]$ cat /etc/modprobe.d/ntfs.conf
alias fs-ntfs ntfs3

[jelle@thing ~]$ sudo mount -t auto /dev/loop0 /mnt
mount: /mnt: unknown filesystem type 'ntfs'.
       dmesg(1) may have more information after failed mount system call.

dmesg output:
[17012.519443] request_module fs-ntfs succeeded, but still no fs?

This is on fedora without ntfs-3g and only access to ntfs3 (the old RO ntfs module is not enabled)

karelzak commented 2 years ago

The proposed kernel module alias as modprobe.conf does not work as expected,

Unfortunately, this is true. The reason and possible solution are in previous comments. We need kernel change to register the alias.

so I still think util-linux mount should have a special fallback to ntfs3 when ntfs cannot be loaded

util-linux has no clue how the kernel loads modules and what is the current configuration. And report "ntfs3" instead of "ntfs" is a backwardly incompatible dirty hack rather than a real solution. Ask kernel developers for the solution.

If you need a quick solution then add /sbin/mount.ntfs script where it will call /usr/bin/mount -i -t ntfs3 $1 $2 (not tested).

marcosfrm commented 2 years ago

Complete patch (ref https://github.com/torvalds/linux/commit/10d4879f9ef01cc6190fafe4257d06f375bab92c).

diff --git a/fs/ntfs3/Kconfig b/fs/ntfs3/Kconfig
index 6e4cbc48ab8e..ecab36d18500 100644
--- a/fs/ntfs3/Kconfig
+++ b/fs/ntfs3/Kconfig
@@ -44,3 +44,11 @@ config NTFS3_FS_POSIX_ACL
      NOTE: this is linux only feature. Windows will ignore these ACLs.

      If you don't know what Access Control Lists are, say N.
+
+config NTFS3_AS_NTFS
+   bool "Use NTFS3 as default NTFS driver"
+   depends on NTFS3_FS
+   depends on NTFS_FS=n
+   default y
+   help
+     Registers ntfs as an alias to ntfs3.
diff --git a/fs/ntfs3/super.c b/fs/ntfs3/super.c
index 47012c9bf505..69a3a326410a 100644
--- a/fs/ntfs3/super.c
+++ b/fs/ntfs3/super.c
@@ -1438,7 +1438,7 @@ static int ntfs_init_fs_context(struct fs_context *fc)
 }

 // clang-format off
-static struct file_system_type ntfs_fs_type = {
+static struct file_system_type ntfs3_fs_type = {
    .owner          = THIS_MODULE,
    .name           = "ntfs3",
    .init_fs_context    = ntfs_init_fs_context,
@@ -1448,6 +1448,41 @@ static struct file_system_type ntfs_fs_type = {
 };
 // clang-format on

+#ifdef CONFIG_NTFS3_AS_NTFS
+// clang-format off
+static struct file_system_type ntfs_fs_type = {
+   .owner          = THIS_MODULE,
+   .name           = "ntfs",
+   .init_fs_context    = ntfs_init_fs_context,
+   .parameters     = ntfs_fs_parameters,
+   .kill_sb        = kill_block_super,
+   .fs_flags       = FS_REQUIRES_DEV | FS_ALLOW_IDMAP,
+};
+// clang-format on
+
+MODULE_ALIAS_FS("ntfs");
+MODULE_ALIAS("ntfs");
+
+static inline int register_ntfs_alias(void)
+{
+   return register_filesystem(&ntfs_fs_type);
+}
+
+static inline void unregister_ntfs_alias(void)
+{
+   unregister_filesystem(&ntfs_fs_type);
+}
+#else
+static inline int register_ntfs_alias(void)
+{
+   return 0;
+}
+
+static inline void unregister_ntfs_alias(void)
+{
+}
+#endif /* CONFIG_NTFS3_AS_NTFS */
+
 static int __init init_ntfs_fs(void)
 {
    int err;
@@ -1474,12 +1509,18 @@ static int __init init_ntfs_fs(void)
        goto out1;
    }

-   err = register_filesystem(&ntfs_fs_type);
+   err = register_ntfs_alias();
    if (err)
-       goto out;
+       goto out2;
+
+   err = register_filesystem(&ntfs3_fs_type);
+   if (err)
+       goto out3;

    return 0;
-out:
+out3:
+   unregister_ntfs_alias();
+out2:
    kmem_cache_destroy(ntfs_inode_cachep);
 out1:
    ntfs3_exit_bitmap();
@@ -1493,7 +1534,8 @@ static void __exit exit_ntfs_fs(void)
        kmem_cache_destroy(ntfs_inode_cachep);
    }

-   unregister_filesystem(&ntfs_fs_type);
+   unregister_filesystem(&ntfs3_fs_type);
+   unregister_ntfs_alias();
    ntfs3_exit_bitmap();
 }

Any kernel dev willing to pick it up?

marcosfrm commented 2 years ago

@aalexandrovich @teksturi

tbzatek commented 2 years ago

@marcosfrm: please remember that you can't just rename or alias filesystem drivers unless you unify the mount options, their arguments and error codes for unknown options. It's not just a simple drop-in replacement.

marcosfrm commented 2 years ago

That will need someone with NTFS expertise (which I do not have).

The basic options are supported by both ntfs and ntfs3:

uid, gid, umask, fmask, dmask, iocharset.

These ones could be aliases:

ntfs ntfs3
show_sys_files showmeta
disable_sparse sparse

It is a shame the hoops users have to jump through to easily use ntfs3, considering that major distributions like Debian, Fedora and Arch do not even enable the old ntfs kernel driver since ages.

tbzatek commented 2 years ago

@marcosfrm, while I appreciate your effort, I'd suggest you to take this matter to either upstream linux-fsdevel mailing list or bugzilla.kernel.org. This needs to be sorted out on a different level. UDisks has recently adapted for using ntfs3 natively and util-linux is so low-level and should stick with its strict rules.

I suggest to close this ticket for the time being (@karelzak).

teksturi commented 2 years ago

@marcosfrm I welcome you to join ntfs3 mailing list https://subspace.kernel.org/lists.linux.dev.html You can see archive from https://lore.kernel.org/ntfs3/ You should make your patches top of https://github.com/Paragon-Software-Group/linux-ntfs3 and send them to mailing list. If you are not familier with how contibutions work with kernel you can also read https://www.kernel.org/doc/html/latest/process/submitting-patches.html

Imo we really want to give user easy route to use ntfs3. We should think both users ntfs and ntfs-3g. So anyone can make patch which adds example alias to some mount options which help end users. If you gonna do this also add document for this.

Thanks for having intrest for ntfs3.

Firestar-Reimu commented 2 years ago

https://github.com/Paragon-Software-Group/linux-ntfs3/commit/1d07a9dfa19914ad27bdb9ec9ac0baa2329b2ae3

When enabled, the windows_names mount option prevents the creation of files or directories with names not allowed by Windows. Use the same option name as NTFS-3G for compatibility.

ntfs3 added windows_names option and more compatible to NTFS-3G

for now mount still use ntfs-3g as ntfs default, and ntfs3 is more recommended for performance.

Firestar-Reimu commented 1 year ago

what is the default umask for NTFS3?

Firestar-Reimu commented 1 year ago

Has this issue been fixed in 2.39?

karelzak commented 1 year ago

Has this issue been fixed in 2.39?

Read the discussion; I don't see anything to fix in util-linux.

marcosfrm commented 2 months ago

Fixed since kernel 6.9 with:

https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/commit/?id=74871791ffa9562d43567c5ff2ae93def3f39f65

Please ask your distro to enable the alias registration (CONFIG_NTFS_FS).