summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2015-11-18 02:32:56 +0000
committerkrw <krw@openbsd.org>2015-11-18 02:32:56 +0000
commitf65ec0feac18fcd9855b994458895d4b99b546e5 (patch)
treefe14b0a9520839ce47479d93d3bc6f9b81bee39c
parentUSER_edit() (a.k.a. -e) edits the on-disk information. So zap GPT (diff)
downloadwireguard-openbsd-f65ec0feac18fcd9855b994458895d4b99b546e5.tar.xz
wireguard-openbsd-f65ec0feac18fcd9855b994458895d4b99b546e5.zip
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.
-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) {