How to decode a USB device label

445 Views Asked by At

I am trying to get a USB device label from the udev library. But I have a problem when the label is not in UTF8 encoding.

The USB device was previously formatted on Windows and has the FAT32 file system. The USB name is “РФПАЦУ” (I used Cyrillic for test purposes (CP866 code page)). To get the USB device properties, I run the following command:

sudo /sbin/blkid -o udev -p /dev/sdd1

The answer is as follows:

ID_FS_LABEL=______
ID_FS_LABEL_ENC=\x90\x94\x8f\x80\x96\x93

According to https://bbs.archlinux.org/viewtopic.php?id=197582

ID_FS_LABEL contains plain ascii, with hex-escaped and any valid utf8 characters but all whitespaces are replaced with '_' , while in ID_FS_LABEL_ENC all potentially unsafe characters are replaced by the corresponding hex value prefixed by '\x'.

I cannot just unhex the ID_FS_LABEL_ENC since the amount of bytes to read is unknown.

Is there a way to find out the encoding of ID_FS_LABEL_ENC? Or a way to get the correct label of a USB device?

0

There are 0 best solutions below