From patchwork Mon Jul 3 13:39:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joshua Watt X-Patchwork-Id: 1802771 X-Patchwork-Delegate: trini@ti.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20221208 header.b=cSGO69dr; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QvnB55YJbz20b1 for ; Mon, 3 Jul 2023 23:40:45 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id CC0448677D; Mon, 3 Jul 2023 15:40:22 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="cSGO69dr"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 34C6286775; Mon, 3 Jul 2023 15:40:21 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=unavailable autolearn_force=no version=3.4.2 Received: from mail-oa1-x33.google.com (mail-oa1-x33.google.com [IPv6:2001:4860:4864:20::33]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 239CC8675D for ; Mon, 3 Jul 2023 15:40:18 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jpewhacker@gmail.com Received: by mail-oa1-x33.google.com with SMTP id 586e51a60fabf-1b3c503af99so14577fac.0 for ; Mon, 03 Jul 2023 06:40:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1688391616; x=1690983616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fNNa2gV/Wjm7yO2e2PBx88jzNXKRtb09Fi9Lvrdh6QI=; b=cSGO69drTfowmBfBXkwvurppPcaTwSakpQ1OKVxERo4ACAdZESRZgqX4P+5UkOv7rn xq1uyxTvawwONSWFtIWLqGGIgZ1t4tBybhcNTOG4/F4TuqEhzk2Vp0VmDUMEcgCHZNlR Yhm2YlZS9MxdTNMa4v2Qw1Rc2HI5+4Zt1FPeOpK5ioytyXg/mwb91EHhFTirLVgxEIiX 7TtjenXkKhEf7f8VgPqa5N6sHuDaLFAtoa4mSQDFsfXNf72uuTXgoryJDvAwPOvBSkDD TJ8StTy4rHpg+BE0TAP0/e6vT9uIL6ChGKWLoxRtCyejrXT/rNVUeJjl24a1Q8Mu3XE7 jGNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1688391616; x=1690983616; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fNNa2gV/Wjm7yO2e2PBx88jzNXKRtb09Fi9Lvrdh6QI=; b=GsRX9YIHFBrmXmPee+2I5uxhu3q4iEI5WctTEc/I1sg3WzxQ/HhqMJrlwmQez1vCc5 groXWgITgB5rzFjoS7V6V22fBl/e1dxoVvOwHiMmdFaJ+TUp42XLXya3QgzbYqh+pMYb VqefbC+9+NgJxOEnoyH4AWz7/fjmPV0yzNqxQjFiU2V4g1BVYH4pmjMvWtx9e1VWsTqk Zn44krZ8wBY9xyo/RCLd9Foaj3kz6t71PUkVRNBUM6FwfHe30mOBRRVJd4m3+FVIWTv6 mNcQ7CGixCJ8gy55DOOM3hwvCG+jIe6CQE9Z1O44BsEHtku8Ia2Gq/zDYQ6Z7GR4AZN3 G+lg== X-Gm-Message-State: ABy/qLZg1f8RRZnOEVUgpiwp0J0fovoe0tx4SErw89dNE5jKIWOCY4A7 Uhw4yPw48JA8y5Qcqu3lpl2Cjvl3leE= X-Google-Smtp-Source: APBJJlEKwLC5tNeZp0w4NT3PUSCX+eZpHBz5fQoYbppu7mkT+uNdUdrtqw3hMCWE3/cytORK2qBg8A== X-Received: by 2002:a05:6870:82ab:b0:1b0:7078:58ad with SMTP id q43-20020a05687082ab00b001b0707858admr15139855oae.38.1688391615928; Mon, 03 Jul 2023 06:40:15 -0700 (PDT) Received: from localhost.localdomain ([204.77.163.107]) by smtp.gmail.com with ESMTPSA id j2-20020a9d7382000000b006b8cf55a997sm535720otk.28.2023.07.03.06.40.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Jul 2023 06:40:15 -0700 (PDT) From: Joshua Watt X-Google-Original-From: Joshua Watt To: u-boot@lists.denx.de Cc: Joshua Watt , Simon Glass , Tobias Waldekranz , Heinrich Schuchardt , Heiko Schocher , Stefan Herbrechtsmeier Subject: [PATCH v2 3/5] disk: part: Add API to get partitions with specific driver Date: Mon, 3 Jul 2023 08:39:54 -0500 Message-Id: <20230703133959.3880305-4-JPEWhacker@gmail.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20230703133959.3880305-1-JPEWhacker@gmail.com> References: <20230623200031.2689749-1-JPEWhacker@gmail.com> <20230703133959.3880305-1-JPEWhacker@gmail.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean 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 Reviewed-by: Simon Glass --- disk/part.c | 38 +++++++++++++++++++++++++++++++------- include/part.h | 19 ++++++++++++++++++- 2 files changed, 49 insertions(+), 8 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..8a0c8732a6 100644 --- a/include/part.h +++ b/include/part.h @@ -105,7 +105,24 @@ struct blk_desc *blk_get_dev(const char *ifname, int dev); struct blk_desc *mg_disk_get_dev(int dev); -/* disk/part.c */ +/** + * part_get_info_by_type() - Get partitions from a block device using a specific + * partition driver + * + * Each interface allocates its own devices and typically struct blk_desc is + * contained with the interface's data structure. There is no global + * numbering for block devices, so the interface name must be provided. + * + * @dev_desc: Block device descriptor + * @part: Partition number to read + * @part_type: Partition driver to use, or PART_TYPE_UNKNOWN to automatically + * choose a driver + * @info: Returned partition information + * + * Return: 0 on success, negative errno on failure + */ +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); /**