Ubuntu – A human-friendlier Samba name mangling

samba

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?

Best Answer

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.