Due to a lot of file exchange works between Windows (GBK encoding) and Linux (UTF-8 encoding), it will encounter character encoding issues easily, such as:
- zip/tar files whose name contains chinese characters on Windows system, unzip/untar it in Linux system.
- run migrated legacy java web application (designed on Windows system, using GBK encoding in JSP) which write GBK-encoding-named files to disk.
- ftp get/put GBK-encoding-named files between Windows FTP server and Linux client.
- switch LANG environment in Linux.
The common issue of the previous mentioned are file locating/naming. After googled, I got an article Using Unicode in Linux http://www.linux.com/archive/feed/39912, it said:
the operating system and many utilities do not realize what characters the bytes in file names represent.
So, it's possible to have 2 中文.txt files with different encoding:
[root@fedora test]# ls
???? 中文
[root@fedora test]# ls | iconv -f GBK
中文
涓iconv: illegal input sequence at position 7
[root@fedora test]# ls 中文 && ls $'\xd6\xd0\xce\xc4'|iconv -f gbk
中文
中文
Questions:
- Is it possible to config linux filesystem use fixed character encoding (like NTFS use UTF-16 internally) to store file names regardless of LANG/LC_ALL environment?
- Or, what I actually want ask is: Is it possible to let file name 中文.txt (
$'\xe4\xb8\xad\xe6\x96\x87.txt') in zh_CN.UTF-8 environment and file name 中文.txt ($'\xd6\xd0\xce\xc4.txt') in zh_CN.GBK environment refer to same file? - If it's not configurable, then is it possible to patch kernel to translate character encoding between file-system and current environment (just a question, not request implementation)? and how much performance con effect if it's possible?