Skip to contentSkip to conversation

Remove trailing space from FAT label

PATCH phcoder 3 participants 4 messages Feb 4, 2009 – Feb 7, 2009

lore
Share & tools
lore

phcoder

author
#0 lore raw

Hello. Here is the patch to remove trailing spaces from FAT label. These spaces generally aren't considiered to be part of label Thanks
Vladimir 'phcoder' Serbinenko

fat.c +7 -1
Index: fs/fat.c
===================================================================
@@ -809,7 +809,13 @@
 
       if (dir.attr == GRUB_FAT_ATTR_VOLUME_ID)
 	{
-	  *label = grub_strndup ((char *) dir.name, 11);
+	  int labellen = 0, i;
+	  for (i = 0; i < 11; i++)
+	    if (dir.name[i] != ' ')
+	      labellen = i + 1;
+
+	  *label = grub_strndup ((char *) dir.name, labellen);
+	  
 	  return GRUB_ERR_NONE;
 	}
     }
ChangeLog +6 -0
Index: ChangeLog
===================================================================
@@ -1,3 +1,9 @@
+2009-02-04  Vladimir Serbinenko  <[email protected]>
+
+	Remove trailing spaces from FAT label
+
+	* fs/fat.c (grub_fat_label): Remove trailing spaces
+
 2009-02-04  Felix Zielcke  <[email protected]>
 
 	util/getroot.c (grub_util_get_grub_dev): Add support for /dev/mdNpN and
#1 lore raw
Quoted 2 lines · phcoder

Hello. Here is the patch to remove trailing spaces from FAT label. These spaces generally aren't considiered to be part of label

Suppose the label is "DOS \0DDDDDDDD", then your algorithm will fail to strip the final space, as it would iterate past the binary null. I don't know if it can happen, but I guess it's better to be prepared.

Also, please see how ordinary 8.3 filenames are handled. Look for "8.3" in fs/fat.c. grub_isspace() is used to check for spaces. Binary nulls and spaces terminate the name. There may be no spaces anywhere in the name.

Perhaps we could use the same mechanism for the label except that no "." is added.

Signature · 2 lines
Regards,
Pavel Roskin
author
#2 lore raw

Hello

Quoted 1 line

Suppose the label is "DOS \0DDDDDDDD",

Such a label is incorrect. But I agree with you that we should reuse the
code and be fault-tolerant (I regularly see FAT volumes breaking the
specifications). Additionally there is a mechanism of nice fat label which works the same way as long names (supported only by some OS). Unifying the code would make these labels accessible. So I'll write a new proposition soon. Thanks
Vladimir 'phcoder' Serbinenko

#3 lore raw
In reply to phcoder
Quoted 10 lines · phcoder

Hello. Here is the patch to remove trailing spaces from FAT label. These spaces generally aren't considiered to be part of label Thanks
Vladimir 'phcoder' Serbinenko

Index: fs/fat.c
===================================================================

fat.c line 813

Quoted 6 lines
fat.c +2 -1
@@ -809,7 +809,13 @@
 
       if (dir.attr == GRUB_FAT_ATTR_VOLUME_ID)
 	{
-	  *label = grub_strndup ((char *) dir.name, 11);
+	  int labellen = 0, i;
+	  for (i = 0; i < 11; i++)

Please use a descriptive macro instead of hardcoding 11.

Signature · 5 lines
Robert Millan

  The DRM opt-in fallacy: "Your data belongs to us. We will decide when (and
  how) you may access your data; but nobody's threatening your freedom: we
  still allow you to remove your data and not access it at all."