Bug 241475 - autofs: no way to pass locale options to msdosfs
Summary: autofs: no way to pass locale options to msdosfs
Status: New
Alias: None
Product: Base System
Classification: Unclassified
Component: bin (show other bugs)
Version: 11.3-RELEASE
Hardware: Any Any
: --- Affects Some People
Assignee: Edward Tomasz Napierala
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2019-10-24 15:58 UTC by Victor Sudakov
Modified: 2020-01-03 14:25 UTC (History)
5 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Victor Sudakov 2019-10-24 15:58:36 UTC
There is no (documented) way to pass locale options (e.g. -L ru_RU.UTF-8 -D CP866) to mount_msdosfs when using the default special -media map.
Comment 1 Masachika ISHIZUKA 2019-10-24 21:43:41 UTC
You can specify options in /etc/fstab like follows.

%grep msdosfs /etc/fstab
/dev/ada0pX   /hoge   msdosfs   rw,noauto,-L=ru_RU.UTF-8,-D=CP866   0   0
Comment 2 Victor Sudakov 2019-10-25 00:50:50 UTC
(In reply to Masachika ISHIZUKA from comment #1)
> You can specify options in /etc/fstab like follows.

How is fstab related to autofs, automount and /etc/autofs/special_media ?
Comment 3 Masachika ISHIZUKA 2019-10-25 23:59:18 UTC
(In reply to Victor Sudakov from comment #2)
Automount is referring /etc/fstab.
See 'special maps' (-noauto) in 'man 5 auto_master'.
Comment 4 Victor Sudakov 2019-10-26 03:01:20 UTC
(In reply to Masachika ISHIZUKA from comment #3)
No, I don't use the -noauto map, I use the -media map. I need to pass locale options to the -media map. I think I made it clear from the very beginning.
Comment 5 Masachika ISHIZUKA 2019-10-26 04:02:16 UTC
(In reply to Victor Sudakov from comment #4)
Sorry.
I think there is no way to specify locale options for the original (non modified) /etc/autofs/special_media.
Comment 6 Victor Sudakov 2019-10-26 07:11:58 UTC
(In reply to Masachika ISHIZUKA from comment #5)
Well, I'm not afraid to modify the original /etc/autofs/special_media. In fact I can make it produce the following output:

root@vas:~ # /etc/autofs/special_media da0
-fstype=msdosfs,nosuid,async,-L=ru_RU.UTF-8,-D=CP866    :/dev/da0

But it's an ugly undocumented way.

root@vas:~ # diff -u /etc/autofs/special_media.bak /etc/autofs/special_media
--- /etc/autofs/special_media.bak       2019-10-26 14:02:02.810753000 +0700
+++ /etc/autofs/special_media   2019-10-26 14:02:59.638463000 +0700
@@ -58,7 +58,7 @@
                fi
                ;;
        "ext2fs" | "msdosfs")
-               echo "-fstype=${_fstype},nosuid,async   :/dev/${_p}"
+               echo "-fstype=${_fstype},nosuid,async,-L=ru_RU.UTF-8,-D=CP866   :/dev/${_p}"
                ;;
        *)
                echo "-fstype=${_fstype},nosuid :/dev/${_p}"
root@vas:~ #
Comment 7 Edward Tomasz Napierala freebsd_committer 2019-11-25 12:36:07 UTC
Can you try passing it in auto_master, like this?

/media          -media          -nosuid,noatime,autoro,-L=ru_RU.UTF-8,-D=CP866

It wouldn't be shown in special_media's output, but it should get used by automountd(8) when mounting; if you set automountd_flags="-v" you should see this in logs:

Nov 25 12:35:05 v2 automountd[1866]: executing "mount -t msdosfs -o nosuid,async,nosuid,noatime,autoro,-L=ru_RU.UTF-8,-D=CP866,automounted /dev/md0 /media/md0/" as pid 1875
Comment 8 Victor Sudakov 2019-11-25 13:25:28 UTC
(In reply to Edward Tomasz Napierala from comment #7)
This won't work because fusefs does not support locale options, and the /media map  mount options are common for both fuse and msdosfs.

If I do as you request, mounting exfat will break.
Comment 9 Edward Tomasz Napierala freebsd_committer 2019-11-25 15:14:43 UTC
Okay, in this case the best way is modifying /etc/autofs/special_media then.
Comment 10 Victor Sudakov 2019-11-25 16:55:59 UTC
(In reply to Edward Tomasz Napierala from comment #9)
> Okay, in this case the best way is modifying /etc/autofs/special_media then.

Do you plan to provide some tunable variables in /etc/autofs/special_media (or even in rc.conf) because hacking /etc/autofs/special_media directly is kind of ugly? 

Like MSDOSFS_ENCODING, MSDOSFS_UMASK or whatever?
Comment 11 Jason W. Bacon freebsd_committer 2019-12-13 02:01:26 UTC
I think hacking special_media is fragile as well as ugly, as the file could be clobbered by freebsd-update.

I did the following to get msdosfs USB sticks writable by default:

-	"ext2fs" | "msdosfs")
+	"ext2fs")
 		echo "-fstype=${_fstype},nosuid,async	:/dev/${_p}"
+		;;
+	"msdosfs")
+		echo "-fstype=${_fstype},nosuid,async,-m=770,-g=operator	:

Adding -m=770 to auto_master breaks mounting for other filesystems like UFS2, which don't accept the flag.

I think a simple solution here would be sourcing an rc.conf-like script for default options, let's say /etc/autofs/defaults.msdosfs.  Or maybe one defaults file for all filesystems:

# /etc/autofs/special_media_defaults
msdosfs_mount_flags="-m=770,-L=ru_RU.UTF-8,-D=CP866"

We could maybe just use /etc/rc.conf for this as well.

I develop and maintain sysutils/auto-admin and sysutils/desktop-installer and I would really like a simple, scriptable way to make automount work out-of-the-box for all common filesystems.  It's one of the few remaining issues for basic desktop functionality in desktop-installer.
Comment 12 Victor Sudakov 2019-12-13 03:52:42 UTC
(In reply to Jason W. Bacon from comment #11)

> I develop and maintain sysutils/auto-admin and sysutils/desktop-installer 

I've used FreeBSD as desktop for over 20 years, and so has (nolens volens) my wife. I assure you, FreeBSD cannot be declared desktop-ready until there is an automounter for removable media working out of the box (supporting files with non-ascii names out of the box etc).

autofs has numerous problems, the worst being these:
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241531
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=242243
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241684
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=241474

Unless they are fixed, we cannot think about using autofs on desktop IMHO.

I'm aware of userland automounters in Gnome, Mate etc, but they are not Cyrillic-ready out of the box.
Comment 13 Jason W. Bacon freebsd_committer 2019-12-13 14:00:46 UTC
I agree.  So let's get the remaining issues fixed.

With the recent demise of TrueOS-Desktop (and Trident moving to a Linux base), I'm ramping up my efforts to improve both the functionality and UI of desktop-installer and make it suitable for a less geeky audience.

My two big remaining issues are external media and selecting a drm-kmod + video driver.  The latter may always require some sort of end-user intervention, but I think the autofs issues can be resolved pretty quickly.

My wife also uses a FreeBSD laptop, sometimes with Chinese characters.  It's doable, but needs to be made more easily configurable.  Most of the pieces are there in base and ports, but figuring out how to integrate them has taken some research.
Comment 14 Edward Tomasz Napierala freebsd_committer 2019-12-13 15:11:50 UTC
FWIW, most of those issues are not bugs in autofs itself, but in other pieces of software that autofs uses.  I'd prefer fixing them in the correct place instead of adding workarounds to autofs.

I wonder if we could just add a sysctl that would specify the default charset, user, group, file mode, and directory mode, to be used by filesystems that don't store this information, if it is not specified on the mount command line.  This way you would set it in sysctl.conf(5).  What do you guys think?
Comment 15 Jason W. Bacon freebsd_committer 2019-12-13 16:39:35 UTC
I'm all for fixing core issues/limitations rather than working around them.

The thought had crossed my mind that maybe end-users should be able specify default options for mount_msdosfs across-the-board rather than just for autofs.

As long as there are easy ways to customize these things and they're well-documented.
Comment 16 Jason W. Bacon freebsd_committer 2019-12-14 04:44:28 UTC
A sysctl may be the solution for some of the issues, but setting command-line flags via sysctl seems rather unconventional.

If we do this through autofs, which is a daemon, I would probably use rc.conf, e.g.

autofs_msdosfs_flags="-m=0660,-M0770"

To modify behavior of a command like mount_msdosfs, a config file and/or env variable would seem more intuitive.
Comment 17 Victor Sudakov 2019-12-14 06:33:55 UTC
(In reply to Jason W. Bacon from comment #16)
> autofs_msdosfs_flags="-m=0660,-M0770"

I second this.
Comment 18 Jason W. Bacon freebsd_committer 2019-12-14 15:30:45 UTC
(In reply to Victor Sudakov from comment #17)

If there's any resistance to hacking mount_*, this approach would be really easy to implement in special_media for now.  I would document in the code that it might be preferable to do it in mount_msdosfs instead.
Comment 19 Edward Tomasz Napierala freebsd_committer 2019-12-14 16:07:35 UTC
It's not about setting command-line arguments via sysctl; it's about setting a kernel parameter via sysctl instead of doing it via command line.

Also, I don't see a point in making it msdosfs-specific, instead of a global knob that applies to all permissionless filesystems.
Comment 20 Jason W. Bacon freebsd_committer 2019-12-14 19:38:34 UTC
(In reply to Edward Tomasz Napierala from comment #19)

Either way it seems a bit counterintuitive to me.  I.e., sysctl is not a place I would think to look for a solution to this problem.  Also, it's creating a redundant interface since the command-line flags already exist.  Are there existing examples of sysctls that mirror command-line flags?  If there are precedents for this sort of thing, I might be inclined to agree.

I definitely agree that one set of controls for all permissionless FSs is the way to go.  What other ones are there besides msdosfs?
Comment 21 Jason W. Bacon freebsd_committer 2020-01-02 01:15:43 UTC
Regarding the locale issue, it occurred to me that maybe mount_msdosfs should use LANG/LC_* from the env as a default.

It may already be doing so.  Looking at /usr/src/sbin/mount_msdosfs/mount_msdosfs.c, the -L flag merely calls setlocale():

                case 'L': {
                        const char *quirk = NULL;
                        if (setlocale(LC_CTYPE, optarg) == NULL)
                                err(EX_CONFIG, "%s", optarg);

Victor: Have you tried setting LANG or LC_CTYPE globally, so it's set for the automountd process and inherited by mount_*?

I'm not entirely sure that it's safe to set a non-default LANG for all root processes, but I'd like to know if setting it for automountd solves this issue.  Maybe as a quick test you could manually start the daemon with

service automountd stop
env LANG=ru_RU.UTF-8 automountd [flags]

As for the permissions issues, perhaps the mount directory should default to the ownership of /dev/console, which is set to the user currently running a session.  I think this would be more useful than root:wheel.

This still leaves some issues for multiuser installations, but I think allowing the local sysadmin to control mount options would take care of most of them.
Comment 22 Victor Sudakov 2020-01-03 13:50:23 UTC
(In reply to Jason W. Bacon from comment #21)
> Victor: Have you tried setting LANG or LC_CTYPE globally

Jason, I'm afraid you are not quite getting the point. 
There is the local charset which you can specify with -L or $LANG. That's correct but it's only a part of the matter. It's about how filenames are presented to the user.

The other part of the matter is how filenames are encoded on the filesystem itself. Most often is's either CP866  or WINDOWS-1251. That's where -D comes into play, and you cannot set -D via locale.
Comment 23 Jason W. Bacon freebsd_committer 2020-01-03 14:25:00 UTC
(In reply to Victor Sudakov from comment #22)

You're right, I did not fully understand the issue.  Just throwing out some ideas.  Thanks for the explanation.