Skip to contentSkip to conversation

grub-core/commands/probe.c: Add bootable parameter

PATCH Superseded Carlo Caione 3 participants 5 messages Dec 12, 2017 – Dec 19, 2017

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 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.

---
 grub-core/commands/probe.c | 18 ++++++++++++++++++
 grub-core/partmap/msdos.c  |  1 +
 include/grub/partition.h   |  3 +++
 3 files changed, 22 insertions(+)
grub-core/commands/probe.c +18 -0
index cf2793e1d..22d1c5660 100644
@@ -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");
 }
grub-core/partmap/msdos.c +1 -0
index 6d4b455a1..6c13c6b8b 100644
@@ -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;
 
 	  grub_dprintf ("partition",
 			"partition %d: flag 0x%x, type 0x%x, start 0x%llx, len 0x%llx\n",
include/grub/partition.h +3 -0
index 7adb7ec6e..d450415e0 100644
@@ -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,
Signature · 1 line
2.14.1
#1 lore raw
Quoted 65 lines · On Tue, Dec 12, 2017, 09:56 Carlo Caione <[email protected]> wrote:

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.

---
 grub-core/commands/probe.c | 18 ++++++++++++++++++
 grub-core/partmap/msdos.c  |  1 +
 include/grub/partition.h   |  3 +++
 3 files changed, 22 insertions(+)
grub-core/commands/probe.c +2 -0
index cf2793e1d..22d1c5660 100644
@@ -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}
   };
grub-core/commands/probe.c +6 -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-core/commands/probe.c +10 -0
+          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");
 }
grub-core/partmap/msdos.c +0 -0
index 6d4b455a1..6c13c6b8b 100644

grub-core/partmap/msdos.c grub_partition_msdos_iterate (grub_disk_t disk, · line 184

Quoted 5 lines
grub-core/partmap/msdos.c +1 -0
@@ -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.

Quoted 28 lines
grub-core/partmap/msdos.c +0 -0
          grub_dprintf ("partition",
                        "partition %d: flag 0x%x, type 0x%x, start 0x%llx,

len 0x%llx\n",

include/grub/partition.h +3 -0
index 7adb7ec6e..d450415e0 100644
@@ -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
[email protected]
https://lists.gnu.org/mailman/listinfo/grub-devel

#2 lore raw
Quoted 69 lines · Vladimir 'phcoder' Serbinenko
Quoted 66 lines · On Tue, Dec 12, 2017, 09:56 Carlo Caione <[email protected]> wrote:

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.

---
 grub-core/commands/probe.c | 18 ++++++++++++++++++
 grub-core/partmap/msdos.c  |  1 +
 include/grub/partition.h   |  3 +++
 3 files changed, 22 insertions(+)
grub-core/commands/probe.c +2 -0
index cf2793e1d..22d1c5660 100644
@@ -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}
   };
grub-core/commands/probe.c +6 -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)

grub-core/commands/probe.c +9 -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");
 }
grub-core/partmap/msdos.c +0 -0
index 6d4b455a1..6c13c6b8b 100644
Quoted 8 lines

grub-core/partmap/msdos.c grub_partition_msdos_iterate (grub_disk_t disk, · line 183

Quoted 5 lines
grub-core/partmap/msdos.c +1 -0
@@ -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.

the new flag entry is added to struct grub_partition not struct grub_msdos_partition_mbr, is that actually risky?

Signature · 1 line
Carlo Caione  |  +39.340.80.30.096  |  Endless
#3 lore raw
Quoted 84 lines · On Wed, Dec 13, 2017, 12:30 Carlo Caione <[email protected]> wrote:
Quoted 27 lines · Vladimir 'phcoder' Serbinenko
Quoted 24 lines · On Tue, Dec 12, 2017, 09:56 Carlo Caione <[email protected]> wrote:

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.

---
 grub-core/commands/probe.c | 18 ++++++++++++++++++
 grub-core/partmap/msdos.c  |  1 +
 include/grub/partition.h   |  3 +++
 3 files changed, 22 insertions(+)
grub-core/commands/probe.c +1 -0
index cf2793e1d..22d1c5660 100644
@@ -31,6 +31,7 @@
 #include <grub/env.h>
 #include <grub/extcmd.h>
 #include <grub/i18n.h>
+#include <grub/msdos_partition.h>
 
Quoted 5 lines

grub-core/commands/probe.c static const struct grub_arg_option options[] = · line 47

Quoted 5 lines
grub-core/commands/probe.c +0 -0
 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."),

Quoted 2 lines

grub-core/commands/probe.c static const struct grub_arg_option options[] = · line 49

Quoted 2 lines
grub-core/commands/probe.c +0 -0
 0, 0},
     {"label",          'l', 0, N_("Determine filesystem label."), 0,

0},

Quoted 1 line

grub-core/commands/probe.c static const struct grub_arg_option options[] = · line 50

Quoted 1 line
grub-core/commands/probe.c +1 -0
+    {"bootable",       'b', 0, N_("Determine if bootable / active flag

is

Quoted 5 lines

grub-core/commands/probe.c grub_cmd_probe (grub_extcmd_context_t ctxt, int

Quoted 5 lines
grub-core/commands/probe.c +0 -0
 set."), 0, 0},
     {0, 0, 0, 0, 0, 0}
   };
grub-core/commands/probe.c +0 -0
@@ -154,6 +156,22 @@ grub_cmd_probe (grub_extcmd_context_t ctxt, int

argc,

Quoted 29 lines
Quoted 29 lines
grub-core/commands/probe.c +6 -0
 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)

grub-core/commands/probe.c +9 -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");
 }
grub-core/partmap/msdos.c +0 -0
index 6d4b455a1..6c13c6b8b 100644
Quoted 8 lines

grub-core/partmap/msdos.c grub_partition_msdos_iterate (grub_disk_t disk, · line 183

Quoted 5 lines
grub-core/partmap/msdos.c +1 -0
@@ -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.

Quoted 3 lines

the new flag entry is added to struct grub_partition not struct grub_msdos_partition_mbr, is that actually risky?

I spoke about part_msdos module. It's already larger than it should be

Quoted 4 lines

--
Carlo Caione | +39.340.80.30.096 | Endless

#4 lore raw
Quoted 7 lines · Vladimir 'phcoder' Serbinenko
Quoted 5 lines
Quoted 2 lines

part_msdos is too size-sensitive. Please don't add anything there. Just reread the sector with MBR or EBR in probing.

the new flag entry is added to struct grub_partition not struct grub_msdos_partition_mbr, is that actually risky?

I spoke about part_msdos module. It's already larger than it should be

Yeah, I submitted a V2 for this patch.

Thanks,

Signature · 1 line
Carlo Caione  |  +44.7384.69.16.04  |  Endless