grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v2 6/7] diskfilter: write out currently scanned partition


From: Mihai Moldovan
Subject: [PATCH v2 6/7] diskfilter: write out currently scanned partition
Date: Sun, 24 May 2020 14:25:16 +0200

Knowing the disk is fine, but also knowing the partition number is even
better.

Also, add additional non-util debug messages while scanning for explicit
diskfilter types. It can't hurt to get the information in both modes.
---
 grub-core/disk/diskfilter.c | 54 +++++++++++++++++++++++++++++++++----
 1 file changed, 49 insertions(+), 5 deletions(-)

diff --git a/grub-core/disk/diskfilter.c b/grub-core/disk/diskfilter.c
index 67bf37a9c..ae7f3e4d2 100644
--- a/grub-core/disk/diskfilter.c
+++ b/grub-core/disk/diskfilter.c
@@ -133,10 +133,46 @@ scan_disk_partition_iter (grub_disk_t disk, 
grub_partition_t p, void *data)
   struct grub_diskfilter_pv_id id;
   grub_diskfilter_t diskfilter;
 
+  /*
+   * name + ", partition " (12) + partition number as number + \0
+   *
+   * We'll assume a maximum limit of 99999 (or 100000, if zero-indexed)
+   * partitions here, which should be plenty.
+   *
+   * MBR is limited to 3 + 128 (logical) partitions, GPT by default reserves
+   * enough space for 128 partitions, but can (theoretically) be extended
+   * beyond that limit.
+   *
+   * People have tried to go up to 65536, which is/was a limit in gdisk, but
+   * also found out that a lot of tools can't cope with more than 8192
+   * partitions.
+   *
+   * The pactical benefit is doubtful, but we still can spare a few additional
+   * bytes in the string to be compatible with huge amounts of partition
+   * entries.
+   */
+  const int full_name_max_length = grub_strlen (name) + 18;
+  char *full_name = grub_zalloc (full_name_max_length);
+  if (!full_name)
+    {
+      return 0;
+    }
+
+  /* Add disk name. */
+  grub_snprintf (full_name, full_name_max_length, "%s", name);
+
+  if (p)
+    {
+      /* Add partition description and number. */
+      grub_snprintf (full_name + grub_strlen (name),
+                    full_name_max_length - grub_strlen (name),
+                    ", partition %d", p->number);
+    }
+
   grub_dprintf ("diskfilter", "Scanning for DISKFILTER devices on disk %s\n",
-               name);
+               full_name);
 #ifdef GRUB_UTIL
-  grub_util_info ("Scanning for DISKFILTER devices on disk %s", name);
+  grub_util_info ("Scanning for DISKFILTER devices on disk %s", full_name);
 #endif
 
   disk->partition = p;
@@ -149,14 +185,19 @@ scan_disk_partition_iter (grub_disk_t disk, 
grub_partition_t p, void *data)
            && m->disk->dev->id == disk->dev->id
            && m->part_start == grub_partition_get_start (disk->partition)
            && m->part_size == grub_disk_get_size (disk))
-         return 0;
+         {
+           grub_free (full_name);
+           return 0;
+         }
     }
 
   for (diskfilter = grub_diskfilter_list; diskfilter; diskfilter = 
diskfilter->next)
     {
+      grub_dprintf ("diskfilter", "Scanning for %s devices on disk %s\n",
+                   diskfilter->name, full_name);
 #ifdef GRUB_UTIL
-      grub_util_info ("Scanning for %s devices on disk %s", 
-                     diskfilter->name, name);
+      grub_util_info ("Scanning for %s devices on disk %s",
+                     diskfilter->name, full_name);
 #endif
       id.uuid = 0;
       id.uuidlen = 0;
@@ -166,6 +207,7 @@ scan_disk_partition_iter (grub_disk_t disk, 
grub_partition_t p, void *data)
        {
          if (id.uuidlen)
            grub_free (id.uuid);
+         grub_free (full_name);
          return 0;
        }
       if (arr && id.uuidlen)
@@ -179,6 +221,8 @@ scan_disk_partition_iter (grub_disk_t disk, 
grub_partition_t p, void *data)
       grub_errno = GRUB_ERR_NONE;
     }
 
+  grub_free (full_name);
+
   return 0;
 }
 
-- 
2.25.1




reply via email to

[Prev in Thread] Current Thread [Next in Thread]