[PATCH 06/16] common: bootscan: add scan_disk callback

Ahmad Fatoum a.fatoum at pengutronix.de
Tue Apr 1 03:47:56 PDT 2025


The scan_disk callback will be invoked for every disk and makes
implementing logic easier, where a bootscanner wants to process specific
partitions by type for example.

Signed-off-by: Ahmad Fatoum <a.fatoum at pengutronix.de>
---
 common/bootscan.c  | 25 ++++++++++++++++++++++---
 include/bootscan.h |  3 +++
 2 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/common/bootscan.c b/common/bootscan.c
index cc25f070508a..222498c609a4 100644
--- a/common/bootscan.c
+++ b/common/bootscan.c
@@ -14,10 +14,26 @@
 static int boot_scan_device(struct bootscanner *scanner,
 			    struct bootentries *bootentries, struct device *dev)
 {
+	struct cdev *cdev;
+	int ret;
 
 	pr_debug("%s(%s): %s\n", __func__, scanner->name, dev_name(dev));
 
 	device_detect(dev);
+
+	if (!scanner->scan_disk)
+		goto scan_device;
+
+	list_for_each_entry(cdev, &dev->cdevs, devices_list) {
+		if (cdev_is_partition(cdev))
+			continue;
+
+		ret = scanner->scan_disk(scanner, bootentries, cdev);
+		if (ret)
+			return ret;
+	}
+
+scan_device:
 	return scanner->scan_device(scanner, bootentries, dev);
 }
 
@@ -38,7 +54,7 @@ static int boot_scan_ubi(struct bootscanner *scanner,
 
 	pr_debug("%s(%s): %s\n", __func__, scanner->name, cdev->name);
 
-	if (!scanner->scan_device)
+	if (!scanner->scan_disk && !scanner->scan_device)
 		return 0;
 
 	ret = ubi_attach_mtd_dev(cdev->mtd, UBI_DEV_NUM_AUTO, 0, 20);
@@ -83,8 +99,11 @@ int boot_scan_cdev(struct bootscanner *scanner,
 	filetype = file_detect_type(buf, 512);
 	free(buf);
 
-	if (type == filetype_mbr || type == filetype_gpt)
-		return -EINVAL;
+	if (type == filetype_mbr || type == filetype_gpt) {
+		if (!scanner->scan_disk || cdev_is_partition(cdev))
+			return -EINVAL;
+		return scanner->scan_disk(scanner, bootentries, cdev);
+	}
 
 	if (filetype == filetype_ubi && IS_ENABLED(CONFIG_MTD_UBI)) {
 		ret = boot_scan_ubi(scanner, bootentries, cdev);
diff --git a/include/bootscan.h b/include/bootscan.h
index 3161896faf07..99094dc09320 100644
--- a/include/bootscan.h
+++ b/include/bootscan.h
@@ -16,6 +16,9 @@ struct bootscanner {
 	/** Invoked for when scanning a directory */
 	int (*scan_directory)(struct bootscanner *,
 			      struct bootentries *, const char *);
+	/** Invoked for when scanning a disk */
+	int (*scan_disk)(struct bootscanner *,
+			 struct bootentries *, struct cdev *);
 	/** Fallback: Invoked only when none of the above returned results */
 	int (*scan_device)(struct bootscanner *,
 			   struct bootentries *, struct device *);
-- 
2.39.5




More information about the barebox mailing list