grub-core/commands/probe.c: Add bootable parameter
PATCH v2 1/1 grub-core/commands/probe.c: Add bootable parameter
From: Carlo Caione <[email protected]>
Sometimes we are interested in checking whether an msdos partition has the boot flag set. Introduce a new parameter to the probe command to check this.
Signed-off-by Carlo Caione <[email protected]>
--- grub-core/commands/probe.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+)
grub-core/commands/probe.c +26 -0
@@ -31,6 +31,7 @@#include <grub/env.h> #include <grub/extcmd.h> #include <grub/i18n.h> +#include <grub/msdos_partition.h> GRUB_MOD_LICENSE ("GPLv3+" );
@@ -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}, + {"bootable", 'b', 0, N_("Determine if bootable / active flag is set."), 0, 0}, {0, 0, 0, 0, 0, 0} };
@@ -154,6 +156,30 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int argc, char **args)grub_device_close (dev);return GRUB_ERR_NONE ; } +if (state[6 ].set) + { +const char *val ="none" ; +if (dev->disk && dev->disk->partition && +grub_strcmp (dev->disk->partition->partmap->name,"msdos" ) ==0 ) + { +struct grub_msdos_partition_mbr mbr; +int index = dev->disk->partition->index; +grub_partition_t part = dev->disk->partition; + dev->disk->partition = part->parent; +if (!grub_disk_read (dev->disk,0 ,0 ,sizeof (mbr), &mbr)) + { +if (mbr.entries[index].type !=GRUB_PC_PARTITION_TYPE_GPT_DISK && + mbr.entries[index].flag &0x80 ) + val ="bootable" ; + } + } +if (state[0 ].set) +grub_env_set (state[0 ].arg, val); +else +grub_printf ("%s" , val); +grub_device_close (dev); +return GRUB_ERR_NONE ; + }grub_device_close (dev);return grub_error (GRUB_ERR_BAD_ARGUMENT ,"unrecognised target" ); }
Signature · 1 line
2.14.1