disk_partition_uuid() and disk_partition_set_uuid() were introduced to let
us avoid the usage of #ifdef when dealing with the field uuid of
struct disk_partition.

In allocate_disk_part() commit c5f1d005f517 ("part: Add accessors for
struct disk_partition uuid") missed to use the setter.

print_gpt_info() and create_gpt_partitions_list() are further functions
where we should use the getter.

Fixes: c5f1d005f517 ("part: Add accessors for struct disk_partition uuid")
Signed-off-by: Heinrich Schuchardt <heinrich.schucha...@canonical.com>
---
v2:
        new patch
---
 cmd/gpt.c | 23 ++++++++++++-----------
 1 file changed, 12 insertions(+), 11 deletions(-)

diff --git a/cmd/gpt.c b/cmd/gpt.c
index 8969efba8c..092f7defff 100644
--- a/cmd/gpt.c
+++ b/cmd/gpt.c
@@ -211,10 +211,9 @@ 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;
-       if (IS_ENABLED(CONFIG_PARTITION_UUIDS)) {
-               strlcpy(newpart->gpt_part_info.uuid, disk_partition_uuid(info),
-                       UUID_STR_LEN + 1);
-       }
+       if (IS_ENABLED(CONFIG_PARTITION_UUIDS))
+               disk_partition_set_uuid(&newpart->gpt_part_info,
+                                       disk_partition_uuid(info));
        newpart->partnum = partnum;
 
        return newpart;
@@ -250,9 +249,9 @@ static void print_gpt_info(void)
                       curr->gpt_part_info.name);
                printf("Type %s, bootable %d\n", curr->gpt_part_info.type,
                       curr->gpt_part_info.bootable & PART_BOOTABLE);
-#ifdef CONFIG_PARTITION_UUIDS
-               printf("UUID %s\n", curr->gpt_part_info.uuid);
-#endif
+               if (CONFIG_IS_ENABLED(PARTITION_UUIDS))
+                       printf("UUID %s\n",
+                              disk_partition_uuid(&curr->gpt_part_info));
                printf("\n");
        }
 }
@@ -296,10 +295,12 @@ static int create_gpt_partitions_list(int numparts, const 
char *guid,
                        (unsigned long long)curr->gpt_part_info.size *
                                            curr->gpt_part_info.blksz);
                strncat(partitions_list, partstr, PART_NAME_LEN + 1);
-
-               strcat(partitions_list, ",uuid=");
-               strncat(partitions_list, curr->gpt_part_info.uuid,
-                       UUID_STR_LEN + 1);
+               if (CONFIG_IS_ENABLED(PARTITION_UUIDS)) {
+                       strcat(partitions_list, ",uuid=");
+                       strncat(partitions_list,
+                               disk_partition_uuid(&curr->gpt_part_info),
+                               UUID_STR_LEN + 1);
+               }
                strcat(partitions_list, ";");
        }
        return 0;
-- 
2.40.1

Reply via email to