svn commit: r189273 - head/usr.sbin/boot0cfg

Marcel Moolenaar marcel at FreeBSD.org
Sun Mar 1 20:35:55 PST 2009


Author: marcel
Date: Mon Mar  2 04:35:52 2009
New Revision: 189273
URL: http://svn.freebsd.org/changeset/base/189273

Log:
  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.

Modified:
  head/usr.sbin/boot0cfg/boot0cfg.c

Modified: head/usr.sbin/boot0cfg/boot0cfg.c
==============================================================================
--- head/usr.sbin/boot0cfg/boot0cfg.c	Mon Mar  2 04:12:41 2009	(r189272)
+++ head/usr.sbin/boot0cfg/boot0cfg.c	Mon Mar  2 04:35:52 2009	(r189273)
@@ -343,9 +343,8 @@ read_mbr(const char *disk, u_int8_t **mb
 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, 
 	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, 
 	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);
 }
 
 /*


More information about the svn-src-head mailing list