Home | History | Annotate | Line # | Download | only in ofw
ofdisk.c revision 1.16
      1  1.16      matt /*	$NetBSD: ofdisk.c,v 1.16 2001/08/25 19:05:04 matt Exp $	*/
      2   1.1        ws 
      3   1.1        ws /*
      4   1.1        ws  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5   1.1        ws  * Copyright (C) 1995, 1996 TooLs GmbH.
      6   1.1        ws  * All rights reserved.
      7   1.1        ws  *
      8   1.1        ws  * Redistribution and use in source and binary forms, with or without
      9   1.1        ws  * modification, are permitted provided that the following conditions
     10   1.1        ws  * are met:
     11   1.1        ws  * 1. Redistributions of source code must retain the above copyright
     12   1.1        ws  *    notice, this list of conditions and the following disclaimer.
     13   1.1        ws  * 2. Redistributions in binary form must reproduce the above copyright
     14   1.1        ws  *    notice, this list of conditions and the following disclaimer in the
     15   1.1        ws  *    documentation and/or other materials provided with the distribution.
     16   1.1        ws  * 3. All advertising materials mentioning features or use of this software
     17   1.1        ws  *    must display the following acknowledgement:
     18   1.1        ws  *	This product includes software developed by TooLs GmbH.
     19   1.1        ws  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20   1.1        ws  *    derived from this software without specific prior written permission.
     21   1.1        ws  *
     22   1.1        ws  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23   1.1        ws  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24   1.1        ws  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25   1.1        ws  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26   1.1        ws  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27   1.1        ws  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28   1.1        ws  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29   1.1        ws  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30   1.1        ws  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31   1.1        ws  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32   1.1        ws  */
     33   1.1        ws 
     34   1.1        ws #include <sys/param.h>
     35   1.1        ws #include <sys/buf.h>
     36   1.1        ws #include <sys/device.h>
     37  1.16      matt #include <sys/conf.h>
     38   1.1        ws #include <sys/disklabel.h>
     39   1.1        ws #include <sys/disk.h>
     40   1.1        ws #include <sys/fcntl.h>
     41   1.1        ws #include <sys/ioctl.h>
     42   1.1        ws #include <sys/stat.h>
     43   1.1        ws #include <sys/systm.h>
     44   1.6   thorpej #include <sys/proc.h>
     45   1.1        ws 
     46   1.1        ws #include <dev/ofw/openfirm.h>
     47   1.1        ws 
     48  1.10   mycroft struct ofdisk_softc {
     49   1.1        ws 	struct device sc_dev;
     50   1.1        ws 	int sc_phandle;
     51   1.1        ws 	int sc_unit;
     52   1.4   thorpej 	int sc_flags;
     53   1.1        ws 	struct disk sc_dk;
     54   1.1        ws 	int sc_ihandle;
     55   1.1        ws 	u_long max_transfer;
     56   1.1        ws 	char sc_name[16];
     57   1.1        ws };
     58   1.1        ws 
     59  1.16      matt bdev_decl(ofdisk_);
     60  1.16      matt cdev_decl(ofdisk_);
     61  1.16      matt 
     62   1.4   thorpej /* sc_flags */
     63   1.4   thorpej #define OFDF_ISFLOPPY	0x01		/* we are a floppy drive */
     64   1.4   thorpej 
     65  1.10   mycroft static int ofdisk_match __P((struct device *, struct cfdata *, void *));
     66  1.10   mycroft static void ofdisk_attach __P((struct device *, struct device *, void *));
     67   1.1        ws 
     68   1.1        ws struct cfattach ofdisk_ca = {
     69  1.10   mycroft 	sizeof(struct ofdisk_softc), ofdisk_match, ofdisk_attach
     70   1.1        ws };
     71   1.1        ws 
     72   1.9   thorpej extern struct cfdriver ofdisk_cd;
     73   1.1        ws 
     74  1.10   mycroft void ofdisk_strategy __P((struct buf *));
     75   1.1        ws 
     76  1.10   mycroft struct dkdriver ofdisk_dkdriver = { ofdisk_strategy };
     77   1.1        ws 
     78  1.10   mycroft void ofdisk_getdefaultlabel __P((struct ofdisk_softc *, struct disklabel *));
     79  1.10   mycroft void ofdisk_getdisklabel __P((dev_t));
     80   1.7   thorpej 
     81   1.1        ws static int
     82  1.10   mycroft ofdisk_match(parent, match, aux)
     83   1.1        ws 	struct device *parent;
     84   1.4   thorpej 	struct cfdata *match;
     85   1.4   thorpej 	void *aux;
     86   1.1        ws {
     87  1.10   mycroft 	struct ofbus_attach_args *oba = aux;
     88   1.1        ws 	char type[8];
     89   1.1        ws 	int l;
     90   1.1        ws 
     91  1.10   mycroft 	if (strcmp(oba->oba_busname, "ofw"))
     92  1.10   mycroft 		return (0);
     93  1.10   mycroft 	if ((l = OF_getprop(oba->oba_phandle, "device_type", type,
     94   1.4   thorpej 	    sizeof type - 1)) < 0)
     95   1.1        ws 		return 0;
     96   1.1        ws 	if (l >= sizeof type)
     97   1.1        ws 		return 0;
     98   1.1        ws 	type[l] = 0;
     99   1.1        ws 	return !strcmp(type, "block");
    100   1.1        ws }
    101   1.1        ws 
    102   1.1        ws static void
    103  1.10   mycroft ofdisk_attach(parent, self, aux)
    104   1.1        ws 	struct device *parent, *self;
    105   1.1        ws 	void *aux;
    106   1.1        ws {
    107  1.10   mycroft 	struct ofdisk_softc *of = (void *)self;
    108  1.10   mycroft 	struct ofbus_attach_args *oba = aux;
    109   1.4   thorpej 	char child[64];
    110   1.1        ws 	int l;
    111   1.4   thorpej 
    112  1.10   mycroft 	if ((l = OF_getprop(oba->oba_phandle, "name", child,
    113   1.4   thorpej 	    sizeof child - 1)) < 0)
    114   1.4   thorpej 		panic("device without name?");
    115   1.4   thorpej 	if (l >= sizeof child)
    116   1.4   thorpej 		l = sizeof child - 1;
    117   1.4   thorpej 	child[l] = 0;
    118   1.4   thorpej 
    119   1.4   thorpej 	of->sc_flags = 0;
    120  1.10   mycroft 	of->sc_phandle = oba->oba_phandle;
    121  1.10   mycroft 	of->sc_unit = oba->oba_unit;
    122   1.1        ws 	of->sc_ihandle = 0;
    123  1.10   mycroft 	of->sc_dk.dk_driver = &ofdisk_dkdriver;
    124   1.1        ws 	of->sc_dk.dk_name = of->sc_name;
    125   1.1        ws 	strcpy(of->sc_name, of->sc_dev.dv_xname);
    126   1.1        ws 	disk_attach(&of->sc_dk);
    127  1.13   thorpej #ifdef __BROKEN_DK_ESTABLISH
    128   1.1        ws 	dk_establish(&of->sc_dk, self);				/* XXX */
    129  1.13   thorpej #endif
    130   1.3  christos 	printf("\n");
    131   1.4   thorpej 
    132   1.4   thorpej 	if (strcmp(child, "floppy") == 0)
    133   1.4   thorpej 		of->sc_flags |= OFDF_ISFLOPPY;
    134   1.1        ws }
    135   1.1        ws 
    136   1.1        ws int
    137  1.10   mycroft ofdisk_open(dev, flags, fmt, p)
    138   1.1        ws 	dev_t dev;
    139   1.1        ws 	int flags;
    140   1.1        ws 	int fmt;
    141   1.1        ws 	struct proc *p;
    142   1.1        ws {
    143   1.1        ws 	int unit = DISKUNIT(dev);
    144  1.10   mycroft 	struct ofdisk_softc *of;
    145   1.1        ws 	char path[256];
    146   1.1        ws 	int l;
    147   1.1        ws 
    148   1.1        ws 	if (unit >= ofdisk_cd.cd_ndevs)
    149   1.1        ws 		return ENXIO;
    150   1.1        ws 	if (!(of = ofdisk_cd.cd_devs[unit]))
    151   1.1        ws 		return ENXIO;
    152   1.1        ws 
    153   1.1        ws 	if (!of->sc_ihandle) {
    154   1.4   thorpej 		if ((l = OF_package_to_path(of->sc_phandle, path,
    155  1.11   mycroft 		    sizeof path - 3)) < 0 ||
    156  1.11   mycroft 		    l >= sizeof path - 3)
    157   1.1        ws 			return ENXIO;
    158   1.1        ws 		path[l] = 0;
    159   1.1        ws 
    160   1.1        ws 		/*
    161   1.4   thorpej 		 * XXX This is for the benefit of SCSI/IDE disks that don't
    162   1.4   thorpej 		 * XXX have all their childs in the device tree.
    163   1.4   thorpej 		 * XXX YES, I DO THINK THIS IS A BUG IN OPENFIRMWARE!!!
    164   1.4   thorpej 		 * XXX And yes, this is a very gross hack!
    165   1.4   thorpej 		 * XXX See also ofscsi.c
    166   1.1        ws 		 */
    167   1.1        ws 		if (!strcmp(path + l - 4, "disk")) {
    168   1.1        ws 			path[l++] = '@';
    169   1.1        ws 			path[l++] = '0' + of->sc_unit;
    170   1.1        ws 			path[l] = 0;
    171   1.1        ws 		}
    172   1.1        ws 
    173   1.1        ws 		strcat(path, ":0");
    174   1.1        ws 
    175   1.1        ws 		if (!(of->sc_ihandle = OF_open(path)))
    176   1.1        ws 			return ENXIO;
    177   1.1        ws 
    178   1.1        ws 		/*
    179   1.1        ws 		 * Try to get characteristics of the disk.
    180   1.1        ws 		 */
    181   1.4   thorpej 		of->max_transfer = OF_call_method_1("max-transfer",
    182   1.4   thorpej 		    of->sc_ihandle, 0);
    183   1.1        ws 		if (of->max_transfer > MAXPHYS)
    184   1.1        ws 			of->max_transfer = MAXPHYS;
    185   1.4   thorpej 
    186  1.10   mycroft 		ofdisk_getdisklabel(dev);
    187   1.1        ws 	}
    188   1.1        ws 
    189   1.1        ws 	switch (fmt) {
    190   1.1        ws 	case S_IFCHR:
    191   1.1        ws 		of->sc_dk.dk_copenmask |= 1 << DISKPART(dev);
    192   1.1        ws 		break;
    193   1.1        ws 	case S_IFBLK:
    194   1.1        ws 		of->sc_dk.dk_bopenmask |= 1 << DISKPART(dev);
    195   1.1        ws 		break;
    196   1.1        ws 	}
    197   1.4   thorpej 	of->sc_dk.dk_openmask =
    198   1.4   thorpej 	    of->sc_dk.dk_copenmask | of->sc_dk.dk_bopenmask;
    199   1.1        ws 
    200   1.1        ws 	return 0;
    201   1.1        ws }
    202   1.1        ws 
    203   1.1        ws int
    204  1.10   mycroft ofdisk_close(dev, flags, fmt, p)
    205   1.1        ws 	dev_t dev;
    206   1.1        ws 	int flags;
    207   1.1        ws 	int fmt;
    208   1.1        ws 	struct proc *p;
    209   1.1        ws {
    210  1.10   mycroft 	struct ofdisk_softc *of = ofdisk_cd.cd_devs[DISKUNIT(dev)];
    211   1.1        ws 
    212   1.1        ws 	switch (fmt) {
    213   1.1        ws 	case S_IFCHR:
    214   1.1        ws 		of->sc_dk.dk_copenmask &= ~(1 << DISKPART(dev));
    215   1.1        ws 		break;
    216   1.1        ws 	case S_IFBLK:
    217   1.1        ws 		of->sc_dk.dk_bopenmask &= ~(1 << DISKPART(dev));
    218   1.1        ws 		break;
    219   1.1        ws 	}
    220   1.1        ws 	of->sc_dk.dk_openmask = of->sc_dk.dk_copenmask | of->sc_dk.dk_bopenmask;
    221   1.1        ws 
    222   1.4   thorpej #ifdef	FIRMWORKSBUGS
    223   1.1        ws 	/*
    224   1.1        ws 	 * This is a hack to get the firmware to flush its buffers.
    225   1.1        ws 	 */
    226   1.1        ws 	OF_seek(of->sc_ihandle, 0);
    227   1.1        ws #endif
    228   1.1        ws 	if (!of->sc_dk.dk_openmask) {
    229   1.1        ws 		OF_close(of->sc_ihandle);
    230   1.1        ws 		of->sc_ihandle = 0;
    231   1.1        ws 	}
    232   1.1        ws 
    233   1.1        ws 	return 0;
    234   1.1        ws }
    235   1.1        ws 
    236   1.1        ws void
    237  1.10   mycroft ofdisk_strategy(bp)
    238   1.1        ws 	struct buf *bp;
    239   1.1        ws {
    240  1.10   mycroft 	struct ofdisk_softc *of = ofdisk_cd.cd_devs[DISKUNIT(bp->b_dev)];
    241   1.1        ws 	struct partition *p;
    242   1.1        ws 	u_quad_t off;
    243   1.1        ws 	int read;
    244   1.1        ws 	int (*OF_io)(int, void *, int);
    245   1.1        ws 	daddr_t blkno = bp->b_blkno;
    246   1.4   thorpej 
    247   1.1        ws 	bp->b_resid = 0;
    248   1.1        ws 	if (bp->b_bcount == 0)
    249   1.1        ws 		goto done;
    250   1.1        ws 
    251   1.1        ws 	OF_io = bp->b_flags & B_READ ? OF_read : OF_write;
    252   1.1        ws 
    253   1.1        ws 	if (DISKPART(bp->b_dev) != RAW_PART) {
    254   1.1        ws 		if (bounds_check_with_label(bp, of->sc_dk.dk_label, 0) <= 0) {
    255   1.1        ws 			bp->b_resid = bp->b_bcount;
    256   1.1        ws 			goto done;
    257   1.1        ws 		}
    258   1.1        ws 		p = &of->sc_dk.dk_label->d_partitions[DISKPART(bp->b_dev)];
    259   1.1        ws 		blkno = bp->b_blkno + p->p_offset;
    260   1.1        ws 	}
    261   1.4   thorpej 
    262   1.1        ws 	disk_busy(&of->sc_dk);
    263   1.1        ws 
    264   1.1        ws 	off = (u_quad_t)blkno * DEV_BSIZE;
    265   1.1        ws 	read = -1;
    266   1.1        ws 	do {
    267   1.1        ws 		if (OF_seek(of->sc_ihandle, off) < 0)
    268   1.1        ws 			break;
    269   1.1        ws 		read = OF_io(of->sc_ihandle, bp->b_data, bp->b_bcount);
    270   1.1        ws 	} while (read == -2);
    271   1.4   thorpej 
    272   1.1        ws 	if (read < 0) {
    273   1.1        ws 		bp->b_error = EIO;
    274   1.1        ws 		bp->b_flags |= B_ERROR;
    275   1.1        ws 		bp->b_resid = bp->b_bcount;
    276   1.1        ws 	} else
    277   1.1        ws 		bp->b_resid = bp->b_bcount - read;
    278   1.1        ws 
    279   1.1        ws 	disk_unbusy(&of->sc_dk, bp->b_bcount - bp->b_resid);
    280   1.1        ws 
    281   1.1        ws done:
    282   1.1        ws 	biodone(bp);
    283   1.1        ws }
    284   1.1        ws 
    285   1.1        ws static void
    286   1.1        ws ofminphys(bp)
    287   1.1        ws 	struct buf *bp;
    288   1.1        ws {
    289  1.10   mycroft 	struct ofdisk_softc *of = ofdisk_cd.cd_devs[DISKUNIT(bp->b_dev)];
    290   1.1        ws 
    291   1.1        ws 	if (bp->b_bcount > of->max_transfer)
    292   1.1        ws 		bp->b_bcount = of->max_transfer;
    293   1.1        ws }
    294   1.1        ws 
    295   1.1        ws int
    296  1.16      matt ofdisk_read(dev, uio, flags)
    297   1.1        ws 	dev_t dev;
    298   1.1        ws 	struct uio *uio;
    299  1.16      matt 	int flags;
    300   1.1        ws {
    301  1.10   mycroft 	return physio(ofdisk_strategy, NULL, dev, B_READ, ofminphys, uio);
    302   1.1        ws }
    303   1.1        ws 
    304   1.1        ws int
    305  1.16      matt ofdisk_write(dev, uio, flags)
    306   1.1        ws 	dev_t dev;
    307   1.1        ws 	struct uio *uio;
    308  1.16      matt 	int flags;
    309   1.1        ws {
    310  1.10   mycroft 	return physio(ofdisk_strategy, NULL, dev, B_WRITE, ofminphys, uio);
    311   1.1        ws }
    312   1.1        ws 
    313   1.1        ws int
    314  1.10   mycroft ofdisk_ioctl(dev, cmd, data, flag, p)
    315   1.1        ws 	dev_t dev;
    316   1.1        ws 	u_long cmd;
    317   1.1        ws 	caddr_t data;
    318   1.1        ws 	int flag;
    319   1.1        ws 	struct proc *p;
    320   1.1        ws {
    321  1.10   mycroft 	struct ofdisk_softc *of = ofdisk_cd.cd_devs[DISKUNIT(dev)];
    322   1.1        ws 	int error;
    323  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    324  1.14      fvdl 	struct disklabel newlabel;
    325  1.14      fvdl #endif
    326   1.1        ws 
    327   1.1        ws 	switch (cmd) {
    328   1.1        ws 	case DIOCGDINFO:
    329   1.1        ws 		*(struct disklabel *)data = *of->sc_dk.dk_label;
    330   1.1        ws 		return 0;
    331  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    332  1.14      fvdl 	case ODIOCGDINFO:
    333  1.14      fvdl 		newlabel = *of->sc_dk.dk_label;
    334  1.14      fvdl 		if (newlabel.d_npartitions > OLDMAXPARTITIONS)
    335  1.15      fvdl 			return ENOTTY;
    336  1.14      fvdl 		memcpy(data, &newlabel, sizeof (struct olddisklabel));
    337  1.14      fvdl 		return 0;
    338  1.14      fvdl #endif
    339   1.1        ws 
    340   1.1        ws 	case DIOCGPART:
    341   1.1        ws 		((struct partinfo *)data)->disklab = of->sc_dk.dk_label;
    342   1.1        ws 		((struct partinfo *)data)->part =
    343   1.1        ws 			&of->sc_dk.dk_label->d_partitions[DISKPART(dev)];
    344   1.1        ws 		return 0;
    345   1.1        ws 
    346   1.1        ws 	case DIOCWDINFO:
    347   1.1        ws 	case DIOCSDINFO:
    348  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    349  1.14      fvdl 	case ODIOCWDINFO:
    350  1.14      fvdl 	case ODIOCSDINFO:
    351  1.14      fvdl #endif
    352  1.14      fvdl 	{
    353  1.14      fvdl 		struct disklabel *lp;
    354  1.14      fvdl 
    355  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    356  1.14      fvdl 		if (cmd == ODIOCSDINFO || cmd == ODIOCWDINFO) {
    357  1.14      fvdl 			memset(&newlabel, 0, sizeof newlabel);
    358  1.14      fvdl 			memcpy(&newlabel, data, sizeof (struct olddisklabel));
    359  1.14      fvdl 			lp = &newlabel;
    360  1.14      fvdl 		} else
    361  1.14      fvdl #endif
    362  1.14      fvdl 		lp = (struct disklabel *)data;
    363  1.14      fvdl 
    364   1.1        ws 		if ((flag & FWRITE) == 0)
    365   1.1        ws 			return EBADF;
    366   1.1        ws 
    367   1.1        ws 		error = setdisklabel(of->sc_dk.dk_label,
    368  1.14      fvdl 		    lp, /*of->sc_dk.dk_openmask */0,
    369   1.4   thorpej 		    of->sc_dk.dk_cpulabel);
    370  1.14      fvdl 		if (error == 0 && cmd == DIOCWDINFO
    371  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    372  1.14      fvdl 		    || xfer == ODIOCWDINFO
    373  1.14      fvdl #endif
    374  1.14      fvdl 		    )
    375   1.1        ws 			error = writedisklabel(MAKEDISKDEV(major(dev),
    376  1.10   mycroft 			    DISKUNIT(dev), RAW_PART), ofdisk_strategy,
    377   1.4   thorpej 			    of->sc_dk.dk_label, of->sc_dk.dk_cpulabel);
    378   1.1        ws 
    379   1.1        ws 		return error;
    380  1.14      fvdl 	}
    381   1.7   thorpej 
    382   1.7   thorpej 	case DIOCGDEFLABEL:
    383  1.10   mycroft 		ofdisk_getdefaultlabel(of, (struct disklabel *)data);
    384   1.7   thorpej 		return 0;
    385  1.14      fvdl #ifdef __HAVE_OLD_DISKLABEL
    386  1.14      fvdl 	case DIOCGDEFLABEL:
    387  1.14      fvdl 		ofdisk_getdefaultlabel(of, &newlabel);
    388  1.14      fvdl 		if (newlabel.d_npartitions > OLDMAXPARTITIONS)
    389  1.15      fvdl 			return ENOTTY;
    390  1.14      fvdl 		memcpy(data, &newlabel, sizeof (struct olddisklabel));
    391  1.14      fvdl 		return 0;
    392  1.14      fvdl #endif
    393   1.7   thorpej 
    394   1.1        ws 	default:
    395   1.1        ws 		return ENOTTY;
    396   1.1        ws 	}
    397   1.1        ws }
    398   1.1        ws 
    399   1.1        ws int
    400  1.10   mycroft ofdisk_dump(dev, blkno, va, size)
    401   1.1        ws 	dev_t dev;
    402   1.1        ws 	daddr_t blkno;
    403   1.1        ws 	caddr_t va;
    404   1.1        ws 	size_t size;
    405   1.1        ws {
    406   1.1        ws 	return EINVAL;
    407   1.1        ws }
    408   1.1        ws 
    409   1.1        ws int
    410  1.10   mycroft ofdisk_size(dev)
    411   1.1        ws 	dev_t dev;
    412   1.1        ws {
    413  1.10   mycroft 	struct ofdisk_softc *of;
    414   1.5   thorpej 	struct disklabel *lp;
    415   1.5   thorpej 	int size, part, omask, unit;
    416   1.5   thorpej 
    417   1.5   thorpej 	unit = DISKUNIT(dev);
    418   1.5   thorpej 	if (unit >= ofdisk_cd.cd_ndevs ||
    419   1.5   thorpej 	    (of = ofdisk_cd.cd_devs[unit]) == NULL)
    420   1.1        ws 		return -1;
    421   1.5   thorpej 
    422   1.1        ws 	part = DISKPART(dev);
    423   1.5   thorpej 	omask = of->sc_dk.dk_openmask & (1 << part);
    424   1.6   thorpej 	lp = of->sc_dk.dk_label;
    425   1.5   thorpej 
    426  1.10   mycroft 	if (omask == 0 && ofdisk_open(dev, 0, S_IFBLK, curproc) != 0)
    427   1.5   thorpej 		return -1;
    428   1.5   thorpej 
    429   1.5   thorpej 	if (lp->d_partitions[part].p_fstype != FS_SWAP)
    430   1.1        ws 		size = -1;
    431   1.1        ws 	else
    432   1.5   thorpej 		size = lp->d_partitions[part].p_size *
    433   1.5   thorpej 		    (lp->d_secsize / DEV_BSIZE);
    434   1.5   thorpej 
    435  1.10   mycroft 	if (omask == 0 && ofdisk_close(dev, 0, S_IFBLK, curproc) != 0)
    436   1.1        ws 		return -1;
    437   1.5   thorpej 
    438   1.1        ws 	return size;
    439   1.7   thorpej }
    440   1.7   thorpej 
    441   1.7   thorpej void
    442  1.10   mycroft ofdisk_getdefaultlabel(of, lp)
    443  1.10   mycroft 	struct ofdisk_softc *of;
    444   1.7   thorpej 	struct disklabel *lp;
    445   1.7   thorpej {
    446   1.7   thorpej 
    447   1.7   thorpej 	bzero(lp, sizeof *lp);
    448   1.7   thorpej 
    449   1.7   thorpej 	/*
    450   1.7   thorpej 	 * XXX Firmware bug?  Asking for block size gives a
    451   1.7   thorpej 	 * XXX rediculous number!  So we use what the boot program
    452   1.7   thorpej 	 * XXX uses.
    453   1.7   thorpej 	 */
    454   1.7   thorpej 	lp->d_secsize = DEV_BSIZE;
    455   1.7   thorpej 
    456   1.7   thorpej 	lp->d_secperunit = OF_call_method_1("#blocks",
    457   1.7   thorpej 	    of->sc_ihandle, 0);
    458   1.7   thorpej 	if (lp->d_secperunit == (u_int32_t)-1)
    459   1.7   thorpej 		lp->d_secperunit = 0x7fffffff;
    460   1.7   thorpej 
    461   1.7   thorpej 	lp->d_secpercyl = 1;
    462   1.7   thorpej 	lp->d_nsectors = 1;
    463   1.7   thorpej 	lp->d_ntracks = 1;
    464   1.7   thorpej 	lp->d_ncylinders = lp->d_secperunit;
    465   1.7   thorpej 
    466   1.7   thorpej 	lp->d_partitions[RAW_PART].p_offset = 0;
    467   1.7   thorpej 	lp->d_partitions[RAW_PART].p_size = lp->d_secperunit;
    468   1.7   thorpej 	lp->d_npartitions = RAW_PART + 1;
    469   1.7   thorpej 
    470   1.7   thorpej 	lp->d_magic = DISKMAGIC;
    471   1.7   thorpej 	lp->d_magic2 = DISKMAGIC;
    472   1.7   thorpej 	lp->d_checksum = dkcksum(lp);
    473   1.7   thorpej }
    474   1.7   thorpej 
    475   1.7   thorpej void
    476  1.10   mycroft ofdisk_getdisklabel(dev)
    477   1.7   thorpej 	dev_t dev;
    478   1.7   thorpej {
    479   1.7   thorpej 	int unit = DISKUNIT(dev);
    480  1.10   mycroft 	struct ofdisk_softc *of = ofdisk_cd.cd_devs[unit];
    481   1.7   thorpej 	struct disklabel *lp = of->sc_dk.dk_label;
    482   1.7   thorpej 	char *errmes;
    483   1.7   thorpej 	int l;
    484   1.7   thorpej 
    485  1.10   mycroft 	ofdisk_getdefaultlabel(of, lp);
    486   1.7   thorpej 
    487   1.7   thorpej 	/*
    488   1.7   thorpej 	 * Don't read the disklabel on a floppy; simply
    489   1.7   thorpej 	 * assign all partitions the same size/offset as
    490   1.7   thorpej 	 * RAW_PART.  (This is essentially what the ISA
    491   1.7   thorpej 	 * floppy driver does, but we don't deal with
    492   1.7   thorpej 	 * density stuff.)
    493   1.7   thorpej 	 */
    494   1.7   thorpej 	if (of->sc_flags & OFDF_ISFLOPPY) {
    495   1.7   thorpej 		lp->d_npartitions = MAXPARTITIONS;
    496   1.7   thorpej 		for (l = 0; l < lp->d_npartitions; l++) {
    497   1.7   thorpej 			if (l == RAW_PART)
    498   1.7   thorpej 				continue;
    499   1.7   thorpej 			/* struct copy */
    500   1.7   thorpej 			lp->d_partitions[l] =
    501   1.7   thorpej 			    lp->d_partitions[RAW_PART];
    502   1.7   thorpej 		}
    503   1.7   thorpej 		lp->d_checksum = dkcksum(lp);
    504   1.7   thorpej 	} else {
    505   1.7   thorpej 		errmes = readdisklabel(MAKEDISKDEV(major(dev),
    506  1.10   mycroft 		    unit, RAW_PART), ofdisk_strategy, lp,
    507   1.7   thorpej 		    of->sc_dk.dk_cpulabel);
    508   1.7   thorpej 		if (errmes != NULL)
    509  1.12       cgd 			printf("%s: %s\n", of->sc_dev.dv_xname, errmes);
    510   1.7   thorpej 	}
    511   1.1        ws }
    512