Skip to contentSkip to conversation

skip over invalid BSD partitions

PATCH In review Felix Zielcke 4 participants 11 messages Jul 30, 2008 – Aug 5, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 skip over invalid BSD partitions

On invalid BSD partitions partmap/pc.c stops with reading the partitons, so grub doestn't know anything about the ones behind it. Attached patch fixes this and displays also the partition number not only the invalid magic it encounters

2008-07-31 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Skip over invalid BSD partitions or if there's no space for the disk label and print the partition number on a invalid magic

pc.c +11 -7
Index: partmap/pc.c
===================================================================
@@ -160,9 +160,11 @@
 		{
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_error (GRUB_ERR_BAD_PART_TABLE,
+				  "no space for disk label");
+		      continue;
+		    }
 		  /* Read the BSD label.  */
 		  if (grub_disk_read (&raw,
 				      (p.start
@@ -175,10 +177,12 @@
 		  /* Check if it is valid.  */
 		  if (label.magic
 		      != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "invalid disk label magic 0x%x",
-				       label.magic);
-
+		    {
+		      grub_error (GRUB_ERR_BAD_PART_TABLE,
+				  "invalid disk label magic 0x%x on partition %d",
+				  label.magic,p.index);
+		      continue;
+		    }
 		  for (pcdata.bsd_part = 0;
 		       pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
 		       pcdata.bsd_part++)
#1 lore raw
Quoted 10 lines · Felix Zielcke

On invalid BSD partitions partmap/pc.c stops with reading the partitons, so grub doestn't know anything about the ones behind it. Attached patch fixes this and displays also the partition number not only the invalid magic it encounters

2008-07-31 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Skip over invalid BSD partitions or if there's no space for the disk label and print the partition number on a invalid magic

When does this occur?

Quoted 6 lines

Index: partmap/pc.c
===================================================================

pc.c +0 -0
@@ -160,9 +160,11 @@
 		{

pc.c line 167

Quoted 10 lines
pc.c +5 -3
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_error (GRUB_ERR_BAD_PART_TABLE,
+				  "no space for disk label");
+		      continue;
+		    }

If you continue as no error occured, why do you throw an error?

--
Marco

#2 lore raw

Am Freitag, den 01.08.2008, 12:40 +0200 schrieb Marco Gerards:

Quoted 2 lines

When does this occur?

That's the Debian bugreport for it:

http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=478238

It's very easy to reproduce.
I never used any *BSD flavour just Linux so I even didn't know about these BSD subpartitions or whatever these are.
I made a new partition table with Linux fdisk
Set the first partition to type 0x6a for OpenBSD
then the second one to type 0x83 for Linux
formated 2. with ext2
tested it with grub-probe and grub-emu
It failed to detect it because the for() stops reading further partitions if the BSD one is invalid.

Quoted 3 lines

If you continue as no error occured, why do you throw an error?

I thought it would be a good idea to give the user a warning that something is wrong with that partition which has a BSD type. At least the return is wrong see above.

#3 lore raw
In reply to Marco Gerards
Quoted 10 lines · Marco Gerards

pc.c line 167

Quoted 8 lines
pc.c +5 -3
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_error (GRUB_ERR_BAD_PART_TABLE,
+				  "no space for disk label");
+		      continue;
+		    }

If you continue as no error occured, why do you throw an error?

Uhm nobody's going to handle this error. The caller will simply see that some partitions are not processed.

How about using grub_dprintf instead?

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."
#4 lore raw
Quoted 12 lines · Robert Millan
Quoted 10 lines · Marco Gerards

pc.c line 167

Quoted 8 lines
pc.c +5 -3
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_error (GRUB_ERR_BAD_PART_TABLE,
+				  "no space for disk label");
+		      continue;
+		    }

If you continue as no error occured, why do you throw an error?

Quoted 4 lines

Uhm nobody's going to handle this error. The caller will simply see that some partitions are not processed.

How about using grub_dprintf instead?

Agreed.

--
Marco

#5 lore raw

Am Dienstag, den 05.08.2008, 12:16 +0200 schrieb Marco Gerards:

Quoted 7 lines
Quoted 2 lines · Robert Millan

How about using grub_dprintf instead?

Agreed.

Attached.
I hope I get soon used to your changelog :)

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

pc.c +10 -7
Index: partmap/pc.c
===================================================================
@@ -160,9 +160,10 @@
 		{
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_dprintf ("partition","no space for disk label\n");
+		      continue;
+		    }
 		  /* Read the BSD label.  */
 		  if (grub_disk_read (&raw,
 				      (p.start
@@ -175,10 +176,12 @@
 		  /* Check if it is valid.  */
 		  if (label.magic
 		      != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "invalid disk label magic 0x%x",
-				       label.magic);
-
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic,p.index);
+		      continue;
+		    }
 		  for (pcdata.bsd_part = 0;
 		       pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
 		       pcdata.bsd_part++)
#6 lore raw

Am Dienstag, den 05.08.2008, 12:49 +0200 schrieb Felix Zielcke:

Quoted 10 lines

Am Dienstag, den 05.08.2008, 12:16 +0200 schrieb Marco Gerards:

Quoted 7 lines
Quoted 2 lines · Robert Millan

How about using grub_dprintf instead?

Agreed.

Attached.

I forgot 2 little spaces ;)

