Re: [BUG] Cdrom labels are always 'padded' with spaces at the end

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi Maxim,

On Tue, Sep 22, 2009 at 04:48:03AM +0300, Maxim Levitsky wrote:
> > However blkid_probe_set_label removes this whitespace, but
> > blkid_probe_set_utf8label don't.

 you're right. This is a bug.

> > Attached patch (against -git) just adds the whitespace removal to second
> > function.

 I have committed a little different version (see below).

 Please, use the "Signed-off-by:" line in your patches next time. For
 more details see README.devel in the package. Thanks.

> However there is additional problem,
> Problem is that Joliet label is saved in UTF-16, thus consists only of
> 16 chars, while, normal label is 32 chars wide.

> What you suggest to do?

 The old good libvolume_id had a nice solution. Unfortunately, I have
 forgot to port this solution to libblkid. It should be fixed now (see
 u-l-ng repository).

> Is that this important to use joilet label?

 We need to use Joliet label if the label is different to the label
 from (ISO9660) primary volume descriptor.

 It means that ASCII-only label should be always read from ISO9660
 primary volume descriptor, because this label is longer (32 chars).
 The Joliet label (16 chars) should be used for non-ASCII chars only.

 Thanks, we fix two bugs ;-)

    Karel


>From c2dbd49bdfd84e9145044ae564d5ef841e60a41e Mon Sep 17 00:00:00 2001
From: Karel Zak <kzak@xxxxxxxxxx>
Date: Tue, 22 Sep 2009 12:32:34 +0200
Subject: [PATCH] libblkid: trim tailing whitespace from unicode LABELs

old version:
	$ ./blkid -o udev -p iso-joliet.img
	ID_FS_LABEL=ThisIsLabel
	ID_FS_LABEL_ENC=ThisIsLabel\x20\x20\x20\x20\x20
	ID_FS_VERSION=Joliet\x20Extension
	ID_FS_TYPE=iso9660
	ID_FS_USAGE=filesystem

new version:
	$ ./blkid -o udev -p iso-joliet.img
	ID_FS_LABEL=ThisIsLabel
	ID_FS_LABEL_ENC=ThisIsLabel
	ID_FS_VERSION=Joliet\x20Extension
	ID_FS_TYPE=iso9660
	ID_FS_USAGE=filesystem

Reported-by: Maxim Levitsky <maximlevitsky@xxxxxxxxx>
Addresses-Ubuntu-Bug: #432215
Signed-off-by: Karel Zak <kzak@xxxxxxxxxx>
---
 shlibs/blkid/src/blkidP.h                  |    1 +
 shlibs/blkid/src/partitions/partitions.c   |   12 +++---------
 shlibs/blkid/src/probe.c                   |   24 ++++++++++++++++++++++++
 shlibs/blkid/src/superblocks/superblocks.c |   14 +++-----------
 4 files changed, 31 insertions(+), 20 deletions(-)

diff --git a/shlibs/blkid/src/blkidP.h b/shlibs/blkid/src/blkidP.h
index 10c2977..40002c5 100644
--- a/shlibs/blkid/src/blkidP.h
+++ b/shlibs/blkid/src/blkidP.h
@@ -413,6 +413,7 @@ extern int blkid_probe_sprintf_value(blkid_probe pr, const char *name,
                 const char *fmt, ...);
 
 extern void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len);
+extern size_t blkid_rtrim_whitespace(unsigned char *str);
 
 /* filter bitmap macros */
 #define blkid_bmp_wordsize		(8 * sizeof(unsigned long))
