Port-macppc archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: Planning for NetBSD 5.0



macallan%NetBSD.org@localhost wrote:

> Fixing installboot sounds like the proper fix to me.

How about this?
---
Index: macppc.c
===================================================================
RCS file: /cvsroot/src/usr.sbin/installboot/arch/macppc.c,v
retrieving revision 1.9
diff -u -r1.9 macppc.c
--- macppc.c    28 Apr 2008 20:24:16 -0000      1.9
+++ macppc.c    7 May 2008 11:42:44 -0000
@@ -39,6 +39,10 @@
 #endif /* !__lint */
 
 #include <sys/param.h>
+#ifndef HAVE_NBTOOL_CONFIG_H
+#include <sys/ioctl.h>
+#include <sys/dkio.h>
+#endif
 
 #include <assert.h>
 #include <err.h>
@@ -92,6 +96,10 @@
 {
        struct apple_drvr_map dm;
        struct apple_part_map_entry pme;
+       int rv;
+#ifdef DIOCWLABEL
+       int enable;
+#endif
 
        assert (params != NULL);
        assert (bb_params != NULL);
@@ -109,8 +117,27 @@
        dm.sbSig =              htobe16(APPLE_DRVR_MAP_MAGIC);
        dm.sbBlockSize =        htobe16(512);
        dm.sbBlkCount =         htobe32(0);
-       if (pwrite(params->fsfd, &dm, MACPPC_BOOT_BLOCK_BLOCKSIZE, 0) !=
-           MACPPC_BOOT_BLOCK_BLOCKSIZE) {
+
+#ifdef DIOCWLABEL
+       /*
+        * block 0 is LABELSECTOR which might be protected by
+        * bounds_check_with_label(9).
+        */
+       enable = 1;
+       rv = ioctl(params->fsfd, DIOCWLABEL, &enable);
+       if (rv != 0) {
+               warn("Cannot enable writes to the label sector");
+               return 0;
+       }
+#endif
+       rv = pwrite(params->fsfd, &dm, MACPPC_BOOT_BLOCK_BLOCKSIZE, 0);
+
+#ifdef DIOCWLABEL
+       /* Reset write-protect. */
+       enable = 0;
+       ioctl(params->fsfd, DIOCWLABEL, &enable);
+#endif
+       if (rv != MACPPC_BOOT_BLOCK_BLOCKSIZE) {
                warn("Can't write sector 0 of `%s'", params->filesystem);
                return (0);
        }

---
Izumi Tsutsui


Home | Main Index | Thread Index | Old Index