From: Carlo Caione <ca...@endlessm.com> 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 <ca...@endlessm.com> --- grub-core/commands/probe.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c index cf2793e1d..f7a5563bf 100644 --- a/grub-core/commands/probe.c +++ b/grub-core/commands/probe.c @@ -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"); } -- 2.14.1 _______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel