No intentional functional change.
-/* $OpenBSD: cmd.c,v 1.174 2023/04/07 16:34:41 krw Exp $ */
+/* $OpenBSD: cmd.c,v 1.175 2023/04/09 17:19:59 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
const struct uuid *
ask_uuid(const struct uuid *olduuid)
{
- static struct uuid uuid;
char lbuf[LINEBUFSZ];
- char *dflt = NULL;
+ static struct uuid uuid;
+ const char *guid;
+ char *dflt;
uint32_t status;
- int menuid;
- menuid = PRT_uuid_to_menuid(olduuid);
- if (menuid == -1) {
- uuid_to_string(olduuid, &dflt, &status);
- if (status != uuid_s_ok) {
- printf("uuid_to_string() failed\n");
+ dflt = PRT_uuid_to_menudflt(olduuid);
+ if (dflt == NULL) {
+ if (asprintf(&dflt, "0") == -1) {
+ warn("asprintf()");
goto done;
}
- } else if (asprintf(&dflt, "%X", menuid) == -1) {
- warn("asprintf()");
- goto done;
}
for (;;) {
goto done;
}
- uuid_from_string(lbuf, &uuid, &status);
+ guid = PRT_menuid_to_guid(hex_octet(lbuf));
+ if (guid == NULL)
+ guid = lbuf;
+
+ uuid_from_string(guid, &uuid, &status);
if (status == uuid_s_ok)
goto done;
- menuid = hex_octet(lbuf);
- switch (menuid) {
- case -1:
- printf("'%s' is not a valid partition id\n", lbuf);
- break;
- case 0:
- uuid_create_nil(&uuid, NULL);
- goto done;
- default:
- uuid = *PRT_menuid_to_uuid(menuid);
- if (uuid_is_nil(&uuid, NULL) == 0)
- goto done;
- printf("'%s' has no associated UUID\n", lbuf);
- break;
- }
+ printf("'%s' has no associated UUID\n", lbuf);
}
done:
-/* $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
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;
}
-/* $OpenBSD: part.h,v 1.44 2023/04/07 14:42:51 krw Exp $ */
+/* $OpenBSD: part.h,v 1.45 2023/04/09 17:19:59 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
void PRT_print_part(const int, const struct prt *, const char *);
void PRT_print_parthdr(void);
const char *PRT_uuid_to_desc(const struct uuid *);
-int PRT_uuid_to_menuid(const struct uuid *);
-const struct uuid *PRT_menuid_to_uuid(const int);
+char *PRT_uuid_to_menudflt(const struct uuid *);
+const char *PRT_menuid_to_guid(const int);
int PRT_protected_uuid(const struct uuid *);
int PRT_lba_to_chs(const struct prt*, struct chs *, struct chs*);