From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcp2J-0006Uu-2T for mharc-grub-devel@gnu.org; Sun, 24 May 2020 07:43:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59830) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcp2I-0006UK-Cz for grub-devel@gnu.org; Sun, 24 May 2020 07:43:22 -0400 Received: from ionic.de ([87.98.244.45]:42845 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcp2H-0005x8-9F for grub-devel@gnu.org; Sun, 24 May 2020 07:43:22 -0400 Received: from apgunner.local.home.ionic.de (home.ionic.de [217.92.117.31]) by mail.ionic.de (Postfix) with ESMTPSA id 191ED4F0BA16 for ; Sun, 24 May 2020 11:43:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ionic.de; s=default; t=1590320597; bh=t1xp/OyBDGC7OVZEZ+G20c6S5I8bkrIsZ8/56/yEEFQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=dNSXHx0D7VVHq52Ax+aGOodVpO1Iw/ZMjBg9BtlA5eMs6Qn2sXxJlpqnuDJpOJoVw jLIK3LVQajGtFdpC7qJFGUfHCoAgO1Bzqd4TZoSo+KeJXota+Fk23VTIOQgALPo5IH fpQkfmykRrfrWb9BE/GCjMx5s0XIT17LGE32ZvGo= From: Mihai Moldovan To: The development of GNU GRUB Subject: [PATCH 6/7] diskfilter: write out currently scanned partition Date: Sun, 24 May 2020 13:43:07 +0200 Message-Id: <20200524114308.1009-7-ionic@ionic.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200524114308.1009-1-ionic@ionic.de> References: <20200524114308.1009-1-ionic@ionic.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=87.98.244.45; envelope-from=ionic@ionic.de; helo=mail.ionic.de X-detected-operating-system: by eggs.gnu.org: First seen = 2020/05/24 07:43:16 X-ACL-Warn: Detected OS = Linux 2.2.x-3.x [generic] X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_PASS=-0.001, URIBL_BLOCKED=0.001 autolearn=_AUTOLEARN X-Spam_action: no action X-BeenThere: grub-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: The development of GNU GRUB List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 24 May 2020 11:43:22 -0000 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