From a9e4cec8d95572d604ee23940faaf1f0b7bd0938 Mon Sep 17 00:00:00 2001 From: tsutsui Date: Fri, 9 May 2008 10:14:35 +0000 Subject: [PATCH] Use DIOCWLABEL ioctl before writing block 0 which might be protected by (now MI) bounds_check_with_label(9). Fixes a problem on sysinst mentioned in PR port-macppc/38016. --- usr.sbin/installboot/arch/macppc.c | 35 ++++++++++++++++++++++++++---- 1 file changed, 31 insertions(+), 4 deletions(-) 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); }