summaryrefslogtreecommitdiffstats
path: root/usr.sbin/boot0cfg
diff options
context:
space:
mode:
authormarcel <marcel@FreeBSD.org>2009-03-02 04:35:52 +0000
committermarcel <marcel@FreeBSD.org>2009-03-02 04:35:52 +0000
commit4306c4bdaf0940c9a4cb6d17e2c3c6d97de32c76 (patch)
tree187260e68d610f0b62e2062abbfed8a2b44d9726 /usr.sbin/boot0cfg
parentffdb6e3c4ea8cea99ebd58ef13a27ab604d4f69d (diff)
downloadFreeBSD-src-4306c4bdaf0940c9a4cb6d17e2c3c6d97de32c76.zip
FreeBSD-src-4306c4bdaf0940c9a4cb6d17e2c3c6d97de32c76.tar.gz
Write the MBR by using the bootcode verb of the gpart class.
The "write MBR" verb is kept for backward compatibility, but the DIOCSMBR ioctl has been removed.
Diffstat (limited to 'usr.sbin/boot0cfg')
-rw-r--r--usr.sbin/boot0cfg/boot0cfg.c49
1 files changed, 22 insertions, 27 deletions
diff --git a/usr.sbin/boot0cfg/boot0cfg.c b/usr.sbin/boot0cfg/boot0cfg.c
index a889fe3..cd3bfe2 100644
--- a/usr.sbin/boot0cfg/boot0cfg.c
+++ b/usr.sbin/boot0cfg/boot0cfg.c
@@ -343,9 +343,8 @@ 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, p;
+ int fd;
ssize_t n;
- char *s;
const char *errmsg;
char *pname;
struct gctl_req *grq;
@@ -359,6 +358,13 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
return;
}
+ /*
+ * If we're called to write to a backup file, don't try to
+ * write through GEOM. It only generates additional errors.
+ */
+ if (flags != 0)
+ return;
+
/* Try open it read only. */
fd = open(fname, O_RDONLY);
if (fd == -1) {
@@ -370,39 +376,28 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
warn("error getting providername for %s", fname);
return;
}
- if (flags != 0)
- err(1, "%s", fname);
+ grq = gctl_get_handle();
+ gctl_ro_param(grq, "class", -1, "PART");
+ gctl_ro_param(grq, "geom", -1, pname);
+ gctl_ro_param(grq, "verb", -1, "bootcode");
+ gctl_ro_param(grq, "bootcode", mbr_size, mbr);
+ gctl_ro_param(grq, "flags", -1, "C");
+ errmsg = gctl_issue(grq);
+ if (errmsg == NULL)
+ goto out;
+
grq = gctl_get_handle();
gctl_ro_param(grq, "verb", -1, "write MBR");
gctl_ro_param(grq, "class", -1, "MBR");
gctl_ro_param(grq, "geom", -1, pname);
gctl_ro_param(grq, "data", mbr_size, mbr);
errmsg = gctl_issue(grq);
- if (errmsg == NULL) {
- free(pname);
- return;
- }
- warnx("%s: %s", fname, pname);
+ if (errmsg != NULL)
+ err(1, "write_mbr: %s", fname);
+
+out:
free(pname);
gctl_free(grq);
-
-#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