summaryrefslogtreecommitdiff
path: root/sbin
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2023-04-11 21:14:20 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2023-04-11 21:14:20 +0000
commitea579f9e5dc96dec6249f7bc80121f7ded88e861 (patch)
treed9309a59dab73a2fdfac1749dc12292e2fdc096f /sbin
parent0fc51a10813ae8a61a65e30ff0563f4fd602f41c (diff)
Abstract find_[gpt|mbr]_menuitem() to simplify code and
prepare for future uses. No functional change.
Diffstat (limited to 'sbin')
-rw-r--r--sbin/fdisk/part.c56
1 files changed, 43 insertions, 13 deletions
diff --git a/sbin/fdisk/part.c b/sbin/fdisk/part.c
index 885481f4666..943158c256d 100644
--- a/sbin/fdisk/part.c
+++ b/sbin/fdisk/part.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: part.c,v 1.157 2023/04/11 17:26:59 krw Exp $ */
+/* $OpenBSD: part.c,v 1.158 2023/04/11 21:14:19 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -732,11 +732,13 @@ const struct menu_item menu_items[] = {
};
const struct gpt_type *find_gpt_type(const struct uuid *);
+const struct menu_item *find_gpt_menuitem(const struct gpt_type *);
const char *find_gpt_desc(const struct gpt_type *);
int gpt_item(const unsigned int);
int uuid_attr(const struct uuid *);
const struct mbr_type *find_mbr_type(const int);
+const struct menu_item *find_mbr_menuitem(const struct mbr_type *);
const char *find_mbr_desc(const struct mbr_type *);
int mbr_item(const unsigned int);
@@ -767,24 +769,38 @@ find_gpt_type(const struct uuid *uuid)
return gt;
}
-const char *
-find_gpt_desc(const struct gpt_type *gt)
+const struct menu_item *
+find_gpt_menuitem(const struct gpt_type *gt)
{
- unsigned int i;
+ unsigned int i;
if (gt != NULL) {
- if (gt->gt_desc != NULL)
- return gt->gt_desc;
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_name;
+ return &menu_items[i];
}
}
return NULL;
}
+const char *
+find_gpt_desc(const struct gpt_type *gt)
+{
+ const struct menu_item *mi;
+
+ if (gt != NULL) {
+ if (gt->gt_desc != NULL)
+ return gt->gt_desc;
+ mi = find_gpt_menuitem(gt);
+ if (mi)
+ return mi->mi_name;
+ }
+
+ return NULL;
+}
+
int
gpt_item(const unsigned int item)
{
@@ -819,19 +835,33 @@ find_mbr_type(const int id)
return mt;
}
+const struct menu_item *
+find_mbr_menuitem(const struct mbr_type *mt)
+{
+ unsigned int i;
+
+ if (mt != NULL) {
+ for (i = 0; i < nitems(menu_items); i++) {
+ if (mbr_item(i) == 0
+ && menu_items[i].mi_mbrid == mt->mt_type)
+ return &menu_items[i];
+ }
+ }
+
+ return NULL;
+}
+
const char *
find_mbr_desc(const struct mbr_type *mt)
{
- unsigned int i;
+ const struct menu_item *mi;
if (mt != NULL) {
if (mt->mt_desc != NULL)
return mt->mt_desc;
- for (i = 0; i < nitems(menu_items); i++) {
- if (mbr_item(i) == 0 &&
- menu_items[i].mi_mbrid == mt->mt_type)
- return menu_items[i].mi_name;
- }
+ mi = find_mbr_menuitem(mt);
+ if (mi)
+ return mi->mi_name;
}
return NULL;