[技術] 解決samba的charset問題

Written on 11:28 上午 by Yu Lai

就在9/11那天所po的"[技術] 在FreeBSD上掛載smbfs"中,其實有個問題沒有被提到,而是最近才解決的,那就是charset的問題。

在那台Linux上是採用zh_TW.Big5的編碼,其檔案系統也是採用Big5來儲存檔名。而在FreeBSD那台是採用zh_TW.UTF-8,自然的透過mount_smbfs來掛載會出現亂碼的問題,在經過測試,發現mount_smbfs -E的選項可說是無效..XD

所幸,解決的方法是根據samba的The Official Samba-3 HOWTO and Reference Guide中的
Chapter 30. Unicode/Charsets裡提到的:
As of Samba-3, Samba can (and will) talk Unicode over the wire. Internally, Samba knows of three kinds of character sets:

unix charset
This is the charset used internally by your operating system. The default is UTF-8, which is fine for most systems and covers all characters in all languages. The default in previous Samba releases was to save filenames in the encoding of the clients for example, CP850 for Western European countries.

display charset
This is the charset Samba uses to print messages on your screen. It should generally be the same as the unix charset.

dos charset
This is the charset Samba uses when communicating with DOS and Windows 9x/Me clients. It will talk Unicode to all newer clients. The default depends on the charsets you have installed on your system. Run testparm -v | grep "dos charset" to see what the default is on your system.

也就是只要將unix charset和display charset皆設為配合系統設定的Big5的CP950,然後在dos charset設為UTF-8,這樣透過mount_smbfs來掛載時就會自動轉成UTF-8的編碼了。而目前的成果自然就是FreeBSD上的pure-ftp (with utf-8 support)可以多很多東西囉。

If you enjoyed this post Subscribe to our feed

2 Comments

  1. Eric Chang |

    不好意思,可以請問你怎麼解決嗎?
    我測試了 mount_smbfs -E 的確是無效,但是又沒看到其他指定charset的方法??

     
  2. Yu Lai |

    Eric Chang你好,
    經過您的提問讓我發現原來我少寫一些說明。
    文章內的三個charset設定是設定在Linux那台的smb.conf之中。
    透過unix charset和display charset指定為CP950,讓samba server知道讀取filesystem時要使用Big5編碼將檔名正確讀出。
    而dos charset設為UTF-8,讓讀取到的檔名轉換成UTF-8編碼,讓client(mount_smbfs)能預設就讀取到UTF-8編碼的檔名,使之能正確顯示。

     

張貼留言