diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-09-12 16:36:53 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2021-09-12 16:36:53 +0000 |
commit | 1b9c507415aff8aded3572043d842232f0da0b03 (patch) | |
tree | dd90987ef22ea3247c7479aa74cf66b3b73c6f9b /sbin/fdisk/gpt.c | |
parent | 3c46e71e62d572a23d8b80e76fa3d90412e2f637 (diff) |
Stop taking detour through unit_types[SECTORS] to find
dl.d_secsize.
Leave unit_types[SECTORS].ut_conversion at 0, and test that to
determine if a size needs to be converted from a sectors value.
Use consistent dance to find the desired size value to print.
Logic is clearer, unit_types[] is now const, nobody but misc.c
knows about SECTORS.
No intentional functional change.
Diffstat (limited to 'sbin/fdisk/gpt.c')
-rw-r--r-- | sbin/fdisk/gpt.c | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c index 9d1435c031c..0130b73ee11 100644 --- a/sbin/fdisk/gpt.c +++ b/sbin/fdisk/gpt.c @@ -1,4 +1,4 @@ -/* $OpenBSD: gpt.c,v 1.51 2021/08/24 15:36:05 krw Exp $ */ +/* $OpenBSD: gpt.c,v 1.52 2021/09/12 16:36:52 krw Exp $ */ /* * Copyright (c) 2015 Markus Muller <mmu@grummel.net> * Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org> @@ -296,7 +296,7 @@ GPT_read(const int which) void GPT_print(const char *units, const int verbosity) { - const int secsize = unit_types[SECTORS].ut_conversion; + const int secsize = dl.d_secsize; struct uuid guid; char *guidstr = NULL; double size; @@ -339,11 +339,14 @@ GPT_print(const char *units, const int verbosity) #endif /* DEBUG */ u = unit_lookup(units); - size = ((double)DL_GETDSIZE(&dl) * secsize) / unit_types[u].ut_conversion; + size = DL_GETDSIZE(&dl); + if (unit_types[u].ut_conversion != 0) + size = (size * secsize) / unit_types[u].ut_conversion; printf("Disk: %s Usable LBA: %llu to %llu [%.0f ", - disk.dk_name, letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end), size); + disk.dk_name, letoh64(gh.gh_lba_start), letoh64(gh.gh_lba_end), + size); - if (u == SECTORS && secsize != DEV_BSIZE) + if (unit_types[u].ut_conversion == 0 && secsize != DEV_BSIZE) printf("%d-byte ", secsize); printf("%s]\n", unit_types[u].ut_lname); @@ -383,14 +386,15 @@ GPT_print_part(const int n, const char *units, const int verbosity) struct uuid guid; struct gpt_partition *partn = &gp[n]; char *guidstr = NULL; - const int secsize = unit_types[SECTORS].ut_conversion; + const int secsize = dl.d_secsize; double size; int u, status; uuid_dec_le(&partn->gp_type, &guid); u = unit_lookup(units); size = letoh64(partn->gp_lba_end) - letoh64(partn->gp_lba_start) + 1; - size = (size * secsize) / unit_types[u].ut_conversion; + if (unit_types[u].ut_conversion != 0) + size = (size * secsize) / unit_types[u].ut_conversion; 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), @@ -474,7 +478,7 @@ init_gh(void) { struct gpt_header oldgh; struct uuid guid; - const int secsize = unit_types[SECTORS].ut_conversion; + const int secsize = dl.d_secsize; int needed; uint32_t status; |