Use the new sector0 munging ioctls to make boot0cfg work under GEOM.

This commit is contained in:
phk 2002-12-29 15:01:58 +00:00
parent 3a8b071f97
commit 1e4d40ec36

View File

@ -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);
}
/*