1
0
mirror of https://git.FreeBSD.org/src.git synced 2024-12-28 11:57:28 +00:00

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

This commit is contained in:
Poul-Henning Kamp 2002-12-29 15:01:58 +00:00
parent f8cfa0dbaf
commit 23db6b2998
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=108394

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