summaryrefslogtreecommitdiff
path: root/sbin/fdisk
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2021-05-15 00:01:22 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2021-05-15 00:01:22 +0000
commitbb9108b3163a798c72379c7728a5879ad3942b34 (patch)
tree5ab216f9183d3f0ddfa900ec4507dea287d674a4 /sbin/fdisk
parent6f44d5d2112c509b7e0494839daef849b538eb0a (diff)
Shuffle GPT_read() code into a nice switch{}, eliminating
unnecesary read of primary GPT when only the secondary GPT is requested. No intentional functional change.
Diffstat (limited to 'sbin/fdisk')
-rw-r--r--sbin/fdisk/gpt.c35
1 files changed, 20 insertions, 15 deletions
diff --git a/sbin/fdisk/gpt.c b/sbin/fdisk/gpt.c
index 113ec5648be..e145bb0457e 100644
--- a/sbin/fdisk/gpt.c
+++ b/sbin/fdisk/gpt.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: gpt.c,v 1.14 2021/05/10 17:16:01 krw Exp $ */
+/* $OpenBSD: gpt.c,v 1.15 2021/05/15 00:01:21 krw Exp $ */
/*
* Copyright (c) 2015 Markus Muller <mmu@grummel.net>
* Copyright (c) 2015 Kenneth R Westerback <krw@openbsd.org>
@@ -196,25 +196,30 @@ GPT_read(int which)
{
int valid;
- valid = GPT_get_header(GPTSECTOR);
- if (valid == 0)
- valid = GPT_get_partition_table(gh.gh_part_lba);
- if (which == PRIMARYGPT || (which == ANYGPT && valid == 0))
+ switch (which) {
+ case PRIMARYGPT:
+ valid = GPT_get_header(GPTSECTOR);
+ break;
+ case SECONDARYGPT:
+ valid = GPT_get_header(DL_GETDSIZE(&dl) - 1);
+ break;
+ case ANYGPT:
+ valid = GPT_get_header(GPTSECTOR);
+ if (valid != 0 || GPT_get_partition_table(gh.gh_part_lba) != 0)
+ valid = GPT_get_header(DL_GETDSIZE(&dl) - 1);
+ break;
+ default:
return;
+ }
- /* No valid GPT found. Zap any artifacts. */
- memset(&gh, 0, sizeof(gh));
- memset(&gp, 0, sizeof(gp));
-
- valid = GPT_get_header(DL_GETDSIZE(&dl) - 1);
if (valid == 0)
valid = GPT_get_partition_table(gh.gh_part_lba);
- if (which == SECONDARYGPT || valid == 0)
- return;
- /* No valid GPT found. Zap any artifacts. */
- memset(&gh, 0, sizeof(gh));
- memset(&gp, 0, sizeof(gp));
+ if (valid != 0) {
+ /* No valid GPT found. Zap any artifacts. */
+ memset(&gh, 0, sizeof(gh));
+ memset(&gp, 0, sizeof(gp));
+ }
}
void