On Tue, Dec 12, 2017, 09:56 Carlo Caione <ca...@caione.org> wrote: > 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 | 18 ++++++++++++++++++ > grub-core/partmap/msdos.c | 1 + > include/grub/partition.h | 3 +++ > 3 files changed, 22 insertions(+) > > diff --git a/grub-core/commands/probe.c b/grub-core/commands/probe.c > index cf2793e1d..22d1c5660 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,22 @@ 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 && > + dev->disk->partition->msdostype != > GRUB_PC_PARTITION_TYPE_GPT_DISK && > + grub_strcmp (dev->disk->partition->partmap->name, "msdos") == 0) > + if (dev->disk->partition->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"); > } > diff --git a/grub-core/partmap/msdos.c b/grub-core/partmap/msdos.c > index 6d4b455a1..6c13c6b8b 100644 > --- a/grub-core/partmap/msdos.c > +++ b/grub-core/partmap/msdos.c > @@ -180,6 +180,7 @@ grub_partition_msdos_iterate (grub_disk_t disk, > p.len = grub_le_to_cpu32 (e->length) > << (disk->log_sector_size - GRUB_DISK_SECTOR_BITS); > p.msdostype = e->type; > + p.flag = e->flag; > part_msdos is too size-sensitive. Please don't add anything there. Just reread the sector with MBR or EBR in probing.
> > grub_dprintf ("partition", > "partition %d: flag 0x%x, type 0x%x, start 0x%llx, > len 0x%llx\n", > diff --git a/include/grub/partition.h b/include/grub/partition.h > index 7adb7ec6e..d450415e0 100644 > --- a/include/grub/partition.h > +++ b/include/grub/partition.h > @@ -87,6 +87,9 @@ struct grub_partition > /* The type of partition whne it's on MSDOS. > Used for embedding detection. */ > grub_uint8_t msdostype; > + > + /* Partition flag */ > + grub_uint8_t flag; > }; > > grub_partition_t EXPORT_FUNC(grub_partition_probe) (struct grub_disk > *disk, > -- > 2.14.1 > > > _______________________________________________ > Grub-devel mailing list > Grub-devel@gnu.org > https://lists.gnu.org/mailman/listinfo/grub-devel >
_______________________________________________ Grub-devel mailing list Grub-devel@gnu.org https://lists.gnu.org/mailman/listinfo/grub-devel