From 2ea83235a5a82a9ddd2546e1b22538fc443bc978 Mon Sep 17 00:00:00 2001 From: krw Date: Fri, 16 Jul 2021 22:50:43 +0000 Subject: [PATCH] Change PRT_protected_guid() to take native order uuid's instead of little endian uuid's. This brings it into line with all the other PRT_ functions taking uuid parameters. While adapting gsetid(), introduce separate partition type and partition guid variables to make the logic clearer. No intentional functional change. --- sbin/fdisk/cmd.c | 29 ++++++++++++++--------------- sbin/fdisk/part.c | 8 +++----- 2 files changed, 17 insertions(+), 20 deletions(-) diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index ccbb51e8d94..dc8cbcef0ca 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.128 2021/07/15 21:58:02 krw Exp $ */ +/* $OpenBSD: cmd.c,v 1.129 2021/07/16 22:50:43 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -303,7 +303,7 @@ Xedit(char *args, struct mbr *mbr) int gsetpid(int pn) { - struct uuid guid; + struct uuid gp_type, gp_guid; struct gpt_partition *gg, oldgg; int num, status; @@ -314,33 +314,32 @@ gsetpid(int pn) GPT_print_parthdr(TERSE); GPT_print_part(pn, "s", TERSE); - if (PRT_protected_guid(&gg->gp_type)) { - uuid_dec_le(&gg->gp_type, &guid); + uuid_dec_le(&gg->gp_type, &gp_type); + if (PRT_protected_guid(&gp_type)) { printf("can't edit partition type %s\n", - PRT_uuid_to_typename(&guid)); + PRT_uuid_to_typename(&gp_type)); goto done; } /* Ask for partition type or GUID. */ - uuid_dec_le(&gg->gp_type, &guid); - num = ask_pid(PRT_uuid_to_type(&guid), &guid); + num = ask_pid(PRT_uuid_to_type(&gp_type), &gp_type); if (num <= 0xff) - guid = *(PRT_type_to_uuid(num)); - uuid_enc_le(&gg->gp_type, &guid); - if (PRT_protected_guid(&gg->gp_type)) { - uuid_dec_le(&gg->gp_type, &guid); + gp_type = *(PRT_type_to_uuid(num)); + if (PRT_protected_guid(&gp_type)) { printf("can't change partition type to %s\n", - PRT_uuid_to_typename(&guid)); + PRT_uuid_to_typename(&gp_type)); goto done; } + uuid_enc_le(&gg->gp_type, &gp_type); - if (uuid_is_nil(&gg->gp_guid, NULL)) { - uuid_create(&guid, &status); + uuid_dec_le(&gg->gp_guid, &gp_guid); + if (uuid_is_nil(&gp_guid, NULL)) { + uuid_create(&gp_guid, &status); if (status != uuid_s_ok) { printf("could not create guid for partition\n"); goto done; } - uuid_enc_le(&gg->gp_guid, &guid); + uuid_enc_le(&gg->gp_guid, &gp_guid); } if (memcmp(gg, &oldgg, sizeof(*gg))) diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index eb4434dd98e..14e8ba92f6d 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.98 2021/07/16 13:26:04 krw Exp $ */ +/* $OpenBSD: part.c,v 1.99 2021/07/16 22:50:43 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -157,16 +157,14 @@ static const struct protected_guid { #endif int -PRT_protected_guid(const struct uuid *leuuid) +PRT_protected_guid(const struct uuid *uuid) { - struct uuid uuid; char *str = NULL; int rslt; unsigned int i; uint32_t status; - uuid_dec_le(leuuid, &uuid); - uuid_to_string(&uuid, &str, &status); + uuid_to_string(uuid, &str, &status); if (status != uuid_s_ok) { rslt = 1; goto done; -- 2.20.1