14

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?

Alex
  • 1,288
  • 2
    Check out the description of this patch in the Samba Mailing List. The described method is working out-of-the-box with Samba 4.1.4-Debian. – mpy Feb 08 '14 at 17:59
  • @mpy I've tried this but it still doesn't work for me when I copy files with illegal windows characters to my samba share. It works to only convert things that would've been OK (like a space converted to a symbol), but not for things that wouldn't work (like ':' converted to another symbol). Any pointers? – pd12 Apr 09 '16 at 16:42

3 Answers3

16

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.

Ryan
  • 25
  • 4
Emil
  • 161
  • I've tried this but it still doesn't work for me when I copy files with illegal windows characters to my samba share. It works to only convert things that would've been OK (like a space converted to a symbol), but not for things that wouldn't work (like ':' converted to another symbol). Any pointers? – pd12 Apr 09 '16 at 16:27
  • 2
    This works great! One thing to note is that you can not map everything to the same character, and in your example, anything that actullly has an underscore in it will no longer be accessible. Instead I used the following mappings: 0x3a:0x7e 0x3f:0x5e, so : becomes ~ and ? becomes ^. – Geoffrey May 12 '16 at 04:35
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)

Michael K
  • 13,888
  • They look better now. In fact, when I set "mangled names" to "no", the file names show up in Windows completely unchanged. While this certainly looks better, it also makes Windows applications unable to open the files. If I try to open a file tes:t.txt in Notepad, e.g., I am told "Cannot find the [...]\tes:t.txt file." Same goes with other "illegal" files in their respective applications. – Alex Nov 15 '11 at 08:58
  • edited my answer! – Michael K Nov 15 '11 at 09:05
  • mangled map has been removed from Samba. From what I can tell after a little looking around, it was removed years ago. This is what my log.smbd file says if I try to use it: Ignoring unknown parameter "mangled map" – Alex Nov 15 '11 at 09:33
  • You are right... deprecated. It won't work. It is not that simple - the complicated file name is to prevent having two files with the dame name. The file foo:.txt and foo_.txt could exist and then your renaming would fail. So the best would be to enforce file name rules such that only names are allowed which are allowed in both file systems. – Michael K Nov 15 '11 at 09:40
1

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.