All of lore.kernel.org
 help / color / mirror / Atom feed
From: Mihai Moldovan <ionic@ionic.de>
To: The development of GNU GRUB <grub-devel@gnu.org>
Subject: [PATCH v2 6/7] diskfilter: write out currently scanned partition
Date: Sun, 24 May 2020 14:25:16 +0200	[thread overview]
Message-ID: <20200524122517.5010-7-ionic@ionic.de> (raw)
In-Reply-To: <20200524122517.5010-1-ionic@ionic.de>

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



  parent reply	other threads:[~2020-05-24 12:25 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-05-24 12:25 [PATCH v2 0/7] support >512b sector disks with old/buggy firmware Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 1/7] biosdisk: autodetect hardware sector size (opt-in) Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 2/7] biosdisk: restore LBA mode after read/write failures Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 3/7] setup: add support for native sector addressing w/ 512-bytes lengths Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 4/7] grub-install: hook up --emu-512b to sector size autodetection in biosdisk Mihai Moldovan
2020-05-24 12:25 ` [PATCH v2 5/7] docs/grub: document --emu-512b install option Mihai Moldovan
2020-05-24 12:25 ` Mihai Moldovan [this message]
2020-05-24 12:25 ` [PATCH v2 7/7] gpt: respect native sector size if set/detected Mihai Moldovan
2020-05-27  7:29 ` [PATCH v2 0/7] support >512b sector disks with old/buggy firmware Mihai Moldovan

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200524122517.5010-7-ionic@ionic.de \
    --to=ionic@ionic.de \
    --cc=grub-devel@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.