From patchwork Sun Aug 13 14:26:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 1820720 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 (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.a=rsa-sha256 header.s=google header.b=A8ba6iBF; 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 4RP0Jk2q7tz1yf6 for ; Mon, 14 Aug 2023 00:28:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6991A8698B; Sun, 13 Aug 2023 16:27:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=chromium.org header.i=@chromium.org header.b="A8ba6iBF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D010C86967; Sun, 13 Aug 2023 16:27:35 +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,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-il1-x12c.google.com (mail-il1-x12c.google.com [IPv6:2607:f8b0:4864:20::12c]) (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 9FEDF86958 for ; Sun, 13 Aug 2023 16:27:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=chromium.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=sjg@chromium.org Received: by mail-il1-x12c.google.com with SMTP id e9e14a558f8ab-349a94f3d69so2499495ab.1 for ; Sun, 13 Aug 2023 07:27:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; t=1691936852; x=1692541652; 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=Xri1NiiRE67YeAoyXdgIrpBFtsXDHh4MdQok/Vqmsd0=; b=A8ba6iBFmT+mtooAPWrhMrbllS7/klw3FfirTn8yfPjQPkwFlETCiL6B4jzolaGKtV Awk4YawWmXwqzh6a4aUYfdHG5Phfglj5uaJhyk8bJx66mlyWsDYFPtfB33s0oMh3s7U5 RwrMzN3HlKd2KfDTvRwwMQBZvYEgvxcxHd8lM= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691936852; x=1692541652; 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=Xri1NiiRE67YeAoyXdgIrpBFtsXDHh4MdQok/Vqmsd0=; b=SluWHBAyHI26ICkp03hLRAyCFCE0BSJGNpbfDPXWQHAek8biv/oAY73rXq1Cmk2Xo3 jgb2KSGLV/ny6hAhERgMHObPp6/fpf2e8VmTEa6rSkQYw8MmuFTfQqc/rGTKOD6K5O/m mJtTjTkQeECFylHUJAIiuCHkerUQre3k7pENUtFD62QtG9pd3vYTThEUt2FdIhtdAWrb 2khvFwF24QEF8P1fiJEXZynKx/iPKdES+CqyYcLG/jOnW3NGuuRMup5ZI1k3XnKtq9yn PdV44zUGwYALAwVNpJcvFPC0jdj/b/PVDDThgVmQTepjrLcw7O/C0r+le1BjN7bDmMtH Kj+g== X-Gm-Message-State: AOJu0YxF0LQPArHTI0A/9BAqWQNhKYUg0dP0ybW3IIIioH2aDZg8mGzb DlJU0pds/bbPRcv88gVH8Jh/nx1N4kwguRaIbT4= X-Google-Smtp-Source: AGHT+IEu8mL+GXaC7rPiPmEk9OaJ0ZCIJbbBmffMuu9GeyOTAwy+qucJcgT6Ossbe6nfrzm3tUeqTw== X-Received: by 2002:a05:6e02:20e1:b0:348:d683:36bf with SMTP id q1-20020a056e0220e100b00348d68336bfmr13302765ilv.12.1691936852238; Sun, 13 Aug 2023 07:27:32 -0700 (PDT) Received: from sjg1.lan (c-73-14-173-85.hsd1.co.comcast.net. [73.14.173.85]) by smtp.gmail.com with ESMTPSA id w7-20020a02cf87000000b00430cf006d9bsm2280952jar.30.2023.08.13.07.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 13 Aug 2023 07:27:32 -0700 (PDT) From: Simon Glass To: U-Boot Mailing List Cc: Simon Glass , Bin Meng , Heinrich Schuchardt , Ilias Apalodimas , Joshua Watt , Stefan Herbrechtsmeier , Tobias Waldekranz Subject: [PATCH 08/24] part: Add accessors for struct disk_partition uuid Date: Sun, 13 Aug 2023 08:26:36 -0600 Message-ID: <20230813142708.361456-9-sjg@chromium.org> X-Mailer: git-send-email 2.41.0.640.ga95def55d0-goog In-Reply-To: <20230813142708.361456-1-sjg@chromium.org> References: <20230813142708.361456-1-sjg@chromium.org> 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 This field is only present when a CONFIG is set. To avoid annoying #ifdefs in the source code, add accessors. Update all code to use it. Note that the accessor is optional. It can be omitted if it is known that the option is enabled. Signed-off-by: Simon Glass --- cmd/gpt.c | 10 ++++------ disk/part.c | 8 ++------ disk/part_dos.c | 17 ++++++++--------- disk/part_efi.c | 31 ++++++++++++++++--------------- fs/fat/fat.c | 4 +--- include/part.h | 27 +++++++++++++++++++++++++++ 6 files changed, 58 insertions(+), 39 deletions(-) diff --git a/cmd/gpt.c b/cmd/gpt.c index 007a68eaa72a..8969efba8c80 100644 --- a/cmd/gpt.c +++ b/cmd/gpt.c @@ -211,12 +211,10 @@ static struct disk_part *allocate_disk_part(struct disk_partition *info, PART_TYPE_LEN); newpart->gpt_part_info.type[PART_TYPE_LEN - 1] = '\0'; newpart->gpt_part_info.bootable = info->bootable; -#ifdef CONFIG_PARTITION_UUIDS - strncpy(newpart->gpt_part_info.uuid, (const char *)info->uuid, - UUID_STR_LEN); - /* UUID_STR_LEN is correct, as uuid[]'s length is UUID_STR_LEN+1 chars */ - newpart->gpt_part_info.uuid[UUID_STR_LEN] = '\0'; -#endif + if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) { + strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info), + UUID_STR_LEN + 1); + } newpart->partnum = partnum; return newpart; diff --git a/disk/part.c b/disk/part.c index 9190e8806187..91c6ac42cc83 100644 --- a/disk/part.c +++ b/disk/part.c @@ -368,10 +368,8 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type, struct part_driver *drv; if (blk_enabled()) { -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) /* The common case is no UUID support */ - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif @@ -416,9 +414,7 @@ int part_get_info_whole_disk(struct blk_desc *desc, info->bootable = 0; strcpy((char *)info->type, BOOT_PART_TYPE); strcpy((char *)info->name, "Whole Disk"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); #ifdef CONFIG_PARTITION_TYPE_GUID info->type_guid[0] = 0; #endif diff --git a/disk/part_dos.c b/disk/part_dos.c index f94d2172d772..f576e9368edb 100644 --- a/disk/part_dos.c +++ b/disk/part_dos.c @@ -230,10 +230,8 @@ static int part_get_info_extended(struct blk_desc *desc, return -1; } -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - if (!ext_part_sector) + if (CONFIG_IS_ENABLED(PARTITION_UUIDS) && !ext_part_sector) disksig = get_unaligned_le32(&buffer[DOS_PART_DISKSIG_OFFSET]); -#endif /* Print all primary/logical partitions */ pt = (dos_partition_t *) (buffer + DOS_PART_TBL_OFFSET); @@ -255,9 +253,12 @@ static int part_get_info_extended(struct blk_desc *desc, /* sprintf(info->type, "%d, pt->sys_ind); */ strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(pt); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - sprintf(info->uuid, "%08x-%02x", disksig, part_num); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + char str[12]; + + sprintf(str, "%08x-%02x", disksig, part_num); + disk_partition_set_uuid(info, str); + } info->sys_ind = pt->sys_ind; return 0; } @@ -291,9 +292,7 @@ static int part_get_info_extended(struct blk_desc *desc, info->blksz = DOS_PART_DEFAULT_SECTOR; info->bootable = 0; strcpy((char *)info->type, "U-Boot"); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info->uuid[0] = 0; -#endif + disk_partition_clr_uuid(info); return 0; } diff --git a/disk/part_efi.c b/disk/part_efi.c index 4ac21868d088..a6f7375cd38a 100644 --- a/disk/part_efi.c +++ b/disk/part_efi.c @@ -289,10 +289,11 @@ int part_get_info_efi(struct blk_desc *desc, int part, print_efiname(&gpt_pte[part - 1])); strcpy((char *)info->type, "U-Boot"); info->bootable = get_bootable(&gpt_pte[part - 1]); -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, info->uuid, - UUID_STR_FORMAT_GUID); -#endif + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + uuid_bin_to_str(gpt_pte[part - 1].unique_partition_guid.b, + (char *)disk_partition_uuid(info), + UUID_STR_FORMAT_GUID); + } #ifdef CONFIG_PARTITION_TYPE_GUID uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b, info->type_guid, UUID_STR_FORMAT_GUID); @@ -415,10 +416,7 @@ int gpt_fill_pte(struct blk_desc *desc, le64_to_cpu(gpt_h->last_usable_lba); int i, k; size_t efiname_len, dosname_len; -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - char *str_uuid; unsigned char *bin_uuid; -#endif #ifdef CONFIG_PARTITION_TYPE_GUID char *str_type_guid; unsigned char *bin_type_guid; @@ -487,16 +485,19 @@ int gpt_fill_pte(struct blk_desc *desc, &partition_basic_data_guid, 16); #endif -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - str_uuid = partitions[i].uuid; - bin_uuid = gpt_e[i].unique_partition_guid.b; + if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) { + const char *str_uuid; + + str_uuid = disk_partition_uuid(&partitions[i]); + bin_uuid = gpt_e[i].unique_partition_guid.b; - if (uuid_str_to_bin(str_uuid, bin_uuid, UUID_STR_FORMAT_GUID)) { - log_debug("Partition no. %d: invalid guid: %s\n", - i, str_uuid); - return -EINVAL; + if (uuid_str_to_bin(str_uuid, bin_uuid, + UUID_STR_FORMAT_GUID)) { + log_debug("Partition no. %d: invalid guid: %s\n", + i, str_uuid); + return -EINVAL; + } } -#endif /* partition attributes */ memset(&gpt_e[i].attributes, 0, diff --git a/fs/fat/fat.c b/fs/fat/fat.c index d1476aa433d6..8ff1fd0ec835 100644 --- a/fs/fat/fat.c +++ b/fs/fat/fat.c @@ -110,9 +110,7 @@ int fat_register_device(struct blk_desc *dev_desc, int part_no) info.name[0] = 0; info.type[0] = 0; info.bootable = 0; -#if CONFIG_IS_ENABLED(PARTITION_UUIDS) - info.uuid[0] = 0; -#endif + disk_partition_clr_uuid(&info); } return fat_set_blk_dev(dev_desc, &info); diff --git a/include/part.h b/include/part.h index dfe1dc08baa4..303ccd036754 100644 --- a/include/part.h +++ b/include/part.h @@ -80,6 +80,33 @@ struct disk_partition { #endif }; +/* Accessors for struct disk_partition field ->uuid */ +extern char *__invalid_use_of_disk_partition_uuid; + +static inline const char *disk_partition_uuid(const struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + return info->uuid; +#else + return __invalid_use_of_disk_partition_uuid; +#endif +} + +static inline void disk_partition_set_uuid(struct disk_partition *info, + const char *val) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + strlcpy(info->uuid, val, UUID_STR_LEN + 1); +#endif +} + +static inline void disk_partition_clr_uuid(struct disk_partition *info) +{ +#if CONFIG_IS_ENABLED(PARTITION_UUIDS) + *info->uuid = '\0'; +#endif +} + struct disk_part { int partnum; struct disk_partition gpt_part_info;