如何正确获取带中文的 fat32 U 盘卷标?


对于 ubuntu 系统,插入一个在 windows 下命名为 “usb 磁盘”的 fat32 U 盘,执行:


 ls /dev/disk/by-label

对应的 U 盘 label 显示为 “USB\x20\xb4\xc5\xc5\xcc”。usb 变为了大写,空格变为了 \x20,后面的 \xb4\xc5\xc5\xcc 不知是什么编码。

对于在搭载 angstrom beaglebone 的开发板上,我使用 udev 规则进行自动挂载:


 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}"

ls /media 的结果,对应的 mount point 为 USB_____。被转换为下划线了。

应该怎么正确获取到这个卷标呢?

fat32 Ubuntu 字符编码 Linux udev

duyaya 11 years, 2 months ago

插入一个在 windows 下命名为 “usb 磁盘”的 fat32 U 盘

后面的 \xb4\xc5\xc5\xcc 不知是什么编码。

编码是GBK。


 python2
>>> print(str('\x20\xb4\xc5\xc5\xcc').decode('gbk').encode('UTF-8'))
 磁盘

所以你获取到 \xb4\xc5\xc5\xcc 后转换一下即可。

wxklr answered 11 years, 2 months ago

Your Answer