[U-Boot] [PATCH v3 1/5] GPT: add accessor function for disk GUID

Lothar Waßmann
2017-06-06T08:20:36Z

Hi,

On Fri, 2 Jun 2017 19:22:30 -0700 alison at peloton-tech.com wrote:
> From: Alison Chaiken <alison@peloton-tech.com>
>
> In order to read the GPT, modify the partition name strings, and then
> write out a new GPT, the disk GUID is needed. While there is an
> existing accessor for the partition UUIDs, there is none yet for the
> disk GUID.
>
> Signed-off-by: Alison Chaiken <alison@peloton-tech.com>
> ---
> cmd/gpt.c | 26 ++++++++++++++++++++++++++
> disk/part_efi.c | 31 +++++++++++++++++++++++++++++++
> doc/README.gpt | 3 ++-
> include/part.h | 15 +++++++++++++++
> 4 files changed, 74 insertions(+), 1 deletion(-)
>
> diff --git a/cmd/gpt.c b/cmd/gpt.c
> index 3e98821..4d00a35 100644
> --- a/cmd/gpt.c
> +++ b/cmd/gpt.c
> @@ -398,6 +398,23 @@ static int gpt_verify(struct blk_desc *blk_dev_desc, const char *str_part)
> return ret;
> }
>
> +static int do_disk_guid(struct blk_desc *dev_desc, char * const namestr)
> +{
> + int ret;
> + char disk_guid[UUID_STR_LEN + 1];
> +
> + ret = get_disk_guid(dev_desc, disk_guid);
> + if (ret < 0)
> + return CMD_RET_FAILURE;
> +
> + if (namestr)
> + setenv(namestr, disk_guid);
> + else
> + printf("%s\n", disk_guid);
> +
> + return ret;
>
For consistency this should be:
return CMD_RET_SUCCESS;
but see below.

> /**
> * do_gpt(): Perform GPT operations
> *
> @@ -436,6 +453,8 @@ static int do_gpt(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
> } else if ((strcmp(argv[1], "verify") == 0)) {
> ret = gpt_verify(blk_dev_desc, argv[4]);
> printf("Verify GPT: ");
> + } else if (strcmp(argv[1], "guid") == 0) {
> + return do_disk_guid(blk_dev_desc, argv[4]);
> } else {
> return CMD_RET_USAGE;
> }
IMO you should use the existing error handling infrastructure lateron
in this file and just assign the return value of the subcommand
handlers to 'ret' and let the existing code sort out the return code of
this function (just like the gpt_verify() call above does it).

Lothar WaÃŸmann