Skip to contentSkip to conversation

iterate return values

DISCUSSION Hollis Blanchard 3 participants 6 messages Feb 4, 2005

lore
Share & tools
lore
#0 lore raw

This one took waaay too long to track down. :( It is very difficult to debug when the problem is that grub_errno has a stale value.

This fixes my partition map problems, and has been tested both with Apple and DOS partition maps.

-Hollis

Index: ChangeLog
===================================================================
RCS file: /cvsroot/grub/grub2/ChangeLog,v
retrieving revision 1.90

ChangeLog +10 -0
diff -u -p -r1.90 ChangeLog
@@ -1,3 +1,13 @@
+2005-02-03  Hollis Blanchard  <[email protected]>
+
+	* kern/partition.c (grub_partition_probe): Clear `grub_errno' and
+	return 0 if `grub_errno' is GRUB_ERR_BAD_PART_TABLE. 
+	(part_map_iterate): Clear `grub_errno' and return 0 if
+	`partmap->iterate' returns GRUB_ERR_BAD_PART_TABLE. 
+	* partmap/amiga.c (amiga_partition_map_iterate): Return
+	GRUB_ERR_BAD_PART_TABLE if no partition map magic is found.
+	* partmap/apple.c (apple_partition_map_iterate): Likewise.
+
 2005-02-01  Guillem Jover  <[email protected]>
 
 	* loader/i386/pc/multiboot_normal.c (GRUB_MOD_INIT): Fix module

Index: kern/partition.c
===================================================================
RCS file: /cvsroot/grub/grub2/kern/partition.c,v
retrieving revision 1.1

partition.c +24 -7
diff -u -p -r1.1 partition.c
@@ -56,20 +56,28 @@ grub_partition_t
 grub_partition_probe (struct grub_disk *disk, const char *str)
 {
   grub_partition_t part;
-  
+
   auto int part_map_probe (const grub_partition_map_t partmap);
-  
+
   int part_map_probe (const grub_partition_map_t partmap)
     {
       part = partmap->probe (disk, str);
       if (part)
 	return 1;
-      return 0;
+
+      if (grub_errno == GRUB_ERR_BAD_PART_TABLE)
+	{
+	  /* Continue to next partition map type.  */
+	  grub_errno = GRUB_ERR_NONE;
+	  return 0;
+	}
+
+      return 1;
     }
 
   /* Use the first partition map type found.  */
   grub_partition_map_iterate (part_map_probe);
-  
+
   return part;
 }
 
@@ -78,12 +86,21 @@ grub_partition_iterate (struct grub_disk
 			int (*hook) (const grub_partition_t partition))
 {
   auto int part_map_iterate (const grub_partition_map_t partmap);
-  
+
   int part_map_iterate (const grub_partition_map_t partmap)
     {
-      return partmap->iterate (disk, hook);
+      grub_err_t err = partmap->iterate (disk, hook);
+
+      if (err == GRUB_ERR_BAD_PART_TABLE)
+	{
+	  /* Continue to next partition map type.  */
+	  grub_errno = GRUB_ERR_NONE;
+	  return 0;
+	}
+
+      return 1;
     }
-  
+
   grub_partition_map_iterate (part_map_iterate);
   return grub_errno;
 }

Index: partmap/amiga.c
===================================================================
RCS file: /cvsroot/grub/grub2/partmap/amiga.c,v
retrieving revision 1.1

amiga.c +4 -0
diff -u -p -r1.1 amiga.c
@@ -102,6 +102,10 @@ amiga_partition_map_iterate (grub_disk_t
 	  break;
 	}
     }
+
+  if (next == -1)
+    return grub_error (GRUB_ERR_BAD_PART_TABLE,
+		       "Amiga partition map not found.");
   
   /* The end of the partition list is marked using "-1".  */
   while (next != -1)

Index: partmap/apple.c
===================================================================
RCS file: /cvsroot/grub/grub2/partmap/apple.c,v
retrieving revision 1.1

