]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
part: Add accessors for struct disk_partition type_uuid
authorSimon Glass <sjg@chromium.org>
Thu, 24 Aug 2023 19:55:32 +0000 (13:55 -0600)
committerTom Rini <trini@konsulko.com>
Fri, 25 Aug 2023 21:55:18 +0000 (17:55 -0400)
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 <sjg@chromium.org>
disk/part.c
disk/part_efi.c
include/part.h

index 91c6ac42cc83dfcd6621561a3c721559011bfd79..72241b7b232c11a4244bb0143ddd8e24261a2077 100644 (file)
@@ -370,9 +370,7 @@ int part_get_info_by_type(struct blk_desc *desc, int part, int part_type,
        if (blk_enabled()) {
                /* The common case is no UUID support */
                disk_partition_clr_uuid(info);
-#ifdef CONFIG_PARTITION_TYPE_GUID
-               info->type_guid[0] = 0;
-#endif
+               disk_partition_clr_type_guid(info);
 
                if (part_type == PART_TYPE_UNKNOWN) {
                        drv = part_driver_lookup_type(desc);
@@ -415,9 +413,7 @@ int part_get_info_whole_disk(struct blk_desc *desc,
        strcpy((char *)info->type, BOOT_PART_TYPE);
        strcpy((char *)info->name, "Whole Disk");
        disk_partition_clr_uuid(info);
-#ifdef CONFIG_PARTITION_TYPE_GUID
-       info->type_guid[0] = 0;
-#endif
+       disk_partition_clr_type_guid(info);
 
        return 0;
 }
index a6f7375cd38a5726d7cbbe9c290b5734564b9600..20867521382247326e273ce725b60b9827683ac4 100644 (file)
@@ -294,10 +294,11 @@ int part_get_info_efi(struct blk_desc *desc, int part,
                                (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);
-#endif
+       if (IS_ENABLED(CONFIG_PARTITION_TYPE_GUID)) {
+               uuid_bin_to_str(gpt_pte[part - 1].partition_type_guid.b,
+                               (char *)disk_partition_type_uuid(info),
+                               UUID_STR_FORMAT_GUID);
+       }
 
        log_debug("start 0x" LBAF ", size 0x" LBAF ", name %s\n", info->start,
                  info->size, info->name);
index 8e5e543c56ec7a568e26aa81ecbd428e08655871..5cf1c5ec96f0b59ef55fad69fac550d3044e7a5f 100644 (file)
@@ -107,6 +107,34 @@ static inline void disk_partition_clr_uuid(struct disk_partition *info)
 #endif
 }
 
+/* Accessors for struct disk_partition field ->type_guid */
+extern char *__invalid_use_of_disk_partition_type_uuid;
+
+static inline const
+char *disk_partition_type_uuid(const struct disk_partition *info)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+       return info->type_guid;
+#else
+       return __invalid_use_of_disk_partition_type_uuid;
+#endif
+}
+
+static inline void disk_partition_set_type_guid(struct disk_partition *info,
+                                               const char *val)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+       strlcpy(info->type_guid, val, UUID_STR_LEN + 1);
+#endif
+}
+
+static inline void disk_partition_clr_type_guid(struct disk_partition *info)
+{
+#ifdef CONFIG_PARTITION_TYPE_GUID
+       *info->type_guid = '\0';
+#endif
+}
+
 struct disk_part {
        int partnum;
        struct disk_partition gpt_part_info;