linux - 显示fat32 usb盘的卷标?

标签 linux ubuntu character-encoding udev fat32

在我的例子中,我将一个fat32 usb盘的卷标修改为“usb磁盘”(带有中文字符)。

然后我把U盘插到ubuntu(13.04)上,

ls /dev/disk/by-label

显示“USB\x20\xb4\xc5\xc5\xcc”。

或者,我使用 udev 规则在 angstrom beaglebone 上自动挂载外部 USB 磁盘。

IMPORT{program}="/sbin/blkid -o udev -p %N"
ENV{ID_FS_LABEL}!="", ENV{mount_point}="/media/%E{ID_FS_LABEL}"
ACTION=="add", RUN+="/bin/mkdir -p %E{mount_point}", RUN+="/bin/mount -o iocharset=utf8 /dev/%k %E{mount_point}"

我得到一个“/media/USB___”挂载点。

如何获得正确的卷标?

测试一个ntfs和ext3的u盘没问题。

最佳答案

FAT、VFAT 和 FAT32 似乎不使用 unicode 文件名——至少在我看来是这样。他们可以使用“OEM”代码页(我不完全理解)中的大多数字符,但即便如此,仍有许多字符无法显示。

Microsoft 页面对此进行了解释: http://msdn.microsoft.com/en-us/library/windows/desktop/dd317748%28v=vs.85%29.aspx

"NTFS stores file names in Unicode. In contrast, the older FAT12, FAT16, and FAT32 file systems use the OEM character set. For more information, see Code Pages.

"Non-Unicode applications that create FAT files sometimes have to use the standard C runtime library conversion functions to translate between the Windows code page character set and the OEM code page character set. With Unicode implementations of the file system functions, it is not necessary to perform such translations.

"Your application can use generic string types, as described in Windows Data Types for Strings. The application can also use generic function prototypes using techniques described in Conventions for Function Prototypes. For either generic string types or generic function prototypes, your application can use a single source file to compile either a Unicode or a non-Unicode version. To allow for this, the application provides macros for functions that are not invoked when compiling for Unicode.

"In both NTFS and FAT file systems, the special file name characters are: '\', '/', '.', '?', and '*'. On OEM code pages, these special characters are in the ASCII range of characters (0x00 through 0x7F). Their Unicode equivalents are the same values in a 2-byte form, 0x0000 through 0x007F.

"Caution Windows code page and OEM code page character sets used on Japanese-language operating systems contain the Yen symbol (¥) instead of a backslash (\). Thus, the Yen symbol is a prohibited character for NTFS and FAT file systems. When mapping Unicode to a Japanese-language code page, WideCharToMultiByte and other conversion functions map both backslash (U+005C) and the normal Unicode Yen symbol (U+00A5) to this same character. For security reasons, your applications should not typically allow the character U+00A5 in a Unicode string that might be converted for use as a FAT file name. For more information, see Security Considerations: International Features."

这个维基百科页面: http://en.wikipedia.org/wiki/Comparison_of_file_systems 让它更清晰一些

"Any byte except for values 0-31, 127 (DEL) and: " * / : < > ? \ | + , . ; = [] (lowcase a-z are stored as A-Z). With VFAT LFN any Unicode except NUL"

希望这对您有所帮助。

关于linux - 显示fat32 usb盘的卷标?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20969668/

相关文章:

linux - 如何在 shell 脚本中进行反向搜索

java - 为什么Tomcat不保留最小堆空间

ubuntu - 在选项卡或终端之间轻松复制/粘贴 vim

r - 在 Ubuntu 上的 R Shiny App 中读取环境变量的最简单方法是什么?

character-encoding - 具有 polymer 字符编码的Dartlang

java - Socket OutputStream 上的 PrintWriter 导致数据损坏/丢失

linux - 如何将文件从亚马逊 EC2 Linux vps 传输到 Windows 7 家用电脑

linux - 删除 tar 生成的尾随空字符

PHP 文件重命名为 JPG 并上传到服务器有威胁吗?

java - Puppet 启动 Tomcat 时汉字显示不正确,手动启动时可以正常工作