Try DIOCWLABEL ioctl only if write op fails with EROFS
because the ioctl is required and valid only for raw devices.
This commit is contained in:
parent
c2987416cd
commit
ff1b9852ce
|
@ -1,4 +1,4 @@
|
|||
/* $NetBSD: macppc.c,v 1.10 2008/05/09 10:14:35 tsutsui Exp $ */
|
||||
/* $NetBSD: macppc.c,v 1.11 2008/05/24 19:15:21 tsutsui Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2002 The NetBSD Foundation, Inc.
|
||||
|
@ -35,13 +35,14 @@
|
|||
|
||||
#include <sys/cdefs.h>
|
||||
#if !defined(__lint)
|
||||
__RCSID("$NetBSD: macppc.c,v 1.10 2008/05/09 10:14:35 tsutsui Exp $");
|
||||
__RCSID("$NetBSD: macppc.c,v 1.11 2008/05/24 19:15:21 tsutsui Exp $");
|
||||
#endif /* !__lint */
|
||||
|
||||
#include <sys/param.h>
|
||||
#ifndef HAVE_NBTOOL_CONFIG_H
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/dkio.h>
|
||||
#include <errno.h>
|
||||
#endif
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -97,9 +98,6 @@ 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);
|
||||
|
@ -118,24 +116,28 @@ writeapplepartmap(ib_params *params, struct bbinfo_params *bb_params,
|
|||
dm.sbBlockSize = htobe16(512);
|
||||
dm.sbBlkCount = htobe32(0);
|
||||
|
||||
#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);
|
||||
if (rv == -1 && errno == EROFS) {
|
||||
/*
|
||||
* block 0 is LABELSECTOR which might be protected by
|
||||
* bounds_check_with_label(9).
|
||||
*/
|
||||
int enable;
|
||||
|
||||
enable = 1;
|
||||
rv = ioctl(params->fsfd, DIOCWLABEL, &enable);
|
||||
if (rv != 0) {
|
||||
warn("Cannot enable writes to the label sector");
|
||||
return 0;
|
||||
}
|
||||
|
||||
rv = pwrite(params->fsfd, &dm, MACPPC_BOOT_BLOCK_BLOCKSIZE, 0);
|
||||
|
||||
/* 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);
|
||||
|
|
Loading…
Reference in New Issue