summaryrefslogtreecommitdiffstats
path: root/usr.sbin/boot0cfg/boot0cfg.c
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2002-12-29 15:01:58 +0000
committerphk <phk@FreeBSD.org>2002-12-29 15:01:58 +0000
commit2c4226a029e9c920744effd5f4499dcef6a64bc7 (patch)
tree5efc8d60e5a76b21d31dc12670ddb6ea241794be /usr.sbin/boot0cfg/boot0cfg.c
parent78a7deb4bb779eaaac181332869143e3fc21294b (diff)
downloadFreeBSD-src-2c4226a029e9c920744effd5f4499dcef6a64bc7.zip
FreeBSD-src-2c4226a029e9c920744effd5f4499dcef6a64bc7.tar.gz
Use the new sector0 munging ioctls to make boot0cfg work under GEOM.
Diffstat (limited to 'usr.sbin/boot0cfg/boot0cfg.c')
-rw-r--r--usr.sbin/boot0cfg/boot0cfg.c39
1 files changed, 31 insertions, 8 deletions
diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c
index d2ad26b..ae4728e 100644
--- a/usr.sbin/boot0cfg/boot0cfg.c
+++ b/usr.sbin/boot0cfg/boot0cfg.c
@@ -221,9 +221,9 @@ read_mbr(const char *disk, u_int8_t **mbr, int check_version)
ssize_t n;
if ((fd = open(disk, O_RDONLY)) == -1)
- err(1, "%s", disk);
+ err(1, "open %s", disk);
if ((n = read(fd, buf, MBRSIZE)) == -1)
- err(1, "%s", disk);
+ err(1, "read %s", disk);
if (n != MBRSIZE)
errx(1, "%s: short read", disk);
if (cv2(buf + OFF_MAGIC) != 0xaa55)
@@ -255,14 +255,37 @@ read_mbr(const char *disk, u_int8_t **mbr, int check_version)
static void
write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
{
- int fd;
+ int fd, p;
ssize_t n;
-
- if ((fd = open(fname, O_WRONLY | flags, 0666)) == -1 ||
- (n = write(fd, mbr, mbr_size)) == -1 || close(fd))
+ char *s;
+
+ fd = open(fname, O_WRONLY | flags, 0666);
+ if (fd != -1) {
+ n = write(fd, mbr, mbr_size);
+ close(fd);
+ if (n != mbr_size)
+ errx(1, "%s: short write", fname);
+ return;
+ }
+ if (flags != 0)
err(1, "%s", fname);
- if (n != mbr_size)
- errx(1, "%s: short write", fname);
+#ifdef DIOCSMBR
+ for (p = 1; p < 5; p++) {
+ asprintf(&s, "%ss%d", fname, p);
+ fd = open(s, O_RDONLY);
+ if (fd < 0) {
+ free(s);
+ continue;
+ }
+ n = ioctl(fd, DIOCSMBR, (mbr));
+ if (n != 0)
+ err(1, "%s: ioctl DIOCSMBR", fname);
+ close(fd);
+ free(s);
+ return;
+ }
+#endif
+ err(1, "write_mbr: %s", fname);
}
/*
OpenPOWER on IntegriCloud