summaryrefslogtreecommitdiff
path: root/sbin/fdisk/gpt.c
diff options
context:
space:
mode:
Diffstat (limited to 'sbin/fdisk/gpt.c')
-rw-r--r--sbin/fdisk/gpt.c30
1 files changed, 13 insertions, 17 deletions
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c
index 0130b73ee11..cf562f2fb6a 100644
--- a/sbin/fdisk/gpt.c
+++ b/sbin/fdisk/gpt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpt.c,v 1.52 2021/09/12 16:36:52 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.53 2021/09/13 15:07:51 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -296,11 +296,12 @@ GPT_read(const int which)
void
GPT_print(const char *units, const int verbosity)
{
- const int secsize = dl.d_secsize;
+ const struct unit_type *ut;
struct uuid guid;
+ const int secsize = dl.d_secsize;
char *guidstr = NULL;
double size;
- int i, u, status;
+ int i, status;
#ifdef DEBUG
char *p;
@@ -338,17 +339,13 @@ GPT_print(const char *units, const int verbosity)
printf("\n");
#endif /* DEBUG */
- u = unit_lookup(units);
- size = DL_GETDSIZE(&dl);
- if (unit_types[u].ut_conversion != 0)
- size = (size * secsize) / unit_types[u].ut_conversion;
+ size = units_size(units, DL_GETDSIZE(&dl), &ut);
printf("Disk: %s Usable LBA: %llu to %llu [%.0f ",
disk.dk_name, letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end),
size);
-
- if (unit_types[u].ut_conversion == 0 && secsize != DEV_BSIZE)
+ if (ut->ut_conversion == 0 && secsize != DEV_BSIZE)
printf("%d-byte ", secsize);
- printf("%s]\n", unit_types[u].ut_lname);
+ printf("%s]\n", ut->ut_lname);
if (verbosity == VERBOSE) {
printf("GUID: ");
@@ -383,22 +380,21 @@ GPT_print_parthdr(const int verbosity)
void
GPT_print_part(const int n, const char *units, const int verbosity)
{
+ const struct unit_type *ut;
struct uuid guid;
struct gpt_partition *partn = &gp[n];
char *guidstr = NULL;
- const int secsize = dl.d_secsize;
double size;
- int u, status;
+ uint64_t sectors;
+ int status;
uuid_dec_le(&partn->gp_type, &guid);
- u = unit_lookup(units);
- size = letoh64(partn->gp_lba_end) - letoh64(partn->gp_lba_start) + 1;
- if (unit_types[u].ut_conversion != 0)
- size = (size * secsize) / unit_types[u].ut_conversion;
+ sectors = letoh64(partn->gp_lba_end) - letoh64(partn->gp_lba_start) + 1;
+ size = units_size(units, sectors, &ut);
printf("%c%3d: %-36s [%12lld: %12.0f%s]\n",
(letoh64(partn->gp_attrs) & GPTDOSACTIVE)?'*':' ', n,
PRT_uuid_to_typename(&guid), letoh64(partn->gp_lba_start),
- size, unit_types[u].ut_abbr);
+ size, ut->ut_abbr);
if (verbosity == VERBOSE) {
uuid_dec_le(&partn->gp_guid, &guid);