grub-devel
[Top][All Lists]
Advanced

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

Adding partition guid/uuid to the probe command for use with Linux kerne


From: Steve Kenton
Subject: Adding partition guid/uuid to the probe command for use with Linux kernel command line root=PARTUUID=$guid
Date: Sun, 14 Aug 2016 18:31:18 +0000
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.2.0

I have not look at NTFS yet, but is this more what you were wanting? I'm not sure about the printing, should grub_gpt_partentry.guid[16] change to a UUID struct?

Steve Kenton

diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c
index cf2793e..8ff4ff9 100644
--- a/grub-core/commands/probe.c
+++ b/grub-core/commands/probe.c
@@ -24,6 +24,7 @@
 #include <grub/device.h>
 #include <grub/disk.h>
 #include <grub/partition.h>
+#include <grub/gpt_partition.h>
 #include <grub/net.h>
 #include <grub/fs.h>
 #include <grub/file.h>
@@ -45,6 +46,7 @@ static const struct grub_arg_option options[] =
     {"fs",        'f', 0, N_("Determine filesystem type."), 0, 0},
     {"fs-uuid",        'u', 0, N_("Determine filesystem UUID."), 0, 0},
     {"label",        'l', 0, N_("Determine filesystem label."), 0, 0},
+    {"partguid",    'g', 0, N_("Determine partition guid."), 0, 0},
     {0, 0, 0, 0, 0, 0}
   };

@@ -154,6 +156,43 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)
       grub_device_close (dev);
       return GRUB_ERR_NONE;
     }
+  if (state[6].set)
+    {
+      char *val;
+      struct grub_gpt_partentry entry;
+      if (dev->disk && dev->disk->partition)
+    {
+      if (grub_strcmp (dev->disk->partition->partmap->name, "gpt"))
+        return grub_error (GRUB_ERR_NOT_IMPLEMENTED_YET,
+ N_("partition map %s does not support partition GUIDs"), dev->disk->partition->partmap->name); + if (grub_disk_read (dev->disk, dev->disk->partition->offset, dev->disk->partition->index, sizeof(entry), &entry))
+        return grub_errno;
+#if 0
+ val = grub_xasprintf ("%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", /* should grub_gpt_partentry.guid[16] change to a UUID struct? */
+      grub_be_to_cpu32 (*(grub_uint32_t *) &entry.guid[0]),
+      grub_be_to_cpu16 (*(grub_uint16_t *) &entry.guid[4]),
+      grub_be_to_cpu16 (*(grub_uint16_t *) &entry.guid[6]),
+      entry.guid[8], entry.guid[9],
+ entry.guid[10], entry.guid[11], entry.guid[12], entry.guid[13], entry.guid[14], entry.guid[15]);
+#else
+ val = grub_xasprintf ("%02x%02x%02x%02x-%02x%02x-%02x%02x-%02x%02x-%02x%02x%02x%02x%02x%02x", /* guid is big-endian */
+      entry.guid[0], entry.guid[1], entry.guid[2], entry.guid[3],
+      entry.guid[4], entry.guid[5],
+      entry.guid[6], entry.guid[7],
+      entry.guid[8], entry.guid[9],
+ entry.guid[10], entry.guid[11], entry.guid[12], entry.guid[13], entry.guid[14], entry.guid[15]);
+#endif
+    }
+    else
+      val = grub_strdup(""); /* set guid to the empty string */
+      if (state[0].set)
+    grub_env_set (state[0].arg, val);
+      else
+    grub_printf ("%s", val);
+      grub_free (val);
+      grub_device_close (dev);
+      return GRUB_ERR_NONE;
+    }
   grub_device_close (dev);
   return grub_error (GRUB_ERR_BAD_ARGUMENT, "unrecognised target");
 }



reply via email to

[Prev in Thread] Current Thread [Next in Thread]