public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Joshua Watt <jpewhacker@gmail.com>
To: u-boot@lists.denx.de
Cc: Joshua Watt <JPEWhacker@gmail.com>,
	Simon Glass <sjg@chromium.org>,
	Tobias Waldekranz <tobias@waldekranz.com>,
	Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>,
	Heiko Schocher <hs@denx.de>,
	Heinrich Schuchardt <xypron.glpk@gmx.de>
Subject: [PATCH 1/2] disk: part: Add API to get partitions with specific driver
Date: Fri, 23 Jun 2023 14:59:59 -0500	[thread overview]
Message-ID: <20230623200031.2689749-2-JPEWhacker@gmail.com> (raw)
In-Reply-To: <20230623200031.2689749-1-JPEWhacker@gmail.com>

Adds part_driver_get_type() API which can be used to force a specific
driver to be used when getting partition information instead of relying
on auto detection.

Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
---
 disk/part.c    | 38 +++++++++++++++++++++++++++++++-------
 include/part.h |  2 ++
 2 files changed, 33 insertions(+), 7 deletions(-)

diff --git a/disk/part.c b/disk/part.c
index 35300df590..1f8c786ca5 100644
--- a/disk/part.c
+++ b/disk/part.c
@@ -26,6 +26,22 @@
 /* Check all partition types */
 #define PART_TYPE_ALL		-1
 
+static struct part_driver *part_driver_get_type(int part_type)
+{
+	struct part_driver *drv =
+		ll_entry_start(struct part_driver, part_driver);
+	const int n_ents = ll_entry_count(struct part_driver, part_driver);
+	struct part_driver *entry;
+
+	for (entry = drv; entry != drv + n_ents; entry++) {
+		if (part_type == entry->part_type)
+			return entry;
+	}
+
+	/* Not found */
+	return NULL;
+}
+
 static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 {
 	struct part_driver *drv =
@@ -44,10 +60,7 @@ static struct part_driver *part_driver_lookup_type(struct blk_desc *dev_desc)
 			}
 		}
 	} else {
-		for (entry = drv; entry != drv + n_ents; entry++) {
-			if (dev_desc->part_type == entry->part_type)
-				return entry;
-		}
+		return part_driver_get_type(dev_desc->part_type);
 	}
 
 	/* Not found */
@@ -306,8 +319,8 @@ void part_print(struct blk_desc *dev_desc)
 		drv->print(dev_desc);
 }
 
-int part_get_info(struct blk_desc *dev_desc, int part,
-		       struct disk_partition *info)
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info)
 {
 	struct part_driver *drv;
 
@@ -320,7 +333,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 		info->type_guid[0] = 0;
 #endif
 
-		drv = part_driver_lookup_type(dev_desc);
+		if (part_type == PART_TYPE_UNKNOWN) {
+			drv = part_driver_lookup_type(dev_desc);
+		} else {
+			drv = part_driver_get_type(part_type);
+		}
+
 		if (!drv) {
 			debug("## Unknown partition table type %x\n",
 			      dev_desc->part_type);
@@ -340,6 +358,12 @@ int part_get_info(struct blk_desc *dev_desc, int part,
 	return -ENOENT;
 }
 
+int part_get_info(struct blk_desc *dev_desc, int part,
+		  struct disk_partition *info)
+{
+	return part_get_info_by_type(dev_desc, part, PART_TYPE_UNKNOWN, info);
+}
+
 int part_get_info_whole_disk(struct blk_desc *dev_desc,
 			     struct disk_partition *info)
 {
diff --git a/include/part.h b/include/part.h
index be75c73549..f150c84206 100644
--- a/include/part.h
+++ b/include/part.h
@@ -106,6 +106,8 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev);
 struct blk_desc *mg_disk_get_dev(int dev);
 
 /* disk/part.c */
+int part_get_info_by_type(struct blk_desc *dev_desc, int part, int part_type,
+			  struct disk_partition *info);
 int part_get_info(struct blk_desc *dev_desc, int part,
 		  struct disk_partition *info);
 /**
-- 
2.33.0


  reply	other threads:[~2023-06-24 22:27 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-23 19:59 [PATCH 0/2] Fix 'mbr' command with hybrid MBR/GPT Joshua Watt
2023-06-23 19:59 ` Joshua Watt [this message]
2023-06-26  9:07   ` [PATCH 1/2] disk: part: Add API to get partitions with specific driver Simon Glass
2023-06-28 13:33     ` Joshua Watt
2023-06-29 19:09       ` Simon Glass
2023-06-23 20:00 ` [PATCH 2/2] cmd: mbr: Force DOS driver to be used for verify Joshua Watt
2023-07-03 13:39 ` [PATCH v2 0/5] Fix 'mbr' command with hybrid MBR/GPT Joshua Watt
2023-07-03 13:39   ` [PATCH v2 1/5] dm: test: Fix partition test to use mmc2 Joshua Watt
2023-07-04  2:40     ` Simon Glass
2023-07-05  0:16     ` Jaehoon Chung
2023-07-18 13:58     ` Tom Rini
2023-07-03 13:39   ` [PATCH v2 2/5] dm: test: Improve partition test error output Joshua Watt
2023-07-04  2:40     ` Simon Glass
2023-07-18 13:58     ` Tom Rini
2023-07-03 13:39   ` [PATCH v2 3/5] disk: part: Add API to get partitions with specific driver Joshua Watt
2023-07-04  2:40     ` Simon Glass
2023-07-18 13:58     ` Tom Rini
2023-07-03 13:39   ` [PATCH v2 4/5] dm: test: Add test for part_get_info_by_type Joshua Watt
2023-07-04  2:40     ` Simon Glass
2023-07-18 13:58     ` Tom Rini
2023-07-03 13:39   ` [PATCH v2 5/5] cmd: mbr: Force DOS driver to be used for verify Joshua Watt
2023-07-04  2:40     ` Simon Glass
2023-07-18 13:58     ` Tom Rini

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=20230623200031.2689749-2-JPEWhacker@gmail.com \
    --to=jpewhacker@gmail.com \
    --cc=hs@denx.de \
    --cc=sjg@chromium.org \
    --cc=stefan.herbrechtsmeier@weidmueller.com \
    --cc=tobias@waldekranz.com \
    --cc=u-boot@lists.denx.de \
    --cc=xypron.glpk@gmx.de \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox