[U-Boot] [PATCH v6 3/3] GPT: provide commands to selectively rename partitions

Tom Rini trini at konsulko.com
Sun Jun 11 13:38:43 UTC 2017


On Sat, Jun 10, 2017 at 04:33:37PM -0700, alison at peloton-tech.com wrote:
> From: Alison Chaiken <alison at peloton-tech.com>
> 
> This patch provides support in u-boot for renaming GPT
> partitions.  The renaming is accomplished via new 'gpt swap'
> and 'gpt rename' commands.
> 
> The 'swap' mode prints a warning if no matching partition names
> are found.  If only one matching name of a provided pair is found, it
> renames the matching partitions to the new name.

So in the case where 'gpt swap partA partB' is used and partB doesn't
exist, it's the same as 'gpt rename partA partB' ?  That seems like it
might surprise users and I think if we changed:

> +	if (!strcmp(subcomm, "swap")) {
> +		if ((strlen(name1) > PART_NAME_LEN) || (strlen(name2) > PART_NAME_LEN)) {
> +			printf("Names longer than %d characters are truncated.\n", PART_NAME_LEN);
> +			return -EINVAL;
> +		}
> +		list_for_each(pos, &disk_partitions) {
> +			curr = list_entry(pos, struct disk_part, list);
> +			if (!strcmp((char *)curr->gpt_part_info.name, name1)) {
> +				strcpy((char *)curr->gpt_part_info.name, name2);
> +				changed++;
> +			}
> +			else if (!strcmp((char *)curr->gpt_part_info.name, name2)) {
> +				strcpy((char *)curr->gpt_part_info.name, name1);
> +				changed++;
> +			}
> +
> +		}
> +		if (changed == 0) {
> +			printf("No matching partition names were found.\n");
> +			return ret;
> +		}

We could also test for if changed == 1 and return an error.  I assume
that a GPT with the same name used more than one time is already
invalid, but we could be defensive here and test for != 2 instead.
Thanks!

-- 
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 819 bytes
Desc: Digital signature
URL: <http://lists.denx.de/pipermail/u-boot/attachments/20170611/fefff049/attachment.sig>


More information about the U-Boot mailing list