Skip to contentSkip to conversation

simplify partmap probe

PATCH In review Robert Millan 1 participant 2 messages Feb 6, 2008

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 simplify partmap probe

Simplification for partmap probing function.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)

* util/grub-probe.c (probe): Simplify partmap probing (with the assumption that the first word up to the underscore equals to the module name).

util/grub-probe.c renamed from grub2/util/grub-probe.c +13 -12
diff -x configure -x config.h.in -x CVS -x '*~' -x '*.mk' -urp ../grub2/util/grub-probe.c ./util/grub-probe.c
@@ -133,21 +133,22 @@ probe (const char *path)
 
   if (print == PRINT_PARTMAP)
     {
+      char *name;
+      char *underscore;
+      
       if (dev->disk->partition == NULL)
         grub_util_error ("Cannot detect partition map for %s", drive_name);
 
-      if (strcmp (dev->disk->partition->partmap->name, "amiga_partition_map") == 0)
-        printf ("amiga\n");
-      else if (strcmp (dev->disk->partition->partmap->name, "apple_partition_map") == 0)
-        printf ("apple\n");
-      else if (strcmp (dev->disk->partition->partmap->name, "gpt_partition_map") == 0)
-        printf ("gpt\n");
-      else if (strcmp (dev->disk->partition->partmap->name, "pc_partition_map") == 0)
-        printf ("pc\n");
-      else if (strcmp (dev->disk->partition->partmap->name, "sun_partition_map") == 0)
-        printf ("sun\n");
-      else
-        grub_util_error ("Unknown partition map %s", dev->disk->partition->partmap->name);
+      name = strdup (dev->disk->partition->partmap->name);
+      if (! name)
+	grub_util_error ("not enough memory");
+
+      underscore = strchr (name, '_');
+      if (! underscore)
+	grub_util_error ("Invalid partition map %s", name);
+
+      *underscore = '\0';
+      printf ("%s\n", name);
       goto end;
     }
 
#1 lore raw
Quoted 2 lines · Robert Millan

Simplification for partmap probing function.

Committed.

Signature · 5 lines
Robert Millan

<GPLv2> I know my rights; I want my phone call!
<DRM> What use is a phone call… if you are unable to speak?
(as seen on /.)