diff options
author | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-06-02 17:00:25 +0000 |
---|---|---|
committer | Kenneth R Westerback <krw@cvs.openbsd.org> | 2011-06-02 17:00:25 +0000 |
commit | fedd99291ef0f168157c2c17616e972cd0f2b329 (patch) | |
tree | 9e38eba233966e7785a674f4abbfae990ca30160 /sbin | |
parent | a5246a25d8d0e93327996cac653cdd0f2a2cf14c (diff) |
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@
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/disklabel/disklabel.c | 13 |
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."); |