From mboxrd@z Thu Jan 1 00:00:00 1970 Delivery-date: Mon, 05 Jun 2023 16:32:45 +0200 Received: from metis.ext.pengutronix.de ([2001:67c:670:201:290:27ff:fe1d:cc33]) by lore.white.stw.pengutronix.de with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1q6BGI-00Bs7T-Ix for lore@lore.pengutronix.de; Mon, 05 Jun 2023 16:32:45 +0200 Received: from localhost ([127.0.0.1] helo=metis.ext.pengutronix.de) by metis.ext.pengutronix.de with esmtp (Exim 4.92) (envelope-from ) id 1q6BGE-00056b-KX; Mon, 05 Jun 2023 16:32:42 +0200 Received: from drehscheibe.grey.stw.pengutronix.de ([2a0a:edc0:0:c01:1d::a2]) by metis.ext.pengutronix.de with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1q6BGC-00056G-BT; Mon, 05 Jun 2023 16:32:40 +0200 Received: from [2a0a:edc0:0:1101:1d::54] (helo=dude05.red.stw.pengutronix.de) by drehscheibe.grey.stw.pengutronix.de with esmtp (Exim 4.94.2) (envelope-from ) id 1q6BGB-005INV-My; Mon, 05 Jun 2023 16:32:39 +0200 Received: from afa by dude05.red.stw.pengutronix.de with local (Exim 4.94.2) (envelope-from ) id 1q6BGB-003ta1-21; Mon, 05 Jun 2023 16:32:39 +0200 From: Ahmad Fatoum To: oss-tools@pengutronix.de Date: Mon, 5 Jun 2023 16:32:36 +0200 Message-Id: <20230605143236.738735-1-a.fatoum@pengutronix.de> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: [OSS-Tools] [PATCH] libdt: generalize of_find_device_by_uuid for scoped lookup of all UUIDs X-BeenThere: oss-tools@pengutronix.de X-Mailman-Version: 2.1.29 Precedence: list List-Id: Pengutronix Public Open-Source-Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: rhi@pengutronix.de Sender: "OSS-Tools" X-SA-Exim-Connect-IP: 127.0.0.1 X-SA-Exim-Mail-From: oss-tools-bounces@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false Despite the generic name, of_find_device_by_uuid only handled ID_PART_TABLE_UUID (diskuuid) and ID_PART_ENTRY_UUID (partuuid), but not ID_PART_ENTRY_TYPE (GPT Partition Type UUID). In preparation for doing Type UUID lookups, adjust of_find_device_by_uuid to support all three types of GPT UUIDs. Signed-off-by: Ahmad Fatoum --- This patch is the missing prerequisite for my GPT Type UUID series. --- src/libdt.c | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/src/libdt.c b/src/libdt.c index e54d7fb5649d..2c994c647ac9 100644 --- a/src/libdt.c +++ b/src/libdt.c @@ -2405,7 +2405,9 @@ out: return dev; } -static struct udev_device *of_find_device_by_uuid(const char *uuid) +static struct udev_device *of_find_device_by_uuid(struct udev_device *parent, + const char *uuid, + bool type_uuid) { struct udev *udev; struct udev_enumerate *enumerate; @@ -2418,12 +2420,15 @@ static struct udev_device *of_find_device_by_uuid(const char *uuid) } enumerate = udev_enumerate_new(udev); + if (parent) + udev_enumerate_add_match_parent(enumerate, parent); udev_enumerate_add_match_subsystem(enumerate, "block"); udev_enumerate_scan_devices(enumerate); devices = udev_enumerate_get_list_entry(enumerate); udev_list_entry_foreach(dev_list_entry, devices) { const char *path, *devtype, *dev_uuid; struct udev_device *device; + const char *property; path = udev_list_entry_get_name(dev_list_entry); device = udev_device_new_from_syspath(udev, path); @@ -2432,16 +2437,19 @@ static struct udev_device *of_find_device_by_uuid(const char *uuid) devtype = udev_device_get_devtype(device); if (!devtype) continue; - if (!strcmp(devtype, "disk")) { - dev_uuid = udev_device_get_property_value(device, "ID_PART_TABLE_UUID"); - if (dev_uuid && !strcasecmp(dev_uuid, uuid)) - return device; - } else if (!strcmp(devtype, "partition")) { - dev_uuid = udev_device_get_property_value(device, "ID_PART_ENTRY_UUID"); - if (dev_uuid && !strcasecmp(dev_uuid, uuid)) - return device; - } + if (type_uuid) + property = "ID_PART_ENTRY_TYPE"; + else if (!strcmp(devtype, "disk")) + property = "ID_PART_TABLE_UUID"; + else if (!strcmp(devtype, "partition")) + property = "ID_PART_ENTRY_UUID"; + else + continue; + + dev_uuid = udev_device_get_property_value(device, property); + if (dev_uuid && !strcasecmp(dev_uuid, uuid)) + return device; } return NULL; } @@ -2540,7 +2548,7 @@ int of_get_devicepath(struct device_node *partition_node, char **devpath, off_t node->full_name); return -ENODEV; } - dev = of_find_device_by_uuid(uuid); + dev = of_find_device_by_uuid(NULL, uuid, false); if (!dev) { fprintf(stderr, "%s: cannot find device for uuid %s\n", __func__, uuid); -- 2.39.2