diff --git a/shlibs/blkid/src/partitions/partitions.c b/shlibs/blkid/src/partitions/partitions.c
index 94d1556..c1c3916 100644
--- a/shlibs/blkid/src/partitions/partitions.c
+++ b/shlibs/blkid/src/partitions/partitions.c
@@ -855,21 +855,13 @@ int blkid_partition_is_logical(blkid_partition par)
 static void set_string(unsigned char *item, size_t max,
 				const unsigned char *data, size_t len)
 {
-	int i;
-
 	if (len >= max)
 		len = max - 1;
 
 	memcpy(item, data, len);
 	item[len] = '\0';
 
-	/* remove trailing whitespace */
-	i = strlen((char *) item);
-	while (i--) {
-		if (!isspace(item[i]))
-			break;
-	}
-	item[++i] = '\0';
+	blkid_rtrim_whitespace(item);
 }
 
 int blkid_partition_set_name(blkid_partition par,
@@ -887,7 +879,9 @@ int blkid_partition_set_utf8name(blkid_partition par, const unsigned char *name,
 {
 	if (!par)
 		return -1;
+
 	blkid_encode_to_utf8(enc, par->name, sizeof(par->name), name, len);
+	blkid_rtrim_whitespace(par->name);
 	return 0;
 }
 
diff --git a/shlibs/blkid/src/probe.c b/shlibs/blkid/src/probe.c
index 05f61cf..bac4977 100644
--- a/shlibs/blkid/src/probe.c
+++ b/shlibs/blkid/src/probe.c
@@ -911,6 +911,9 @@ int blkid_probe_numof_values(blkid_probe pr)
  * @data: pointer to return value data or NULL
  * @len: pointer to return value length or NULL
  *
+ * Note, the @len returns length of the @data, including the terminating
+ * '\0' character.
+ *
  * Returns: 0 on success, or -1 in case of error.
  */
 int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
@@ -938,6 +941,9 @@ int blkid_probe_get_value(blkid_probe pr, int num, const char **name,
  * @data: pointer to return value data or NULL
  * @len: pointer to return value length or NULL
  *
+ * Note, the @len returns length of the @data, including the terminating
+ * '\0' character.
+ *
  * Returns: 0 on success, or -1 in case of error.
  */
 int blkid_probe_lookup_value(blkid_probe pr, const char *name,
@@ -1013,3 +1019,21 @@ void blkid_unparse_uuid(const unsigned char *uuid, char *str, size_t len)
 #endif
 }
 
+
+/* Removes whitespace from the right-hand side of a string (trailing
+ * whitespace).
+ *
+ * Returns size of the new string (without \0).
+ */
+size_t blkid_rtrim_whitespace(unsigned char *str)
+{
+	size_t i = strlen((char *) str);
+
+	while (i--) {
+		if (!isspace(str[i]))
+			break;
+	}
+	str[++i] = '\0';
+	return i;
+}
+
diff --git a/shlibs/blkid/src/superblocks/superblocks.c b/shlibs/blkid/src/superblocks/superblocks.c
index 0abdab2..077a733 100644
--- a/shlibs/blkid/src/superblocks/superblocks.c
+++ b/shlibs/blkid/src/superblocks/superblocks.c
@@ -467,8 +467,6 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
 {
 	struct blkid_chain *chn = blkid_probe_get_chain(pr);
 	struct blkid_prval *v;
-	int i;
-
 	if (len > BLKID_PROBVAL_BUFSIZ)
 		len = BLKID_PROBVAL_BUFSIZ;
 
@@ -487,14 +485,7 @@ int blkid_probe_set_label(blkid_probe pr, unsigned char *label, size_t len)
 	memcpy(v->data, label, len);
 	v->data[len] = '\0';
 
-	/* remove trailing whitespace */
-	i = strlen((char *) v->data);
-	while (i--) {
-		if (!isspace(v->data[i]))
-			break;
-	}
-	v->data[++i] = '\0';
-	v->len = i + 1;
+	v->len = blkid_rtrim_whitespace(v->data) + 1;
 	return 0;
 }
 
@@ -513,7 +504,8 @@ int blkid_probe_set_utf8label(blkid_probe pr, unsigned char *label,
 	if (!v)
 		return -1;
 
-	v->len = blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+	blkid_encode_to_utf8(enc, v->data, sizeof(v->data), label, len);
+	v->len = blkid_rtrim_whitespace(v->data) + 1;
 	return 0;
 }
 
-- 
1.6.2.5

--
To unsubscribe from this list: send the line "unsubscribe util-linux-ng" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html

[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux