grub-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v2 5/7] partmap/gpt: add print function for guids


From: Daniel Kiper
Subject: Re: [PATCH v2 5/7] partmap/gpt: add print function for guids
Date: Tue, 28 Feb 2023 18:17:35 +0100
User-agent: NeoMutt/20170113 (1.7.2)

On Mon, Feb 20, 2023 at 07:56:28PM +0100, Oliver Steffen wrote:
> Code to print gpt patition guids has been duplicated in multiple places.
> Add a common function for that.
>
> Signed-off-by: Oliver Steffen <osteffen@redhat.com>
> ---
>  grub-core/partmap/gpt.c      | 13 +++++++++++++
>  include/grub/gpt_partition.h |  6 ++++++
>  2 files changed, 19 insertions(+)
>
> diff --git a/grub-core/partmap/gpt.c b/grub-core/partmap/gpt.c
> index 075cc96f1..e0da7e885 100644
> --- a/grub-core/partmap/gpt.c
> +++ b/grub-core/partmap/gpt.c
> @@ -227,6 +227,19 @@ static struct grub_partition_map grub_gpt_partition_map =
>  #endif
>    };
>
> +int
> +grub_gpt_part_guid_snprint (char *str, grub_size_t n, const 
> grub_gpt_part_guid_t *guid)

The GUIDs are used not only for disks. They are generic thing and this
function should be put in the common __non-EFI__ GRUB code.

> +{
> +  return grub_snprintf (str, n,
> +                      GRUB_PRIxGPT_GUID,
> +                      grub_le_to_cpu32 (guid->data1),
> +                      grub_le_to_cpu16 (guid->data2),
> +                      grub_le_to_cpu16 (guid->data3),
> +                      guid->data4[0], guid->data4[1], guid->data4[2],
> +                      guid->data4[3], guid->data4[4], guid->data4[5],
> +                      guid->data4[6], guid->data4[7]);
> +}
> +
>  GRUB_MOD_INIT(part_gpt)
>  {
>    grub_partition_map_register (&grub_gpt_partition_map);
> diff --git a/include/grub/gpt_partition.h b/include/grub/gpt_partition.h
> index 7a93f4329..9b1660322 100644
> --- a/include/grub/gpt_partition.h
> +++ b/include/grub/gpt_partition.h
> @@ -50,6 +50,9 @@ typedef struct grub_gpt_part_guid grub_gpt_part_guid_t;
>       { 0x85, 0xD2, 0xE1, 0xE9, 0x04, 0x34, 0xCF, 0xB3 }      \
>    }
>
> +#define GRUB_PRIxGPT_GUID "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x"

s/GRUB_PRIxGPT_GUID/PRIxGRUB_GUID/

> +#define GRUB_GPT_GUID_STR_LEN 36

#define GRUB_GUID_STRLEN (sizeof("AAAABBBB-CCCC-DDDD-EEEE-FFFFFFFFFFFF") - 1)

The result is the same but everybody knows what you are aiming for.
(stolen from grub-core/commands/probe.c; you could replace
  char val[37] = "none";
with
  char val[GRUB_GUID_STRLEN + 1] = "none";
there).

Daniel



reply via email to

[Prev in Thread] Current Thread [Next in Thread]