diff options
author | Yoshihiro Takahashi <nyan@FreeBSD.org> | 2005-07-15 15:32:52 +0000 |
---|---|---|
committer | Yoshihiro Takahashi <nyan@FreeBSD.org> | 2005-07-15 15:32:52 +0000 |
commit | 0f724690beadaa261e8c3a882eb3bf027047e49a (patch) | |
tree | 06cd72042138ecdc09a04841f5e105e1d71662c4 /usr.sbin/boot98cfg/boot98cfg.c | |
parent | 543f81fa1af8cb79c72fd52c6fe2d38bf267a116 (diff) | |
download | src-0f724690beadaa261e8c3a882eb3bf027047e49a.tar.gz src-0f724690beadaa261e8c3a882eb3bf027047e49a.zip |
Merged from boot0cfg.
- Update the mkrdev function.
- Attempt gctl verb "write MBR" when updating.
Notes
Notes:
svn path=/head/; revision=148064
Diffstat (limited to 'usr.sbin/boot98cfg/boot98cfg.c')
-rw-r--r-- | usr.sbin/boot98cfg/boot98cfg.c | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/usr.sbin/boot98cfg/boot98cfg.c b/usr.sbin/boot98cfg/boot98cfg.c index 0f70103c96df..45c79c99793d 100644 --- a/usr.sbin/boot98cfg/boot98cfg.c +++ b/usr.sbin/boot98cfg/boot98cfg.c @@ -65,6 +65,7 @@ __FBSDID("$FreeBSD$"); #include <err.h> #include <errno.h> #include <fcntl.h> +#include <libgeom.h> #include <paths.h> #include <stdio.h> #include <stdlib.h> @@ -82,7 +83,7 @@ u_char menu[BOOTMENUSIZE]; static int read_boot(const char *, u_char *); static int write_boot(const char *, u_char *); -static char *mkrdev(char *); +static char *mkrdev(const char *); static void usage(void); /* @@ -240,11 +241,11 @@ write_boot(const char *disk, u_char *boot) { int fd, n, i; char buf[MAXPATHLEN]; + const char *q; + struct gctl_req *grq; - fd = open(disk, O_RDWR); + fd = open(disk, O_WRONLY, 0666); if (fd != -1) { - if (lseek(fd, 0, SEEK_SET) == -1) - err(1, "%s", disk); if ((n = write(fd, boot, BOOTSIZE)) < 0) err(1, "%s", disk); if (n != BOOTSIZE) @@ -253,6 +254,23 @@ write_boot(const char *disk, u_char *boot) return 0; } + grq = gctl_get_handle(); + gctl_ro_param(grq, "verb", -1, "write PC98"); + gctl_ro_param(grq, "class", -1, "PC98"); + q = strrchr(disk, '/'); + if (q == NULL) + q = disk; + else + q++; + gctl_ro_param(grq, "geom", -1, q); + gctl_ro_param(grq, "data", BOOTSIZE, boot); + q = gctl_issue(grq); + if (q == NULL) + return 0; + + warnx("%s: %s", disk, q); + gctl_free(grq); + for (i = 0; i < NDOSPART; i++) { snprintf(buf, sizeof(buf), "%ss%d", disk, i + 1); fd = open(buf, O_RDONLY); @@ -272,20 +290,19 @@ write_boot(const char *disk, u_char *boot) * Produce a device path for a "canonical" name, where appropriate. */ static char * -mkrdev(char *fname) +mkrdev(const char *fname) { char buf[MAXPATHLEN]; - struct stat sb; char *s; - s = (char *)fname; if (!strchr(fname, '/')) { - snprintf(buf, sizeof(buf), "%sr%s", _PATH_DEV, fname); - if (stat(buf, &sb)) - snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); - if (!(s = strdup(buf))) - err(1, NULL); - } + snprintf(buf, sizeof(buf), "%s%s", _PATH_DEV, fname); + s = strdup(buf); + } else + s = strdup(fname); + + if (s == NULL) + errx(1, "No more memory"); return s; } |