Home | History | Annotate | Line # | Download | only in ofwboot
ofdev.c revision 1.6.4.3
      1  1.6.4.3  nathanw /*	$NetBSD: ofdev.c,v 1.6.4.3 2002/10/18 02:39:21 nathanw Exp $	*/
      2  1.6.4.2  nathanw 
      3  1.6.4.2  nathanw /*
      4  1.6.4.2  nathanw  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
      5  1.6.4.2  nathanw  * Copyright (C) 1995, 1996 TooLs GmbH.
      6  1.6.4.2  nathanw  * All rights reserved.
      7  1.6.4.2  nathanw  *
      8  1.6.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      9  1.6.4.2  nathanw  * modification, are permitted provided that the following conditions
     10  1.6.4.2  nathanw  * are met:
     11  1.6.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     12  1.6.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     13  1.6.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     14  1.6.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     15  1.6.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     16  1.6.4.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     17  1.6.4.2  nathanw  *    must display the following acknowledgement:
     18  1.6.4.2  nathanw  *	This product includes software developed by TooLs GmbH.
     19  1.6.4.2  nathanw  * 4. The name of TooLs GmbH may not be used to endorse or promote products
     20  1.6.4.2  nathanw  *    derived from this software without specific prior written permission.
     21  1.6.4.2  nathanw  *
     22  1.6.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
     23  1.6.4.2  nathanw  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  1.6.4.2  nathanw  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  1.6.4.2  nathanw  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
     26  1.6.4.2  nathanw  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     27  1.6.4.2  nathanw  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
     28  1.6.4.2  nathanw  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
     29  1.6.4.2  nathanw  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
     30  1.6.4.2  nathanw  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
     31  1.6.4.2  nathanw  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  1.6.4.2  nathanw  */
     33  1.6.4.2  nathanw /*
     34  1.6.4.2  nathanw  * Device I/O routines using Open Firmware
     35  1.6.4.2  nathanw  */
     36  1.6.4.2  nathanw 
     37  1.6.4.2  nathanw #include <sys/param.h>
     38  1.6.4.2  nathanw #include <sys/disklabel.h>
     39  1.6.4.2  nathanw #include <sys/disklabel_mbr.h>
     40  1.6.4.2  nathanw 
     41  1.6.4.2  nathanw #include <netinet/in.h>
     42  1.6.4.2  nathanw 
     43  1.6.4.2  nathanw #include <lib/libsa/stand.h>
     44  1.6.4.2  nathanw #include <lib/libsa/ufs.h>
     45  1.6.4.2  nathanw #include <lib/libsa/cd9660.h>
     46  1.6.4.2  nathanw #include <lib/libsa/dosfs.h>
     47  1.6.4.2  nathanw #include <lib/libsa/nfs.h>
     48  1.6.4.2  nathanw 
     49  1.6.4.2  nathanw #include "ofdev.h"
     50  1.6.4.2  nathanw 
     51  1.6.4.2  nathanw extern char bootdev[];
     52  1.6.4.2  nathanw 
     53  1.6.4.2  nathanw #ifdef DEBUG
     54  1.6.4.2  nathanw # define DPRINTF printf
     55  1.6.4.3  nathanw #else
     56  1.6.4.2  nathanw # define DPRINTF while (0) printf
     57  1.6.4.3  nathanw #endif
     58  1.6.4.2  nathanw 
     59  1.6.4.2  nathanw static char *
     60  1.6.4.2  nathanw filename(str, ppart)
     61  1.6.4.2  nathanw 	char *str;
     62  1.6.4.2  nathanw 	char *ppart;
     63  1.6.4.2  nathanw {
     64  1.6.4.2  nathanw 	char *cp, *lp;
     65  1.6.4.2  nathanw 	char savec;
     66  1.6.4.2  nathanw 	int dhandle;
     67  1.6.4.2  nathanw 	char devtype[16];
     68  1.6.4.3  nathanw 
     69  1.6.4.2  nathanw 	lp = str;
     70  1.6.4.2  nathanw 	devtype[0] = 0;
     71  1.6.4.2  nathanw 	*ppart = 0;
     72  1.6.4.2  nathanw 	for (cp = str; *cp; lp = cp) {
     73  1.6.4.3  nathanw 
     74  1.6.4.2  nathanw 		/* For each component of the path name... */
     75  1.6.4.3  nathanw 		while (*++cp && *cp != '/')
     76  1.6.4.3  nathanw 			;
     77  1.6.4.2  nathanw 		savec = *cp;
     78  1.6.4.2  nathanw 		*cp = 0;
     79  1.6.4.3  nathanw 
     80  1.6.4.2  nathanw 		/* ...look whether there is a device with this name */
     81  1.6.4.2  nathanw 		dhandle = OF_finddevice(str);
     82  1.6.4.2  nathanw 		*cp = savec;
     83  1.6.4.2  nathanw 		if (dhandle == -1) {
     84  1.6.4.3  nathanw 
     85  1.6.4.3  nathanw 			/*
     86  1.6.4.3  nathanw 			 * if not, lp is the delimiter between device and path
     87  1.6.4.3  nathanw 			 * if the last component was a block device.
     88  1.6.4.3  nathanw 			 */
     89  1.6.4.3  nathanw 
     90  1.6.4.2  nathanw 			if (!strcmp(devtype, "block")) {
     91  1.6.4.3  nathanw 
     92  1.6.4.2  nathanw 				/* search for arguments */
     93  1.6.4.2  nathanw 				for (cp = lp;
     94  1.6.4.3  nathanw 				     --cp >= str && *cp != '/' && *cp != ':';)
     95  1.6.4.3  nathanw 					;
     96  1.6.4.2  nathanw 				if (cp >= str && *cp == ':') {
     97  1.6.4.3  nathanw 
     98  1.6.4.3  nathanw 					/*
     99  1.6.4.3  nathanw 					 * found some arguments,
    100  1.6.4.3  nathanw 					 * make OFW ignore them.
    101  1.6.4.3  nathanw 					 */
    102  1.6.4.3  nathanw 
    103  1.6.4.2  nathanw 					*cp = 0;
    104  1.6.4.3  nathanw 					for (cp = lp; *--cp && *cp != ',';)
    105  1.6.4.3  nathanw 						;
    106  1.6.4.3  nathanw 					if (*++cp >= 'a' &&
    107  1.6.4.3  nathanw 					    *cp < 'a' + MAXPARTITIONS)
    108  1.6.4.2  nathanw 						*ppart = *cp;
    109  1.6.4.2  nathanw 				}
    110  1.6.4.2  nathanw 			}
    111  1.6.4.2  nathanw 			return lp;
    112  1.6.4.3  nathanw 		}
    113  1.6.4.3  nathanw 		if (OF_getprop(dhandle, "device_type", devtype,
    114  1.6.4.3  nathanw 		    sizeof devtype) < 0)
    115  1.6.4.2  nathanw 			devtype[0] = 0;
    116  1.6.4.2  nathanw 	}
    117  1.6.4.2  nathanw 	return 0;
    118  1.6.4.2  nathanw }
    119  1.6.4.2  nathanw 
    120  1.6.4.2  nathanw static int
    121  1.6.4.2  nathanw strategy(devdata, rw, blk, size, buf, rsize)
    122  1.6.4.2  nathanw 	void *devdata;
    123  1.6.4.2  nathanw 	int rw;
    124  1.6.4.2  nathanw 	daddr_t blk;
    125  1.6.4.2  nathanw 	size_t size;
    126  1.6.4.2  nathanw 	void *buf;
    127  1.6.4.2  nathanw 	size_t *rsize;
    128  1.6.4.2  nathanw {
    129  1.6.4.2  nathanw 	struct of_dev *dev = devdata;
    130  1.6.4.3  nathanw 	uint64_t pos;
    131  1.6.4.2  nathanw 	int n;
    132  1.6.4.3  nathanw 
    133  1.6.4.2  nathanw 	if (rw != F_READ)
    134  1.6.4.2  nathanw 		return EPERM;
    135  1.6.4.2  nathanw 	if (dev->type != OFDEV_DISK)
    136  1.6.4.2  nathanw 		panic("strategy");
    137  1.6.4.3  nathanw 
    138  1.6.4.3  nathanw 	pos = (uint64_t)(blk + dev->partoff) * dev->bsize;
    139  1.6.4.3  nathanw 
    140  1.6.4.2  nathanw 	for (;;) {
    141  1.6.4.2  nathanw 		if (OF_seek(dev->handle, pos) < 0)
    142  1.6.4.2  nathanw 			break;
    143  1.6.4.2  nathanw 		n = OF_read(dev->handle, buf, size);
    144  1.6.4.2  nathanw 		if (n == -2)
    145  1.6.4.2  nathanw 			continue;
    146  1.6.4.2  nathanw 		if (n < 0)
    147  1.6.4.2  nathanw 			break;
    148  1.6.4.2  nathanw 		*rsize = n;
    149  1.6.4.2  nathanw 		return 0;
    150  1.6.4.2  nathanw 	}
    151  1.6.4.2  nathanw 	return EIO;
    152  1.6.4.2  nathanw }
    153  1.6.4.2  nathanw 
    154  1.6.4.2  nathanw static int
    155  1.6.4.2  nathanw devclose(of)
    156  1.6.4.2  nathanw 	struct open_file *of;
    157  1.6.4.2  nathanw {
    158  1.6.4.2  nathanw 	struct of_dev *op = of->f_devdata;
    159  1.6.4.3  nathanw 
    160  1.6.4.2  nathanw 	if (op->type == OFDEV_NET)
    161  1.6.4.2  nathanw 		net_close(op);
    162  1.6.4.2  nathanw 	OF_close(op->handle);
    163  1.6.4.2  nathanw 	op->handle = -1;
    164  1.6.4.2  nathanw }
    165  1.6.4.2  nathanw 
    166  1.6.4.2  nathanw static struct devsw devsw[1] = {
    167  1.6.4.2  nathanw 	"OpenFirmware",
    168  1.6.4.2  nathanw 	strategy,
    169  1.6.4.2  nathanw 	(int (*)__P((struct open_file *, ...)))nodev,
    170  1.6.4.2  nathanw 	devclose,
    171  1.6.4.2  nathanw 	noioctl
    172  1.6.4.2  nathanw };
    173  1.6.4.2  nathanw int ndevs = sizeof devsw / sizeof devsw[0];
    174  1.6.4.2  nathanw 
    175  1.6.4.2  nathanw static struct fs_ops file_system_ufs = {
    176  1.6.4.2  nathanw 	ufs_open, ufs_close, ufs_read, ufs_write, ufs_seek, ufs_stat
    177  1.6.4.2  nathanw };
    178  1.6.4.2  nathanw static struct fs_ops file_system_cd9660 = {
    179  1.6.4.2  nathanw 	cd9660_open, cd9660_close, cd9660_read, cd9660_write, cd9660_seek,
    180  1.6.4.2  nathanw 	    cd9660_stat
    181  1.6.4.2  nathanw };
    182  1.6.4.2  nathanw static struct fs_ops file_system_dosfs = {
    183  1.6.4.2  nathanw 	dosfs_open, dosfs_close, dosfs_read, dosfs_write, dosfs_seek,
    184  1.6.4.2  nathanw 	    dosfs_stat
    185  1.6.4.2  nathanw };
    186  1.6.4.2  nathanw static struct fs_ops file_system_nfs = {
    187  1.6.4.2  nathanw 	nfs_open, nfs_close, nfs_read, nfs_write, nfs_seek, nfs_stat
    188  1.6.4.2  nathanw };
    189  1.6.4.2  nathanw 
    190  1.6.4.2  nathanw struct fs_ops file_system[3];
    191  1.6.4.2  nathanw int nfsys;
    192  1.6.4.2  nathanw 
    193  1.6.4.2  nathanw static struct of_dev ofdev = {
    194  1.6.4.2  nathanw 	-1,
    195  1.6.4.2  nathanw };
    196  1.6.4.2  nathanw 
    197  1.6.4.2  nathanw char opened_name[256];
    198  1.6.4.2  nathanw int floppyboot;
    199  1.6.4.2  nathanw 
    200  1.6.4.2  nathanw static u_long
    201  1.6.4.2  nathanw get_long(p)
    202  1.6.4.2  nathanw 	const void *p;
    203  1.6.4.2  nathanw {
    204  1.6.4.2  nathanw 	const unsigned char *cp = p;
    205  1.6.4.3  nathanw 
    206  1.6.4.2  nathanw 	return cp[0] | (cp[1] << 8) | (cp[2] << 16) | (cp[3] << 24);
    207  1.6.4.2  nathanw }
    208  1.6.4.2  nathanw 
    209  1.6.4.2  nathanw /*
    210  1.6.4.2  nathanw  * Find a valid disklabel.
    211  1.6.4.2  nathanw  */
    212  1.6.4.2  nathanw static int
    213  1.6.4.2  nathanw search_label(devp, off, buf, lp, off0)
    214  1.6.4.2  nathanw 	struct of_dev *devp;
    215  1.6.4.2  nathanw 	u_long off;
    216  1.6.4.2  nathanw 	char *buf;
    217  1.6.4.2  nathanw 	struct disklabel *lp;
    218  1.6.4.2  nathanw 	u_long off0;
    219  1.6.4.2  nathanw {
    220  1.6.4.2  nathanw 	size_t read;
    221  1.6.4.2  nathanw 	struct mbr_partition *p;
    222  1.6.4.2  nathanw 	int i;
    223  1.6.4.2  nathanw 	u_long poff;
    224  1.6.4.2  nathanw 	static int recursion;
    225  1.6.4.3  nathanw 
    226  1.6.4.2  nathanw 	if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
    227  1.6.4.2  nathanw 	    || read != DEV_BSIZE)
    228  1.6.4.2  nathanw 		return ERDLAB;
    229  1.6.4.3  nathanw 
    230  1.6.4.2  nathanw 	if (*(u_int16_t *)&buf[MBR_MAGICOFF] != sa_htole16(MBR_MAGIC))
    231  1.6.4.2  nathanw 		return ERDLAB;
    232  1.6.4.2  nathanw 
    233  1.6.4.2  nathanw 	if (recursion++ <= 1)
    234  1.6.4.2  nathanw 		off0 += off;
    235  1.6.4.3  nathanw 	for (p = (struct mbr_partition *)(buf + MBR_PARTOFF), i = 0;
    236  1.6.4.3  nathanw 	     i < NMBRPART; i++, p++) {
    237  1.6.4.2  nathanw 		if (p->mbrp_typ == MBR_PTYPE_NETBSD
    238  1.6.4.2  nathanw #ifdef COMPAT_386BSD_MBRPART
    239  1.6.4.2  nathanw 		    || (p->mbrp_typ == MBR_PTYPE_386BSD &&
    240  1.6.4.2  nathanw 			(printf("WARNING: old BSD partition ID!\n"), 1)
    241  1.6.4.2  nathanw 			/* XXX XXX - libsa printf() is void */ )
    242  1.6.4.2  nathanw #endif
    243  1.6.4.2  nathanw 		    ) {
    244  1.6.4.2  nathanw 			poff = get_long(&p->mbrp_start) + off0;
    245  1.6.4.2  nathanw 			if (strategy(devp, F_READ, poff + LABELSECTOR,
    246  1.6.4.2  nathanw 				     DEV_BSIZE, buf, &read) == 0
    247  1.6.4.2  nathanw 			    && read == DEV_BSIZE) {
    248  1.6.4.2  nathanw 				if (!getdisklabel(buf, lp)) {
    249  1.6.4.2  nathanw 					recursion--;
    250  1.6.4.2  nathanw 					return 0;
    251  1.6.4.2  nathanw 				}
    252  1.6.4.2  nathanw 			}
    253  1.6.4.2  nathanw 			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
    254  1.6.4.2  nathanw 			    || read != DEV_BSIZE) {
    255  1.6.4.2  nathanw 				recursion--;
    256  1.6.4.2  nathanw 				return ERDLAB;
    257  1.6.4.2  nathanw 			}
    258  1.6.4.2  nathanw 		} else if (p->mbrp_typ == MBR_PTYPE_EXT) {
    259  1.6.4.2  nathanw 			poff = get_long(&p->mbrp_start);
    260  1.6.4.2  nathanw 			if (!search_label(devp, poff, buf, lp, off0)) {
    261  1.6.4.2  nathanw 				recursion--;
    262  1.6.4.2  nathanw 				return 0;
    263  1.6.4.2  nathanw 			}
    264  1.6.4.2  nathanw 			if (strategy(devp, F_READ, off, DEV_BSIZE, buf, &read)
    265  1.6.4.2  nathanw 			    || read != DEV_BSIZE) {
    266  1.6.4.2  nathanw 				recursion--;
    267  1.6.4.2  nathanw 				return ERDLAB;
    268  1.6.4.2  nathanw 			}
    269  1.6.4.2  nathanw 		}
    270  1.6.4.2  nathanw 	}
    271  1.6.4.3  nathanw 
    272  1.6.4.2  nathanw 	recursion--;
    273  1.6.4.2  nathanw 	return ERDLAB;
    274  1.6.4.2  nathanw }
    275  1.6.4.2  nathanw 
    276  1.6.4.2  nathanw int
    277  1.6.4.2  nathanw devopen(of, name, file)
    278  1.6.4.2  nathanw 	struct open_file *of;
    279  1.6.4.2  nathanw 	const char *name;
    280  1.6.4.2  nathanw 	char **file;
    281  1.6.4.2  nathanw {
    282  1.6.4.2  nathanw 	char *cp;
    283  1.6.4.2  nathanw 	char partition;
    284  1.6.4.2  nathanw 	char fname[256];
    285  1.6.4.2  nathanw 	char buf[DEV_BSIZE];
    286  1.6.4.2  nathanw 	struct disklabel label;
    287  1.6.4.2  nathanw 	int handle, part;
    288  1.6.4.2  nathanw 	size_t read;
    289  1.6.4.2  nathanw 	int error = 0;
    290  1.6.4.2  nathanw 
    291  1.6.4.2  nathanw 	if (ofdev.handle != -1)
    292  1.6.4.2  nathanw 		panic("devopen");
    293  1.6.4.2  nathanw 	if (of->f_flags != F_READ)
    294  1.6.4.2  nathanw 		return EPERM;
    295  1.6.4.2  nathanw 	strcpy(fname, name);
    296  1.6.4.2  nathanw 	cp = filename(fname, &partition);
    297  1.6.4.2  nathanw 	if (cp) {
    298  1.6.4.2  nathanw 		DPRINTF("filename=%s\n", cp);
    299  1.6.4.2  nathanw 		strcpy(buf, cp);
    300  1.6.4.2  nathanw 		*cp = 0;
    301  1.6.4.2  nathanw 	}
    302  1.6.4.2  nathanw 	if (!cp || !*buf)
    303  1.6.4.2  nathanw 		strcpy(buf, DEFAULT_KERNEL);
    304  1.6.4.2  nathanw 	if (!*fname)
    305  1.6.4.2  nathanw 		strcpy(fname, bootdev);
    306  1.6.4.2  nathanw 	DPRINTF("fname=%s\n", fname);
    307  1.6.4.2  nathanw 	strcpy(opened_name, fname);
    308  1.6.4.2  nathanw 	if (partition) {
    309  1.6.4.2  nathanw 		cp = opened_name + strlen(opened_name);
    310  1.6.4.2  nathanw 		*cp++ = ':';
    311  1.6.4.2  nathanw 		*cp++ = partition;
    312  1.6.4.2  nathanw 		*cp = 0;
    313  1.6.4.2  nathanw 	}
    314  1.6.4.2  nathanw 	if (*buf != '/')
    315  1.6.4.2  nathanw 		strcat(opened_name, "/");
    316  1.6.4.2  nathanw 	strcat(opened_name, buf);
    317  1.6.4.2  nathanw 	*file = opened_name + strlen(fname) + 1;
    318  1.6.4.3  nathanw 	if (partition) {
    319  1.6.4.3  nathanw 		*file += 2;
    320  1.6.4.3  nathanw 	}
    321  1.6.4.2  nathanw 	if ((handle = OF_finddevice(fname)) == -1) {
    322  1.6.4.2  nathanw 		DPRINTF("OF_finddevice(\"%s\") failed\n", fname);
    323  1.6.4.2  nathanw 		return ENOENT;
    324  1.6.4.2  nathanw 	}
    325  1.6.4.2  nathanw 	if (OF_getprop(handle, "name", buf, sizeof buf) < 0)
    326  1.6.4.2  nathanw 		return ENXIO;
    327  1.6.4.2  nathanw 	floppyboot = !strcmp(buf, "floppy");
    328  1.6.4.2  nathanw 	if (OF_getprop(handle, "device_type", buf, sizeof buf) < 0)
    329  1.6.4.2  nathanw 		return ENXIO;
    330  1.6.4.3  nathanw 	if (!strcmp(buf, "block")) {
    331  1.6.4.3  nathanw 
    332  1.6.4.3  nathanw 		/*
    333  1.6.4.3  nathanw 		 * For block devices, indicate raw partition
    334  1.6.4.3  nathanw 		 * (:0 in OpenFirmware)
    335  1.6.4.3  nathanw 		 */
    336  1.6.4.3  nathanw 
    337  1.6.4.2  nathanw 		strcat(fname, ":0");
    338  1.6.4.3  nathanw 	}
    339  1.6.4.2  nathanw 	if ((handle = OF_open(fname)) == -1)
    340  1.6.4.2  nathanw 		return ENXIO;
    341  1.6.4.2  nathanw 	memset(&ofdev, 0, sizeof ofdev);
    342  1.6.4.2  nathanw 	ofdev.handle = handle;
    343  1.6.4.2  nathanw 	if (!strcmp(buf, "block")) {
    344  1.6.4.2  nathanw 		ofdev.type = OFDEV_DISK;
    345  1.6.4.2  nathanw 		ofdev.bsize = DEV_BSIZE;
    346  1.6.4.3  nathanw 
    347  1.6.4.2  nathanw 		/* First try to find a disklabel without MBR partitions */
    348  1.6.4.2  nathanw 		if (strategy(&ofdev, F_READ,
    349  1.6.4.2  nathanw 			     LABELSECTOR, DEV_BSIZE, buf, &read) != 0
    350  1.6.4.2  nathanw 		    || read != DEV_BSIZE
    351  1.6.4.2  nathanw 		    || getdisklabel(buf, &label)) {
    352  1.6.4.3  nathanw 
    353  1.6.4.2  nathanw 			/* Else try MBR partitions */
    354  1.6.4.2  nathanw 			error = search_label(&ofdev, 0, buf, &label, 0);
    355  1.6.4.2  nathanw 			if (error && error != ERDLAB)
    356  1.6.4.2  nathanw 				goto bad;
    357  1.6.4.2  nathanw 		}
    358  1.6.4.2  nathanw 
    359  1.6.4.2  nathanw 		if (error == ERDLAB) {
    360  1.6.4.3  nathanw 			if (partition) {
    361  1.6.4.3  nathanw 
    362  1.6.4.3  nathanw 				/*
    363  1.6.4.3  nathanw 				 * User specified a parititon,
    364  1.6.4.3  nathanw 				 * but there is none.
    365  1.6.4.3  nathanw 				 */
    366  1.6.4.3  nathanw 
    367  1.6.4.2  nathanw 				goto bad;
    368  1.6.4.3  nathanw 			}
    369  1.6.4.3  nathanw 
    370  1.6.4.3  nathanw 			/* No label, just use complete disk */
    371  1.6.4.2  nathanw 			ofdev.partoff = 0;
    372  1.6.4.2  nathanw 		} else {
    373  1.6.4.2  nathanw 			part = partition ? partition - 'a' : 0;
    374  1.6.4.2  nathanw 			ofdev.partoff = label.d_partitions[part].p_offset;
    375  1.6.4.2  nathanw 		}
    376  1.6.4.3  nathanw 
    377  1.6.4.2  nathanw 		of->f_dev = devsw;
    378  1.6.4.2  nathanw 		of->f_devdata = &ofdev;
    379  1.6.4.2  nathanw 		file_system[0] = file_system_ufs;
    380  1.6.4.2  nathanw 		file_system[1] = file_system_cd9660;
    381  1.6.4.3  nathanw 		file_system[2] = file_system_dosfs;
    382  1.6.4.3  nathanw 		nfsys = 3;
    383  1.6.4.2  nathanw 		return 0;
    384  1.6.4.2  nathanw 	}
    385  1.6.4.2  nathanw 	if (!strcmp(buf, "network")) {
    386  1.6.4.2  nathanw 		ofdev.type = OFDEV_NET;
    387  1.6.4.2  nathanw 		of->f_dev = devsw;
    388  1.6.4.2  nathanw 		of->f_devdata = &ofdev;
    389  1.6.4.2  nathanw 		file_system[0] = file_system_nfs;
    390  1.6.4.2  nathanw 		nfsys = 1;
    391  1.6.4.2  nathanw 		if (error = net_open(&ofdev))
    392  1.6.4.2  nathanw 			goto bad;
    393  1.6.4.2  nathanw 		return 0;
    394  1.6.4.2  nathanw 	}
    395  1.6.4.2  nathanw 	error = EFTYPE;
    396  1.6.4.2  nathanw bad:
    397  1.6.4.2  nathanw 	OF_close(handle);
    398  1.6.4.2  nathanw 	ofdev.handle = -1;
    399  1.6.4.2  nathanw 	return error;
    400  1.6.4.2  nathanw }
    401