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.
This commit is contained in:
parent
37318b6485
commit
4e754e1bd3
@ -343,9 +343,8 @@ read_mbr(const char *disk, u_int8_t **mbr, int check_version)
|
|||||||
static void
|
static void
|
||||||
write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
|
write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
|
||||||
{
|
{
|
||||||
int fd, p;
|
int fd;
|
||||||
ssize_t n;
|
ssize_t n;
|
||||||
char *s;
|
|
||||||
const char *errmsg;
|
const char *errmsg;
|
||||||
char *pname;
|
char *pname;
|
||||||
struct gctl_req *grq;
|
struct gctl_req *grq;
|
||||||
@ -359,6 +358,13 @@ write_mbr(const char *fname, int flags, u_int8_t *mbr, int mbr_size)
|
|||||||
return;
|
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. */
|
/* Try open it read only. */
|
||||||
fd = open(fname, O_RDONLY);
|
fd = open(fname, O_RDONLY);
|
||||||
if (fd == -1) {
|
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);
|
warn("error getting providername for %s", fname);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (flags != 0)
|
grq = gctl_get_handle();
|
||||||
err(1, "%s", fname);
|
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();
|
grq = gctl_get_handle();
|
||||||
gctl_ro_param(grq, "verb", -1, "write MBR");
|
gctl_ro_param(grq, "verb", -1, "write MBR");
|
||||||
gctl_ro_param(grq, "class", -1, "MBR");
|
gctl_ro_param(grq, "class", -1, "MBR");
|
||||||
gctl_ro_param(grq, "geom", -1, pname);
|
gctl_ro_param(grq, "geom", -1, pname);
|
||||||
gctl_ro_param(grq, "data", mbr_size, mbr);
|
gctl_ro_param(grq, "data", mbr_size, mbr);
|
||||||
errmsg = gctl_issue(grq);
|
errmsg = gctl_issue(grq);
|
||||||
if (errmsg == NULL) {
|
if (errmsg != NULL)
|
||||||
free(pname);
|
err(1, "write_mbr: %s", fname);
|
||||||
return;
|
|
||||||
}
|
out:
|
||||||
warnx("%s: %s", fname, pname);
|
|
||||||
free(pname);
|
free(pname);
|
||||||
gctl_free(grq);
|
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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
Loading…
Reference in New Issue
Block a user