summaryrefslogtreecommitdiff
path: root/usr.sbin/installboot/i386_installboot.c
diff options
context:
space:
mode:
authorKenneth R Westerback <krw@cvs.openbsd.org>2014-04-27 13:41:51 +0000
committerKenneth R Westerback <krw@cvs.openbsd.org>2014-04-27 13:41:51 +0000
commit434d8596bfd54c7371efcbd2b1b8dee514ff4800 (patch)
tree9af1f848eb523ef9d61cd75d7544c7c5340c6598 /usr.sbin/installboot/i386_installboot.c
parent02214cf404d93d1fd99c350af6a580660b958551 (diff)
Don't zap disklabel (and next 6 blocks) when installing boot block on
4k-sector disk drives. Noted and fix tested by David Vasek via misc@ tweaks & ok jsing@
Diffstat (limited to 'usr.sbin/installboot/i386_installboot.c')
-rw-r--r--usr.sbin/installboot/i386_installboot.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/usr.sbin/installboot/i386_installboot.c b/usr.sbin/installboot/i386_installboot.c
index 2a0d188cd29..fff16853700 100644
--- a/usr.sbin/installboot/i386_installboot.c
+++ b/usr.sbin/installboot/i386_installboot.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: i386_installboot.c,v 1.1 2014/01/19 02:58:50 jsing Exp $ */
+/* $OpenBSD: i386_installboot.c,v 1.2 2014/04/27 13:41:50 krw Exp $ */
/* $NetBSD: installboot.c,v 1.5 1995/11/17 23:23:50 gwr Exp $ */
/*
@@ -190,9 +190,13 @@ write_bootblocks(int devfd, char *dev, struct disklabel *dl)
if (!nowrite) {
if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0)
- err(1, "seek bootstrap");
+ err(1, "seek boot sector");
secbuf = calloc(1, dl->d_secsize);
+ if (read(devfd, secbuf, dl->d_secsize) != dl->d_secsize)
+ err(1, "read boot sector");
bcopy(blkstore, secbuf, blksize);
+ if (lseek(devfd, (off_t)start * dl->d_secsize, SEEK_SET) < 0)
+ err(1, "seek bootstrap");
if (write(devfd, secbuf, dl->d_secsize) != dl->d_secsize)
err(1, "write bootstrap");
free(secbuf);