Quoted 3 lines

I hope I get soon used to your changelog :)

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

pc.c +10 -7
Index: partmap/pc.c
===================================================================
@@ -160,9 +160,10 @@
 		{
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_dprintf ("partition", "no space for disk label\n");
+		      continue;
+		    }
 		  /* Read the BSD label.  */
 		  if (grub_disk_read (&raw,
 				      (p.start
@@ -175,10 +176,12 @@
 		  /* Check if it is valid.  */
 		  if (label.magic
 		      != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "invalid disk label magic 0x%x",
-				       label.magic);
-
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }
 		  for (pcdata.bsd_part = 0;
 		       pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
 		       pcdata.bsd_part++)
#7 lore raw
Quoted 4 lines · Felix Zielcke

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

Looks fine.

pc.c line 184

Quoted 6 lines
pc.c +6 -0
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }

Isn't a comma missing after the second string? I am surprised that this compiles. Or am I missing something?

--
Marco

#8 lore raw

Am Dienstag, den 05.08.2008, 15:10 +0200 schrieb Marco Gerards:

Quoted 8 lines
Quoted 4 lines · Felix Zielcke

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

Looks fine.

Hurray.

Quoted 11 lines

Review

Quoted 7 lines
(quoted diff) +6 -0
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }

Isn't a comma missing after the second string? I am surprised that this compiles. Or am I missing something?

Bah, I noticed the 2 missing spaces and then missed that one out :( Attached.

pc.c +10 -7
Index: partmap/pc.c
===================================================================
@@ -160,9 +160,10 @@
 		{
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_dprintf ("partition", "no space for disk label\n");
+		      continue;
+		    }
 		  /* Read the BSD label.  */
 		  if (grub_disk_read (&raw,
 				      (p.start
@@ -175,10 +176,12 @@
 		  /* Check if it is valid.  */
 		  if (label.magic
 		      != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "invalid disk label magic 0x%x",
-				       label.magic);
-
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }
 		  for (pcdata.bsd_part = 0;
 		       pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
 		       pcdata.bsd_part++)
#9 lore raw
In reply to Marco Gerards

Am Dienstag, den 05.08.2008, 15:10 +0200 schrieb Marco Gerards:

Quoted 8 lines
Quoted 4 lines · Felix Zielcke

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

Looks fine.

Hurray.

Quoted 10 lines

Review

Quoted 6 lines
(quoted diff) +6 -0
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }

Isn't a comma missing after the second string? I am surprised that this compiles. Or am I missing something?

You're right, shame on me I notice to missing spaces but not a missing comma.
Attached.

pc.c +10 -7
Index: partmap/pc.c
===================================================================
@@ -160,9 +160,10 @@
 		{
 		  /* Check if the BSD label is within the DOS partition.  */
 		  if (p.len <= GRUB_PC_PARTITION_BSD_LABEL_SECTOR)
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "no space for disk label");
-
+		    {
+		      grub_dprintf ("partition", "no space for disk label\n");
+		      continue;
+		    }
 		  /* Read the BSD label.  */
 		  if (grub_disk_read (&raw,
 				      (p.start
@@ -175,10 +176,12 @@
 		  /* Check if it is valid.  */
 		  if (label.magic
 		      != grub_cpu_to_le32 (GRUB_PC_PARTITION_BSD_LABEL_MAGIC))
-		    return grub_error (GRUB_ERR_BAD_PART_TABLE,
-				       "invalid disk label magic 0x%x",
-				       label.magic);
-
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n",
+				    label.magic, p.index);
+		      continue;
+		    }
 		  for (pcdata.bsd_part = 0;
 		       pcdata.bsd_part < grub_cpu_to_le16 (label.num_partitions);
 		       pcdata.bsd_part++)
#10 lore raw
Quoted 21 lines · Felix Zielcke

Am Dienstag, den 05.08.2008, 15:10 +0200 schrieb Marco Gerards:

Quoted 8 lines
Quoted 4 lines · Felix Zielcke

2008-08-05 Felix Zielcke <[email protected]>

* partmap/pc.c (pc_partition_map_iterate): Do not abort on an invalid BSD magic or if there's no space left, use grub_dprintf to issue a warning.

Looks fine.

Hurray.

Quoted 10 lines

pc.c line 184

Quoted 6 lines
pc.c +6 -0
+		    {
+		      grub_dprintf ("partition",
+				    "invalid disk label magic 0x%x on partition %d\n"
+				    label.magic, p.index);
+		      continue;
+		    }

Isn't a comma missing after the second string? I am surprised that this compiles. Or am I missing something?

Quoted 3 lines

You're right, shame on me I notice to missing spaces but not a missing comma.
Attached.

Seems fine to me :-)

--
Marco