aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorandroid-build-team Robot <android-build-team-robot@google.com>2018-04-10 07:23:16 +0000
committerandroid-build-team Robot <android-build-team-robot@google.com>2018-04-10 07:23:16 +0000
commit17f5668746220291e97b3774e70a9df135021f09 (patch)
treeb3f1b739c12c9755702c62c70f747ea7c590e393
parentca21ef5b9f5069a3e0a5ecc9f6a88aa2156d2778 (diff)
parent25715073b170970469126426196c9e5084613c37 (diff)
downloade2fsprogs-17f5668746220291e97b3774e70a9df135021f09.tar.gz
Snap for 4710485 from 25715073b170970469126426196c9e5084613c37 to pi-release
Change-Id: Icbffb5ceaf0a47a7cab0ba650e079aef9fe85bc2
-rw-r--r--lib/blkid/probe.c35
1 files changed, 34 insertions, 1 deletions
diff --git a/lib/blkid/probe.c b/lib/blkid/probe.c
index 865d9aa3..0293b903 100644
--- a/lib/blkid/probe.c
+++ b/lib/blkid/probe.c
@@ -1160,6 +1160,37 @@ static void unicode_16be_to_utf8(unsigned char *str, int out_len,
str[j] = '\0';
}
+static void unicode_16le_to_utf8(unsigned char *str, int out_len,
+ const unsigned char *buf, int in_len)
+{
+ int i, j;
+ unsigned int c;
+
+ for (i = j = 0; i + 2 <= in_len; i += 2) {
+ c = (buf[i+1] << 8) | buf[i];
+ if (c == 0) {
+ str[j] = '\0';
+ break;
+ } else if (c < 0x80) {
+ if (j+1 >= out_len)
+ break;
+ str[j++] = (unsigned char) c;
+ } else if (c < 0x800) {
+ if (j+2 >= out_len)
+ break;
+ str[j++] = (unsigned char) (0xc0 | (c >> 6));
+ str[j++] = (unsigned char) (0x80 | (c & 0x3f));
+ } else {
+ if (j+3 >= out_len)
+ break;
+ str[j++] = (unsigned char) (0xe0 | (c >> 12));
+ str[j++] = (unsigned char) (0x80 | ((c >> 6) & 0x3f));
+ str[j++] = (unsigned char) (0x80 | (c & 0x3f));
+ }
+ }
+ str[j] = '\0';
+}
+
static int probe_hfs(struct blkid_probe *probe __BLKID_ATTR((unused)),
struct blkid_magic *id __BLKID_ATTR((unused)),
unsigned char *buf)
@@ -1482,7 +1513,9 @@ static int probe_exfat(struct blkid_probe *probe, struct blkid_magic *id,
label = find_exfat_entry_label(probe, sb);
if (label) {
- blkid_set_tag(probe->dev, "LABEL", label->name, label->length);
+ char utf8_label[128];
+ unicode_16le_to_utf8(utf8_label, sizeof(utf8_label), label->name, label->length * 2);
+ blkid_set_tag(probe->dev, "LABEL", utf8_label, 0);
} else {
blkid_set_tag(probe->dev, "LABEL", "disk", 4);
}