From 77ce72ddf2bfbb34c8ef02ab955acbec20d643db Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Fri, 16 May 2014 10:23:28 -0700 Subject: [PATCH] GPT strings are UCS-2LE not UTF-16 There was a problem using UTF-16, it was writing the Byte Order Mark before the string which caused problems with older versions of parted reading the partition name. The test was skipping these 2 bytes when checking the written string. * libparted/labels/gpt.c: Switch to UCS-2LE for GPT Partition names * tests/t0251-gpt-unicode.sh: Update the test --- libparted/labels/gpt.c | 4 ++-- tests/t0251-gpt-unicode.sh | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c index 31f6d17..c19cb59 100644 --- a/libparted/labels/gpt.c +++ b/libparted/labels/gpt.c @@ -1891,7 +1891,7 @@ gpt_partition_set_name (PedPartition *part, const char *name) free(gpt_part_data->translated_name); gpt_part_data->translated_name = xstrdup(name); - iconv_t conv = iconv_open ("UTF-16", nl_langinfo (CODESET)); + iconv_t conv = iconv_open ("UCS-2LE", nl_langinfo (CODESET)); if (conv == (iconv_t)-1) goto err; char *inbuff = gpt_part_data->translated_name; @@ -1916,7 +1916,7 @@ gpt_partition_get_name (const PedPartition *part) if (gpt_part_data->translated_name == NULL) { char buffer[200]; - iconv_t conv = iconv_open (nl_langinfo (CODESET), "UTF-16"); + iconv_t conv = iconv_open (nl_langinfo (CODESET), "UCS-2LE"); if (conv == (iconv_t)-1) goto err; char *inbuff = (char *)&gpt_part_data->name; diff --git a/tests/t0251-gpt-unicode.sh b/tests/t0251-gpt-unicode.sh index 36a4c26..fbffbcb 100755 --- a/tests/t0251-gpt-unicode.sh +++ b/tests/t0251-gpt-unicode.sh @@ -31,7 +31,7 @@ parted -s $dev mklabel gpt mkpart primary ext2 1MiB 2MiB name 1 $part_name > emp compare /dev/null empty || fail=1 # check for expected output -dd if=$dev bs=1 skip=$(($sector_size_+$sector_size_+58)) count=10 2>/dev/null | od -An -tx1 > out || fail=1 +dd if=$dev bs=1 skip=$(($sector_size_+$sector_size_+56)) count=10 2>/dev/null | od -An -tx1 > out || fail=1 echo ' 66 00 6f 00 6f 00 24 1d 00 00' >> exp compare exp out || fail=1 -- 1.9.0