summaryrefslogtreecommitdiffstats
path: root/usr.sbin/boot0cfg
diff options
context:
space:
mode:
authorphk <phk@FreeBSD.org>2005-07-15 08:04:32 +0000
committerphk <phk@FreeBSD.org>2005-07-15 08:04:32 +0000
commit821d28352b21950012c374f0efc0898f549d05e7 (patch)
treeda944144f0cf9d3e71303adab5a56855d6d86ae0 /usr.sbin/boot0cfg
parent885176b2cbda98eeccbcfd3e2ee66633088f6007 (diff)
downloadFreeBSD-src-821d28352b21950012c374f0efc0898f549d05e7.zip
FreeBSD-src-821d28352b21950012c374f0efc0898f549d05e7.tar.gz
Attempt gctl verb "write MBR" when updating.
This should solve the problem of modifying the MBR while running.
Diffstat (limited to 'usr.sbin/boot0cfg')
-rw-r--r--usr.sbin/boot0cfg/Makefile3
-rw-r--r--usr.sbin/boot0cfg/boot0cfg.c23
2 files changed, 25 insertions, 1 deletions
diff --git a/usr.sbin/boot0cfg/Makefile b/usr.sbin/boot0cfg/Makefile
index 3f87438..dc02cad 100644
--- a/usr.sbin/boot0cfg/Makefile
+++ b/usr.sbin/boot0cfg/Makefile
@@ -5,4 +5,7 @@ MAN= boot0cfg.8
WARNS?= 2
+DPADD= ${LIBGEOM}
+LDADD= -lgeom
+
.include <bsd.prog.mk>
diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c
index 6783360..6fd0587 100644
--- a/usr.sbin/boot0cfg/boot0cfg.c
+++ b/usr.sbin/boot0cfg/boot0cfg.c
@@ -35,6 +35,7 @@ __FBSDID("$FreeBSD$");
#include <err.h>
#include <errno.h>
#include <fcntl.h>
+#include <libgeom.h>
#include <paths.h>
#include <stdio.h>
#include <stdlib.h>
@@ -256,6 +257,8 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
int fd, p;
ssize_t n;
char *s;
+ const char *q;
+ struct gctl_req *grq;
fd = open(fname, O_WRONLY | flags, 0666);
if (fd != -1) {
@@ -265,12 +268,30 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
errx(1, "%s: short write", fname);
return;
}
+
if (flags != 0)
err(1, "%s", fname);
+ grq = gctl_get_handle();
+ gctl_ro_param(grq, "verb", -1, "write MBR");
+ gctl_ro_param(grq, "class", -1, "MBR");
+ q = strrchr(fname, '/');
+ if (q == NULL)
+ q = fname;
+ else
+ q++;
+ gctl_ro_param(grq, "geom", -1, q);
+ gctl_ro_param(grq, "data", mbr_size, mbr);
+ q = gctl_issue(grq);
+ if (q == NULL)
+ return;
+
+ warnx("%s: %s", fname, q);
+ gctl_free(grq);
+
#ifdef DIOCSMBR
for (p = 1; p < 5; p++) {
asprintf(&s, "%ss%d", fname, p);
- fd = open(s, O_RDWR);
+ fd = open(s, O_RDONLY);
if (fd < 0) {
free(s);
continue;
OpenPOWER on IntegriCloud