diff --git a/usr.sbin/installboot/arch/macppc.c b/usr.sbin/installboot/arch/macppc.c index d4696b7ed5e8..667757ae7684 100644 --- a/usr.sbin/installboot/arch/macppc.c +++ b/usr.sbin/installboot/arch/macppc.c @@ -1,4 +1,4 @@ -/* $NetBSD: macppc.c,v 1.9 2008/04/28 20:24:16 martin Exp $ */ +/* $NetBSD: macppc.c,v 1.10 2008/05/09 10:14:35 tsutsui Exp $ */ /*- * Copyright (c) 2002 The NetBSD Foundation, Inc. @@ -35,10 +35,14 @@ #include #if !defined(__lint) -__RCSID("$NetBSD: macppc.c,v 1.9 2008/04/28 20:24:16 martin Exp $"); +__RCSID("$NetBSD: macppc.c,v 1.10 2008/05/09 10:14:35 tsutsui Exp $"); #endif /* !__lint */ #include +#ifndef HAVE_NBTOOL_CONFIG_H +#include +#include +#endif #include #include @@ -92,6 +96,10 @@ writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params, { 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 @@ writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params, 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; + (void)ioctl(params->fsfd, DIOCWLABEL, &enable); +#endif + if (rv != MACPPC_BOOT_BLOCK_BLOCKSIZE) { warn("Can't write sector 0 of `%s'", params->filesystem); return (0); }