diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2023-04-09 17:20:00 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2023-04-09 17:20:00 +0000 |
commit | 9d9ec701ad7d617c368b86c7b2054b4f897641a9 (patch) | |
tree | 6eca6c316795c79a351b2c23e7f65d0f23cbd00b /sbin/fdisk/part.c | |
parent | 0e7b9263b431c9e78de132dba76b7df82fbd9508 (diff) |
Refactor and simplify GPT menu selection logic.
No intentional functional change.
Diffstat (limited to 'sbin/fdisk/part.c')
-rw-r--r-- | sbin/fdisk/part.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c index d3d4cae324d..e67f9be399a 100644 --- a/sbin/fdisk/part.c +++ b/sbin/fdisk/part.c @@ -1,4 +1,4 @@ -/* $OpenBSD: part.c,v 1.153 2023/04/08 15:25:47 krw Exp $ */ +/* $OpenBSD: part.c,v 1.154 2023/04/09 17:19:59 krw Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -1091,39 +1091,38 @@ PRT_uuid_to_desc(const struct uuid *uuid) return guid; } -int -PRT_uuid_to_menuid(const struct uuid *uuid) +char * +PRT_uuid_to_menudflt(const struct uuid *uuid) { - const struct gpt_type *gt; + char *dflt; unsigned int i; + uint32_t status; - gt = find_gpt_type(uuid); - if (gt != NULL) { - for (i = 0; i < nitems(menu_items); i++) { - if (gpt_item(i) == 0 && - strcasecmp(menu_items[i].mi_guid, gt->gt_guid) == 0) - return menu_items[i].mi_menuid; - } + uuid_to_string(uuid, &dflt, &status); + if (status != uuid_s_ok) + return NULL; + + for (i = 0; i < nitems(menu_items); i++) { + if (gpt_item(i) || strcasecmp(menu_items[i].mi_guid, dflt)) + continue; + free(dflt); + dflt = NULL; + if (asprintf(&dflt, "%X", menu_items[i].mi_menuid) == -1) + return NULL; } - return -1; + return dflt; } -const struct uuid * -PRT_menuid_to_uuid(const int menuid) +const char * +PRT_menuid_to_guid(const int menuid) { - static struct uuid uuid; unsigned int i; - uint32_t status = uuid_s_ok; for (i = 0; i < nitems(menu_items); i++) { - if (gpt_item(i) == 0 && menu_items[i].mi_menuid == menuid) { - uuid_from_string(menu_items[i].mi_guid, &uuid, &status); - break; - } + if (gpt_item(i) == 0 && menu_items[i].mi_menuid == menuid) + return menu_items[i].mi_guid; } - if (i == nitems(menu_items) || status != uuid_s_ok) - uuid_create_nil(&uuid, NULL); - return &uuid; + return NULL; } |