diff options
Diffstat (limited to 'sbin/fdisk')
-rw-r--r-- | sbin/fdisk/cmd.c | 11 | ||||
-rw-r--r-- | sbin/fdisk/fdisk.c | 5 | ||||
-rw-r--r-- | sbin/fdisk/user.c | 16 |
3 files changed, 23 insertions, 9 deletions
diff --git a/sbin/fdisk/cmd.c b/sbin/fdisk/cmd.c index db32b5abd02..6d4ee70f227 100644 --- a/sbin/fdisk/cmd.c +++ b/sbin/fdisk/cmd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: cmd.c,v 1.41 2006/07/18 19:05:42 mbalmer Exp $ */ +/* $OpenBSD: cmd.c,v 1.42 2006/07/27 04:06:13 ray Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -314,15 +314,18 @@ int Xwrite(cmd_t *cmd, disk_t *disk, mbr_t *mbr, mbr_t *tt, int offset) { char mbr_buf[DEV_BSIZE]; - int fd; + int fd, ret; + + ret = CMD_CONT; printf("Writing MBR at offset %d.\n", offset); fd = DISK_open(disk->name, O_RDWR); MBR_make(mbr, mbr_buf); - MBR_write(fd, offset, mbr_buf); + if (MBR_write(fd, offset, mbr_buf) != -1) + ret = CMD_CLEAN; close(fd); - return (CMD_CLEAN); + return (ret); } /* ARGSUSED */ diff --git a/sbin/fdisk/fdisk.c b/sbin/fdisk/fdisk.c index d2a7f3ce7c6..7a0aa9ef10a 100644 --- a/sbin/fdisk/fdisk.c +++ b/sbin/fdisk/fdisk.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fdisk.c,v 1.41 2006/07/09 21:19:41 miod Exp $ */ +/* $OpenBSD: fdisk.c,v 1.42 2006/07/27 04:06:13 ray Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -162,7 +162,8 @@ main(int argc, char *argv[]) /* Now do what we are supposed to */ if (i_flag || u_flag) - USER_init(&disk, &mbr, u_flag); + if (USER_init(&disk, &mbr, u_flag) == -1) + err(1, "error initializing MBR"); if (m_flag) USER_modify(&disk, &mbr, 0, 0); diff --git a/sbin/fdisk/user.c b/sbin/fdisk/user.c index 3727ae4988d..8e952af5a5d 100644 --- a/sbin/fdisk/user.c +++ b/sbin/fdisk/user.c @@ -1,4 +1,4 @@ -/* $OpenBSD: user.c,v 1.22 2005/01/19 15:48:20 deraadt Exp $ */ +/* $OpenBSD: user.c,v 1.23 2006/07/27 04:06:13 ray Exp $ */ /* * Copyright (c) 1997 Tobias Weingartner @@ -26,6 +26,7 @@ */ #include <err.h> +#include <errno.h> #include <util.h> #include <stdio.h> #include <unistd.h> @@ -89,7 +90,12 @@ USER_init(disk_t *disk, mbr_t *tt, int preserve) if (yn) { fd = DISK_open(disk->name, O_RDWR); MBR_make(tt, mbr_buf); - MBR_write(fd, (off_t)0, mbr_buf); + if (MBR_write(fd, 0, mbr_buf) == -1) { + int saved_errno = errno; + DISK_close(fd); + errno = saved_errno; + return (-1); + } DISK_close(fd); } else printf("MBR is unchanged\n"); @@ -168,7 +174,11 @@ again: printf("Writing current MBR to disk.\n"); fd = DISK_open(disk->name, O_RDWR); MBR_make(&mbr, mbr_buf); - MBR_write(fd, offset, mbr_buf); + if (MBR_write(fd, offset, mbr_buf) == -1) { + warn("error writing MBR"); + close(fd); + goto again; + } close(fd); } else printf("Aborting changes to current MBR.\n"); |