# USB drives: foreign language file names



## free-and-bsd (Apr 3, 2017)

Hi everyone.

I'm just posting this here because I've been experiencing this problem for quite some time and it was extremely difficult to find the solution.

When inserting a USB flash drive it's mounted with mount_msdosfs(8). But the Handbook fails to mention that unless you supply -L for locale and -D for DOS codepage all your Russian/French/Korean etc, file names will appear as ?????.ext and you won't be able to handle them.

One needs to use syntax like this:

```
mount_msdosfs -L ja_JP.eucJP -D CP932 /dev/ada1s1 /mnt
```
 (for Japanese)

Now why is this not mentioned anywhere in the relevant sources? Until I've recently found it in mount_msdosfs(8) I had to rename all files to English names. This one's especially tricky for former Windows users.

Another question: how can corresponding rules (or maps?) be added to the autofs (5) ? The working of these maps seems obscure to me when I try to go beyond the /etc/auto_master file basics.


----------



## scottro (Apr 3, 2017)

I wonder if changing that to en_US.UTF-8 might work.  I've not seen EUC used in Japanese encoding in awhile, but I don't see that much Japanese encoding.
And if not en_US.UTF-8 (which, as an LC_CTYPE, usually works for me in viewing Japanese or writing it to someone using a Mac to read it), ja_JP.UTF-8.  If you have time  and inclination  let me know if it works on the same files that the EUC stuff worked on.


----------



## free-and-bsd (Apr 3, 2017)

scottro said:


> I wonder if changing that to en_US.UTF-8 might work.  I've not seen EUC used in Japanese encoding in awhile, but I don't see that much Japanese encoding.
> And if not en_US.UTF-8 (which, as an LC_CTYPE, usually works for me in viewing Japanese or writing it to someone using a Mac to read it), ja_JP.UTF-8.  If you have time  and inclination  let me know if it works on the same files that the EUC stuff worked on.


It does, even without mentioning the -D for DOS codepage -- at least for Russian names. Can't test that on Korean right now, but I guess it will work there as well.

The Japanese example is taken from the mount_msdosfs(8) man page, I used Korean.

On the other hand, in my user environment LANG _is_ set to en_US.UTF-8. I think this comes from the system wide /etc/login.conf settings?


----------



## scottro (Apr 3, 2017)

Ah, Ok. Thanks for taking the time to explain.  I'm not an expert (I only play with it with my own user environment), but that sounds logical.


----------



## free-and-bsd (Apr 4, 2017)

scottro said:


> Ah, Ok. Thanks for taking the time to explain.  I'm not an expert (I only play with it with my own user environment), but that sounds logical.


No, you are always ready to help and very quick in that, too. Thank you so much .

Still, it's not clear to me why I have to explicitly supply this settings on command line when it's set system wide... And perhaps other people DON'T have this same problem because for them it _does_ work the way it should for me? That is more than likely.

In the past I used to have edited /etc/login.conf, but now I'm using the one supplied by the distribution. So nothing special there. Same with setting system locale etc. -- nothing out of the way.


----------



## free-and-bsd (Feb 15, 2019)

Ok, doing this through the new automount facility seems rather straightforward. Just edit /etc/auto_master file and modify the line:
`/media  -media  -nosuid`
to
`/media   -media  -nosuid,fstype=msdosfs,-L=ru_RU.UTF-8`

The only problem I see is that still the USB drive will be mounted not writable to unprivileged user. In spite of vfs.usermount=1 set in /etc/sysctl.conf.

EDIT: wanted to add that this process creates "final" mountpoint under specified directory (/media), and no matter who owns that one, the one created will be owned by root:wheel. So, it mounts inserted USB drives automatically upon entering that dir in a file browser, but it remains not writable nor umount-able by regular user. Which kind of limits its usability, I should think.


----------



## free-and-bsd (Feb 18, 2019)

Ok, to continue the matter of the correct display of file names in foreign languages. 

When I get my USB drive mounted using msdosfs option `-L=$specific_locale`, it will then display ALL foreign filenames correctly (apart from English, it's Korean and Russian in my case). But the filename that's not in the $specific_locale it will not be able to determine the file type. So in console the output of `ls $mnt_dir` will look like this (mounted with -L=ru_RU.UTF-8):
`$>ls /media/da0s1
ls: BD-N443-사용설명서.pdf: Invalid argument
69-версия-1.odt           System Volume Information`
Notice "invalid argument" against the file named in Korean here. And when trying to remove the Korean-named file you get refusal with the same output:
`$>rm /media/da0s1/*pdf
rm: /media/da0s1/BD-N443-사용설명서.pdf: Invalid argument`
Needless to say, this doesn't happen in MS Windows with USB drives at all, nor in FreeBSD on the normal filesystem (not USB flash).

So I wonder if this problem is considered unsolvable, unimportant or what. Whoever is working with files in multiple languages will have to face it, right?


----------



## free-and-bsd (Feb 18, 2019)

Well I just wonder how this is achieved under MS Windows (10, for example), where the FAT32-formatted (mount_msdosfs and msdosfs_iconv.ko in FreeBSD) USB drives display all language names correctly when mounted.


----------



## Vull (Feb 18, 2019)

You might want to try the sysutils/automount port which automatically mounts removable FAT32 USB drives, and also allows you to specify your character encoding and/or codepage in the file /usr/local/etc/automount.conf. This not the same software as that which is used in the base system's `automount` command, and requires very little configuration. The version in packages and ports is presently 1.5.8 which works fine in FreeBSD version 11.2, but if you're using  FreeBSD 12.0 you'll need to install the sysutils/automount version 1.6.0 or higher, which you can download and easily install from this download page: https://github.com/vermaden/automount

You can specify any non-root user name and get full write privileges for that user. I use the encoding en_US.UTF-8 but you should be able to specify any other encoding you like. The default contents of automount.conf are:
	
	



```
USERUMOUNT=YES
ATIME=NO
REMOVEDIRS=YES
FM="caja --browser --no-desktop"
USER=vermaden
ENCODING=pl_PL.ISO8859-2
CODEPAGE=cp852
```


----------



## free-and-bsd (Feb 18, 2019)

Yes, currently I'm using that program, and very thankful for it, too.


----------

