Improve 'probe' grub-shell command with functionality to read and
display a partition PARTLABEL string, which is known as GPT partition
name on GPT formatted disks.

Signed-off-by: Vitaly Kuzmichev <vitaly.kuzmic...@rtsoft.de>
---
 grub-core/commands/probe.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c
index 05aed2295..1a5fc30a2 100644
--- a/grub-core/commands/probe.c
+++ b/grub-core/commands/probe.c
@@ -48,6 +48,7 @@ static const struct grub_arg_option options[] =
     {"fs-uuid",                'u', 0, N_("Determine filesystem UUID."), 0, 0},
     {"label",          'l', 0, N_("Determine filesystem label."), 0, 0},
     {"part-uuid",      0,   0, N_("Determine partition UUID."), 0, 0},
+    {"part-label",     0,   0, N_("Determine partition label."), 0, 0},
     {0, 0, 0, 0, 0, 0}
   };
 
@@ -124,6 +125,27 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char 
**args)
       grub_free (part_uuid);
       return GRUB_ERR_NONE;
     }
+  if (state[7].set)
+    {
+      char *part_label;
+
+      part_label = grub_gpt_partition_get_label (dev);
+      if (!part_label && grub_errno)
+       {
+         grub_error_push ();
+         grub_device_close (dev);
+         grub_error_pop ();
+         return grub_errno;
+       }
+
+      if (state[0].set)
+       grub_env_set (state[0].arg, part_label ? part_label : "none");
+      else
+       grub_printf ("%s", part_label ? part_label : "none");
+      grub_device_close (dev);
+      grub_free (part_label);
+      return GRUB_ERR_NONE;
+    }
   fs = grub_fs_probe (dev);
   if (! fs)
     {
-- 
2.34.1


_______________________________________________
Grub-devel mailing list
Grub-devel@gnu.org
https://lists.gnu.org/mailman/listinfo/grub-devel

Reply via email to