A human-friendlier Samba name mangling

Most of our computers run Ubuntu, but two of them dual-boot into Windows, and when we have guests over, they typically also run Windows computers. Thus, in addition to using NFS, our file server (Ubuntu server) also runs Samba.

And since we use Ubuntu mostly, we like to take advantage of its advantages over Windows, such as being able to use the characters \:*?"<>| in a file name. The problem, of course, is that Windows doesn't accept those characters in file names, and so Samba has to translate the file name into something more acceptable. The way it does this, however, I find to be obnoxious.

The file name Episode 182 - Exorcist 2: The Heretic.mp4 for instance turns into E4Q82R~Y.MP4. This is a terrible "correction". Is there a way to make Samba's mangling a little more friendly to humans? Is possible to "correct" it to something like Episode 182 - Exorcist 2_ The Heretic.mp4 instead, where the illegal characters are simply substituted?


Solution 1:

mangled map is now deprecated and will no longer work in new versions of Samba.

You can use vfs_catia to solve the problem. Add the following lines to smb.conf:

vfs objects = catia
catia:mappings = 0x003a:0x2236,0x003f:0x0294,0x002a:0x2217,0x003c:0x276e,0x003e:0x276f,0x0022:0x02ba,0x007c:0x2223,0x005c:0x29f9

Mapping is specified with 0x prefixed hexedecimal character codes separated by a colon. The provided mapping will remap illegal characters to unicode lookalikes that are unlikely to be used in any language.

: ? * < > " | \
∶ ʔ ∗ ❮ ❯ ʺ ∣ ⧹

The code can be put under [global] or in an individual [share] section. Placing it in [global] may impact performance.

Note that any character you map to cannot be used in filenames on the server or they will be inaccessible.

Example: A windows client accessing a file named file❮name.txt on the server will request file<name.txt from the server due to the mapping, which will result in a file not found error.

Solution 2:

In this link you can see the mangling options. I think first you should disable the option:

mangled names

After that I guess the names should look better...

To replace the colon e.g. use this line:

mangled map =(: _)

You can add more replace rules like this:

mangled map =(: _) (foo bar)

(also replaces any occurence of foo by bar)

Solution 3:

Newer POSIX clients (at least Linux and macOS) don’t need manually character mapping, and can instead mutually cooperate with the server so filenames with NTFS reserved characters work just fine. Per Samba docs, and the man pages:

On the server (see man vfs_fruit):

vfs objects = catia fruit
fruit:encoding = native

On the client, it may be necessary to mount with the mapposix* option (see man mount.cifs).


*It seems like mapchars should be the correct option, but with testing, mapposix is what works.