summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkrw <krw@openbsd.org>2011-06-02 17:00:24 +0000
committerkrw <krw@openbsd.org>2011-06-02 17:00:24 +0000
commit6b38f2f9c7b1623a67c10e87633b574384f29fb2 (patch)
tree745defbfd309518470d8a4ab3e6f738329e88cb9
parentdon't exit from the main loop if there are pending time outs. (diff)
downloadwireguard-openbsd-6b38f2f9c7b1623a67c10e87633b574384f29fb2.tar.xz
wireguard-openbsd-6b38f2f9c7b1623a67c10e87633b574384f29fb2.zip
Hack to ensure that the in-core labels contain the current bounds
info from the physical disk after 'disklabel -e' writes the label to disk. Saves having to reboot or do other contortions to initialize these fields. Toss in same treatment for total sectors so all fields forcibly set by kernel have current values. 0'ing of the bounds noted by matthew@. 'lovely' deraadt@
-rw-r--r--sbin/disklabel/disklabel.c13
1 files changed, 12 insertions, 1 deletions
diff --git a/sbin/disklabel/disklabel.c b/sbin/disklabel/disklabel.c
index 4a2223ff464..d0e74e1c5e6 100644
--- a/sbin/disklabel/disklabel.c
+++ b/sbin/disklabel/disklabel.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: disklabel.c,v 1.179 2011/05/22 13:05:47 otto Exp $ */
+/* $OpenBSD: disklabel.c,v 1.180 2011/06/02 17:00:24 krw Exp $ */
/*
* Copyright (c) 1987, 1993
@@ -842,6 +842,7 @@ edit(struct disklabel *lp, int f)
int first, ch, fd, error = 0;
struct disklabel label;
FILE *fp;
+ u_int64_t total_sectors, starting_sector, ending_sector;
if ((fd = mkstemp(tmpfil)) == -1 || (fp = fdopen(fd, "w")) == NULL) {
if (fd != -1)
@@ -867,8 +868,18 @@ edit(struct disklabel *lp, int f)
warn("%s", tmpfil);
break;
}
+ /* Get values set by OS and not the label. */
+ if (ioctl(f, DIOCGPDINFO, &label) < 0)
+ err(4, "ioctl DIOCGPDINFO");
+ ending_sector = DL_GETBEND(&label);
+ starting_sector = DL_GETBSTART(&label);
+ total_sectors = DL_GETDSIZE(&label);
memset(&label, 0, sizeof(label));
error = getasciilabel(fp, &label);
+ DL_SETBEND(&label, ending_sector);
+ DL_SETBSTART(&label, starting_sector);
+ DL_SETDSIZE(&label, total_sectors);
+
if (error == 0) {
if (cmplabel(lp, &label) == 0) {
puts("No changes.");