/*
* Copyright (C) 1995, 1996 Wolfgang Solfrank.
* Copyright (C) 1995, 1996 TooLs GmbH.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by TooLs GmbH.
* 4. The name of TooLs GmbH may not be used to endorse or promote products
* derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
if (strcmp(child, "floppy") == 0)
of->sc_flags |= OFDF_ISFLOPPY;
else {
/* Discover wedges on this disk. */
dkwedge_discover(&of->sc_dk);
}
}
int
ofdisk_open(dev_t dev, int flags, int fmt, struct lwp *lwp)
{
struct ofdisk_softc *of;
char path[256];
int error, l, part;
of = device_lookup_private(&ofdisk_cd, DISKUNIT(dev));
if (of == NULL)
return ENXIO;
part = DISKPART(dev);
mutex_enter(&of->sc_dk.dk_openlock);
/*
* If there are wedges, and this is not RAW_PART, then we
* need to fail.
*/
if (of->sc_dk.dk_nwedges != 0 && part != RAW_PART) {
error = EBUSY;
goto bad1;
}
/*
* XXX This is for the benefit of SCSI/IDE disks that don't
* XXX have all their childs in the device tree.
* XXX YES, I DO THINK THIS IS A BUG IN OPENFIRMWARE!!!
* XXX And yes, this is a very gross hack!
* XXX See also ofscsi.c
*/
if (!strcmp(path + l - 4, "disk")) {
path[l++] = '@';
path[l++] = '0' + of->sc_unit;
path[l] = 0;
}
/*
* Try to get characteristics of the disk.
*/
of->max_transfer = OF_call_method_1("max-transfer",
of->sc_ihandle, 0);
if (of->max_transfer > MAXPHYS)
of->max_transfer = MAXPHYS;
#ifdef FIRMWORKSBUGS
/*
* This is a hack to get the firmware to flush its buffers.
*/
OF_seek(of->sc_ihandle, 0);
#endif
if (!of->sc_dk.dk_openmask) {
OF_close(of->sc_ihandle);
of->sc_ihandle = 0;
}
if (bp->b_bcount > of->max_transfer)
bp->b_bcount = of->max_transfer;
}
int
ofdisk_read(dev_t dev, struct uio *uio, int flags)
{
return physio(ofdisk_strategy, NULL, dev, B_READ, ofminphys, uio);
}
int
ofdisk_write(dev_t dev, struct uio *uio, int flags)
{
return physio(ofdisk_strategy, NULL, dev, B_WRITE, ofminphys, uio);
}
int
ofdisk_ioctl(dev_t dev, u_long cmd, void *data, int flag, struct lwp *l)
{
struct ofdisk_softc *of =
device_lookup_private(&ofdisk_cd, DISKUNIT(dev));
int error;
#ifdef __HAVE_OLD_DISKLABEL
struct disklabel newlabel;
#endif
/* XXX: Why not allow wedges on floppy? */
switch (cmd) {
case DIOCDWEDGE:
case DIOCAWEDGE:
case DIOCLWEDGES:
case DIOCRMWEDGES:
case DIOCMWEDGES:
if (OFDISK_FLOPPY_P(of))
return ENOTTY;
}
/*
* XXX Firmware bug? Asking for block size gives a
* XXX ridiculous number! So we use what the boot program
* XXX uses.
*/
lp->d_secsize = DEV_BSIZE;
void
ofdisk_getdisklabel(dev_t dev)
{
int unit = DISKUNIT(dev);
struct ofdisk_softc *of =
device_lookup_private(&ofdisk_cd, unit);
struct disklabel *lp = of->sc_dk.dk_label;
const char *errmes;
int l;
ofdisk_getdefaultlabel(of, lp);
/*
* Don't read the disklabel on a floppy; simply
* assign all partitions the same size/offset as
* RAW_PART. (This is essentially what the ISA
* floppy driver does, but we don't deal with
* density stuff.)
*/
if (OFDISK_FLOPPY_P(of)) {
lp->d_npartitions = MAXPARTITIONS;
for (l = 0; l < lp->d_npartitions; l++) {
if (l == RAW_PART)
continue;
/* struct copy */
lp->d_partitions[l] =
lp->d_partitions[RAW_PART];
}
lp->d_checksum = dkcksum(lp);
} else {
errmes = readdisklabel(MAKEDISKDEV(major(dev),
unit, RAW_PART), ofdisk_strategy, lp,
of->sc_dk.dk_cpulabel);
if (errmes != NULL)
printf("%s: %s\n", device_xname(of->sc_dev), errmes);
}
}