[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[PATCH 6/7] diskfilter: write out currently scanned partition
From: |
Mihai Moldovan |
Subject: |
[PATCH 6/7] diskfilter: write out currently scanned partition |
Date: |
Sun, 24 May 2020 13:43:07 +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
- [PATCH 0/7] support >512b sector disks with old/buggy firmware, Mihai Moldovan, 2020/05/24
- [PATCH 4/7] grub-install: hook up --emu-512b to sector size autodetection in biosdisk, Mihai Moldovan, 2020/05/24
- [PATCH 6/7] diskfilter: write out currently scanned partition,
Mihai Moldovan <=
- [PATCH 2/7] biosdisk: restore LBA mode after read/write failures, Mihai Moldovan, 2020/05/24
- [PATCH 5/7] docs/grub: document --emu-512b install option, Mihai Moldovan, 2020/05/24
- [PATCH 1/7] biosdisk: autodetect hardware sector size (opt-in), Mihai Moldovan, 2020/05/24
- [PATCH 7/7] gpt: respect native sector size if set/detected, Mihai Moldovan, 2020/05/24
- [PATCH 3/7] setup: add support for native sector addressing w/ 512-bytes lengths, Mihai Moldovan, 2020/05/24