apple.c +5 -2
diff -u -p -r1.1 apple.c
@@ -108,7 +108,7 @@ apple_partition_map_iterate (grub_disk_t
   raw.partition = 0;
 
   part.partmap = &grub_apple_partition_map;
-  
+
   for (;;)
     {
       if (grub_disk_read (&raw, pos / GRUB_DISK_SECTOR_SIZE,
@@ -134,6 +134,10 @@ apple_partition_map_iterate (grub_disk_t
       partno++;
     }
 
+  if ((pos / GRUB_DISK_SECTOR_SIZE) == 0)
+    return grub_error (GRUB_ERR_BAD_PART_TABLE,
+		       "Apple partition map not found.");
+
   return 0;
 }
 
@@ -178,7 +182,6 @@ apple_partition_map_probe (grub_disk_t d
  fail:
   grub_free (p);
   return 0;
-
 }
 
 
#1 lore raw
Quoted 2 lines · Hollis Blanchard

This one took waaay too long to track down. :( It is very difficult to debug when the problem is that grub_errno has a stale value.

It might be a good idea that grub_error can output an error immediately when debug mode is enabled.

Okuji

#2 lore raw
In reply to Hollis Blanchard
Quoted 5 lines · Hollis Blanchard

This one took waaay too long to track down. :( It is very difficult to debug when the problem is that grub_errno has a stale value.

This fixes my partition map problems, and has been tested both with Apple and DOS partition maps.

That's nice! There are a few comments. If you fixed those minor issues, feel free to commit the patch.

ChangeLog line 1

Quoted 12 lines

-Hollis

Index: ChangeLog
===================================================================
RCS file: /cvsroot/grub/grub2/ChangeLog,v
retrieving revision 1.90
diff -u -p -r1.90 ChangeLog

ChangeLog +1 -0
@@ -1,3 +1,13 @@
+2005-02-03  Hollis Blanchard  <[email protected]>

The changelog is fine for me, but please don't send it in as a patch.

ChangeLog line 4

Quoted 5 lines
ChangeLog +2 -2
-  
+
   auto int part_map_probe (const grub_partition_map_t partmap);
-  
+

Please watch out for changes like these.

ChangeLog line 10

Quoted 6 lines
ChangeLog +6 -0
+      if (err == GRUB_ERR_BAD_PART_TABLE)
+	{
+	  /* Continue to next partition map type.  */
+	  grub_errno = GRUB_ERR_NONE;
+	  return 0;
+	}

This looks like a tab, please don't use tabs. I hope you can fix it if that is the case and the same for the rest of the patch, if the same happened there.

Thanks,
Marco

#3 lore raw
Quoted 1 line · Marco Gerards

The changelog is fine for me, but please don't send it in as a patch.

For me, it is fine to include ChangeLog entries in a patch. What is wrong?

Quoted 3 lines

This looks like a tab, please don't use tabs. I hope you can fix it if that is the case and the same for the rest of the patch, if the same happened there.

Hmmh, I think I use tabs, too. Should I stop using tabs inside GRUB? In the past, tabs were prefered, because using only spaces enlarged the source code and the network bandwidth was extremely narrow. Nowadays, these reasons are not effective any longer.

Okuji

#4 lore raw
Quoted 5 lines · Yoshinori K. Okuji
Quoted 1 line · Marco Gerards

The changelog is fine for me, but please don't send it in as a patch.

For me, it is fine to include ChangeLog entries in a patch. What is wrong?

When you apply the patch it can not be applied when the changelog was changed by another commit.

Quoted 8 lines
Quoted 3 lines

This looks like a tab, please don't use tabs. I hope you can fix it if that is the case and the same for the rest of the patch, if the same happened there.

Hmmh, I think I use tabs, too. Should I stop using tabs inside GRUB? In the past, tabs were prefered, because using only spaces enlarged the source code and the network bandwidth was extremely narrow. Nowadays, these reasons are not effective any longer.

Perhaps I am just confused. I was under the impression the GCS forces you to use spaces, but I can't find anything about it. And emacs creates tabs too when indenting. So it seems I was just very wrong.

Sorry for the confusion.

Thanks,
Marco

#5 lore raw
Quoted 5 lines · Marco Gerards
Quoted 2 lines

For me, it is fine to include ChangeLog entries in a patch. What is wrong?

When you apply the patch it can not be applied when the changelog was changed by another commit.

In that case, you just get it from ChangeLog.rej, no?

I think our opinions are different because I rarely use the command "patch" to apply patches for development. I usually apply patches by hand, since I always want to modify patches more or less before applying them. This might be solved if I start complaining a lot in order to let contributors modify patches as I wish, but I think most of them would be merely scared and rush way...

Quoted 4 lines

Perhaps I am just confused. I was under the impression the GCS forces you to use spaces, but I can't find anything about it. And emacs creates tabs too when indenting. So it seems I was just very wrong.

But you are right actually, since tabs are mostly useless and rather confusing.

Okuji