From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from list by lists.gnu.org with archive (Exim 4.90_1) id 1jcph6-0007o8-2c for mharc-grub-devel@gnu.org; Sun, 24 May 2020 08:25:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jcph1-0007kI-6k for grub-devel@gnu.org; Sun, 24 May 2020 08:25:27 -0400 Received: from ionic.de ([2001:41d0:a:588b:1::2]:52803 helo=mail.ionic.de) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1jcph0-0004kY-6T for grub-devel@gnu.org; Sun, 24 May 2020 08:25:26 -0400 Received: from apgunner.local.home.ionic.de (home.ionic.de [217.92.117.31]) by mail.ionic.de (Postfix) with ESMTPSA id 719244F0BA18 for ; Sun, 24 May 2020 12:25:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=ionic.de; s=default; t=1590323123; bh=t1xp/OyBDGC7OVZEZ+G20c6S5I8bkrIsZ8/56/yEEFQ=; h=From:To:Subject:Date:In-Reply-To:References:From; b=uzRe/rJ6KTkaLjb2tMAWUHenpNwDgOSHnOSAKpr+nsVhEi2vbUE+vS/QlfcontWiA vn7cj5119AOhw7YeWvHANs9vUp9ZZZyAzoUZxdYt0HESrP/wyePt1SP8oCyEi66Oyz ASdACgX3MPyUNGDwut1YYUqbwsB+ORqMuqx0KMl4= From: Mihai Moldovan To: The development of GNU GRUB Subject: [PATCH v2 6/7] diskfilter: write out currently scanned partition Date: Sun, 24 May 2020 14:25:16 +0200 Message-Id: <20200524122517.5010-7-ionic@ionic.de> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200524122517.5010-1-ionic@ionic.de> References: <20200524122517.5010-1-ionic@ionic.de> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Received-SPF: pass client-ip=2001:41d0:a:588b:1::2; envelope-from=ionic@ionic.de; helo=mail.ionic.de X-detected-operating-system: by eggs.gnu.org: No matching host in p0f cache. That's all we know. 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 12:25:27 -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