summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian C. Lane <bcl@redhat.com>2014-05-16 10:23:28 -0700
committerBrian C. Lane <bcl@redhat.com>2014-05-19 10:01:21 -0700
commitd80457356f41f1abdf84733923113087068e9bca (patch)
tree899a44603331546a17b0d31139644c931678fa21
parent16bc3c1ea807f7a506d0500ba2de16686bee3426 (diff)
downloadparted-d80457356f41f1abdf84733923113087068e9bca.tar.gz
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
-rw-r--r--libparted/labels/gpt.c22
-rwxr-xr-xtests/t0251-gpt-unicode.sh2
2 files changed, 11 insertions, 13 deletions
diff --git a/libparted/labels/gpt.c b/libparted/labels/gpt.c
index 5c8df59..82eb58d 100644
--- a/libparted/labels/gpt.c
+++ b/libparted/labels/gpt.c
@@ -819,8 +819,7 @@ _parse_part_entry (PedDisk *disk, GuidPartitionEntry_t *pte)
gpt_part_data->type = pte->PartitionTypeGuid;
gpt_part_data->uuid = pte->UniquePartitionGuid;
for (i = 0; i < 36; i++)
- gpt_part_data->name[i] =
- (efi_char16_t) PED_LE16_TO_CPU ((uint16_t) pte->PartitionName[i]);
+ gpt_part_data->name[i] = (efi_char16_t) pte->PartitionName[i];
gpt_part_data->name[i] = 0;
gpt_part_data->translated_name = 0;
@@ -1237,8 +1236,7 @@ _partition_generate_part_entry (PedPartition *part, GuidPartitionEntry_t *pte)
pte->Attributes.LegacyBIOSBootable = 1;
for (i = 0; i < 36; i++)
- pte->PartitionName[i]
- = (efi_char16_t) PED_CPU_TO_LE16 ((uint16_t) gpt_part_data->name[i]);
+ pte->PartitionName[i] = gpt_part_data->name[i];
}
static int
@@ -1889,7 +1887,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;
@@ -1902,8 +1900,8 @@ gpt_partition_set_name (PedPartition *part, const char *name)
return;
err:
ped_exception_throw (PED_EXCEPTION_WARNING,
- PED_EXCEPTION_IGNORE,
- _("Can not translate partition name"));
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
iconv_close (conv);
}
@@ -1914,23 +1912,23 @@ 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;
+ goto err;
char *inbuff = (char *)&gpt_part_data->name;
char *outbuff = buffer;
size_t inbuffsize = 72;
size_t outbuffsize = sizeof(buffer);
if (iconv (conv, &inbuff, &inbuffsize, &outbuff, &outbuffsize) == -1)
- goto err;
+ goto err;
iconv_close (conv);
*outbuff = 0;
gpt_part_data->translated_name = xstrdup (buffer);
return gpt_part_data->translated_name;
err:
ped_exception_throw (PED_EXCEPTION_WARNING,
- PED_EXCEPTION_IGNORE,
- _("Can not translate partition name"));
+ PED_EXCEPTION_IGNORE,
+ _("Can not translate partition name"));
iconv_close (conv);
return "";
}
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