From 212e85fb12b77ff71662d0ba9ceed8eabcde34a6 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Tue, 22 Sep 2009 14:58:34 +0200 Subject: [PATCH] libblkid: prefer ISO9660 PVD Label to Joliet Label The old good libvolume_id had the same behavior. Reported-by: Maxim Levitsky Signed-off-by: Karel Zak --- shlibs/blkid/src/probers/iso9660.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/shlibs/blkid/src/probers/iso9660.c b/shlibs/blkid/src/probers/iso9660.c index 1ea704c1..1ebcccf0 100644 --- a/shlibs/blkid/src/probers/iso9660.c +++ b/shlibs/blkid/src/probers/iso9660.c @@ -19,6 +19,7 @@ #include "blkidP.h" +/* PVD - Primary volume descriptor */ struct iso_volume_descriptor { unsigned char vd_type; unsigned char vd_id[5]; @@ -48,6 +49,20 @@ struct high_sierra_volume_descriptor { unsigned char volume_id[32]; }; +/* returns 1 if the begin of @ascii is equal to @utf16 string. + */ +static int ascii_eq_utf16be(unsigned char *ascii, + unsigned char *utf16, size_t len) +{ + int a, u; + + for (a = 0, u = 0; u < len; a++, u += 2) { + if (utf16[u] != 0x0 || ascii[a] != utf16[u + 1]) + return 0; + } + return 1; +} + /* old High Sierra format */ static int probe_iso9660_hsfs(blkid_probe pr, const struct blkid_idmag *mag) { @@ -96,6 +111,13 @@ static int probe_iso9660(blkid_probe pr, const struct blkid_idmag *mag) memcmp(iso->escape_sequences, "%/C", 3) == 0 || memcmp(iso->escape_sequences, "%/E", 3) == 0) { + /* Is the Joliet (UTF16BE) label equal to the label in + * the PVD? If yes, use PVD label. The Jolied version + * of the label could be trimed (because UTF16..). + */ + if (ascii_eq_utf16be(label, iso->volume_id, 32)) + break; + blkid_probe_set_utf8label(pr, iso->volume_id, sizeof(iso->volume_id), -- 2.39.5