summaryrefslogtreecommitdiff
path: root/sbin/fdisk/fdisk.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2015-11-18 02:32:57 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2015-11-18 02:32:57 +0000
commit4b744b8270992e26ce5340e5ddb5fd5aa4c5a60a (patch)
treed88ebb799ed09cff46d2a3db5cd85b2cd0e384c6 /sbin/fdisk/fdisk.c
parent97021d33639128465c1cc20b4ec2d8b7fa085596 (diff)
Rejig the MBR file reading logic so
1) If mbr_file is NULL use built-in mbr for -i, -u and 'reinit'. 2) If mbr_file cannot be opened issue a warning and use built-in mbr for -i, -u, and 'reinit'. 3) If mbr_file can't be read, bail out of fdisk. 4) Use the mbr read from mbr_file for -i, -u, and 'reinit'. Remove inappropriate GPT dancing. This restores pre-GPT-editing mbr_file handling and makes the logic clearer at the expense of a tiny bit of duplication.
Diffstat (limited to 'sbin/fdisk/fdisk.c')
-rw-r--r--sbin/fdisk/fdisk.c37
1 files changed, 16 insertions, 21 deletions
diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c
index d41a7dd82ef..0b7f7be1f74 100644
--- a/sbin/fdisk/fdisk.c
+++ b/sbin/fdisk/fdisk.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: fdisk.c,v 1.90 2015/11/18 01:53:12 krw Exp $ */
+/* $OpenBSD: fdisk.c,v 1.91 2015/11/18 02:32:56 krw Exp $ */
/*
* Copyright (c) 1997 Tobias Weingartner
@@ -184,30 +184,25 @@ main(int argc, char *argv[])
}
/* Create initial/default MBR. */
- if (mbrfile != NULL && (fd = open(mbrfile, O_RDONLY)) == -1) {
- warn("%s", mbrfile);
- warnx("using builtin MBR");
- memset(&initial_mbr, 0, sizeof(initial_mbr));
- mbrfile = NULL;
- }
if (mbrfile == NULL) {
- if (MBR_protective_mbr(&initial_mbr) != 0) {
+ memcpy(&dos_mbr, builtin_mbr, sizeof(dos_mbr));
+ } else {
+ fd = open(mbrfile, O_RDONLY);
+ if (fd == -1) {
+ warn("%s", mbrfile);
+ warnx("using builtin MBR");
memcpy(&dos_mbr, builtin_mbr, sizeof(dos_mbr));
+ } else {
+ len = read(fd, &dos_mbr, sizeof(dos_mbr));
+ close(fd);
+ if (len == -1)
+ err(1, "Unable to read MBR from '%s'", mbrfile);
+ else if (len != sizeof(dos_mbr))
+ errx(1, "Unable to read complete MBR from '%s'",
+ mbrfile);
}
- } else {
- len = read(fd, &dos_mbr, sizeof(dos_mbr));
- if (len == -1)
- err(1, "Unable to read MBR from '%s'", mbrfile);
- else if (len != sizeof(dos_mbr))
- errx(1, "Unable to read complete MBR from '%s'",
- mbrfile);
- close(fd);
- }
- if (f_flag || MBR_protective_mbr(&initial_mbr) != 0) {
- memset(&gh, 0, sizeof(gh));
- memset(&gp, 0, sizeof(gp));
- MBR_parse(&dos_mbr, 0, 0, &initial_mbr);
}
+ MBR_parse(&dos_mbr, 0, 0, &initial_mbr);
query = NULL;
if (i_flag) {