Home | History | Annotate | Line # | Download | only in netboot
devopen.c revision 1.1.2.2
      1  1.1.2.2  nathanw /* $NetBSD: devopen.c,v 1.1.2.2 2002/11/11 22:03:46 nathanw Exp $ */
      2  1.1.2.2  nathanw 
      3  1.1.2.2  nathanw /*-
      4  1.1.2.2  nathanw  * Copyright (c) 1992, 1993
      5  1.1.2.2  nathanw  *	The Regents of the University of California.  All rights reserved.
      6  1.1.2.2  nathanw  *
      7  1.1.2.2  nathanw  * This code is derived from software contributed to Berkeley by
      8  1.1.2.2  nathanw  * Ralph Campbell.
      9  1.1.2.2  nathanw  *
     10  1.1.2.2  nathanw  * Redistribution and use in source and binary forms, with or without
     11  1.1.2.2  nathanw  * modification, are permitted provided that the following conditions
     12  1.1.2.2  nathanw  * are met:
     13  1.1.2.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     14  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     15  1.1.2.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     16  1.1.2.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     17  1.1.2.2  nathanw  *    documentation and/or other materials provided with the distribution.
     18  1.1.2.2  nathanw  * 3. All advertising materials mentioning features or use of this software
     19  1.1.2.2  nathanw  *    must display the following acknowledgement:
     20  1.1.2.2  nathanw  *	This product includes software developed by the University of
     21  1.1.2.2  nathanw  *	California, Berkeley and its contributors.
     22  1.1.2.2  nathanw  * 4. Neither the name of the University nor the names of its contributors
     23  1.1.2.2  nathanw  *    may be used to endorse or promote products derived from this software
     24  1.1.2.2  nathanw  *    without specific prior written permission.
     25  1.1.2.2  nathanw  *
     26  1.1.2.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     27  1.1.2.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     28  1.1.2.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     29  1.1.2.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     30  1.1.2.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     31  1.1.2.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     32  1.1.2.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     33  1.1.2.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     34  1.1.2.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     35  1.1.2.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     36  1.1.2.2  nathanw  * SUCH DAMAGE.
     37  1.1.2.2  nathanw  *
     38  1.1.2.2  nathanw  *	@(#)devopen.c	8.1 (Berkeley) 6/10/93
     39  1.1.2.2  nathanw  */
     40  1.1.2.2  nathanw 
     41  1.1.2.2  nathanw #include <lib/libsa/stand.h>
     42  1.1.2.2  nathanw 
     43  1.1.2.2  nathanw /*
     44  1.1.2.2  nathanw  * Decode the string 'fname', open the device and return the remaining
     45  1.1.2.2  nathanw  * file name if any.
     46  1.1.2.2  nathanw  */
     47  1.1.2.2  nathanw int
     48  1.1.2.2  nathanw devopen(f, fname, file)
     49  1.1.2.2  nathanw 	struct open_file *f;
     50  1.1.2.2  nathanw 	const char *fname;
     51  1.1.2.2  nathanw 	char **file;	/* out */
     52  1.1.2.2  nathanw {
     53  1.1.2.2  nathanw 	register char *cp;
     54  1.1.2.2  nathanw 	register char *ncp;
     55  1.1.2.2  nathanw 	register struct devsw *dp;
     56  1.1.2.2  nathanw #if 0
     57  1.1.2.2  nathanw 	register int c, i;
     58  1.1.2.2  nathanw #endif
     59  1.1.2.2  nathanw 	int ctlr = 0, unit = 0, part = 0;
     60  1.1.2.2  nathanw 	char namebuf[20];
     61  1.1.2.2  nathanw 	int rc;
     62  1.1.2.2  nathanw 
     63  1.1.2.2  nathanw 	cp = (char *)fname;
     64  1.1.2.2  nathanw 	ncp = namebuf;
     65  1.1.2.2  nathanw 
     66  1.1.2.2  nathanw #if 0
     67  1.1.2.2  nathanw 	/* look for a string like '5/rz0/vmunix' or '5/rz3f/vmunix */
     68  1.1.2.2  nathanw 	if ((c = *cp) >= '0' && c <= '9') {
     69  1.1.2.2  nathanw 		ctlr = c - '0';
     70  1.1.2.2  nathanw 		/* skip the '/' */
     71  1.1.2.2  nathanw 		if (*++cp != '/')
     72  1.1.2.2  nathanw 			return (ENXIO);
     73  1.1.2.2  nathanw 		cp++;
     74  1.1.2.2  nathanw 		while ((c = *cp) != '\0') {
     75  1.1.2.2  nathanw 			if (c == '/')
     76  1.1.2.2  nathanw 				break;
     77  1.1.2.2  nathanw 			if (c >= '0' && c <= '9') {
     78  1.1.2.2  nathanw 				/* read unit number */
     79  1.1.2.2  nathanw 				unit = c - '0';
     80  1.1.2.2  nathanw 
     81  1.1.2.2  nathanw 				/* look for a partition */
     82  1.1.2.2  nathanw 				if ((c = *++cp) >= 'a' && c <= 'h') {
     83  1.1.2.2  nathanw 					part = c - 'a';
     84  1.1.2.2  nathanw 					c = *++cp;
     85  1.1.2.2  nathanw 				}
     86  1.1.2.2  nathanw 				if (c != '/')
     87  1.1.2.2  nathanw 					return (ENXIO);
     88  1.1.2.2  nathanw 				break;
     89  1.1.2.2  nathanw 			}
     90  1.1.2.2  nathanw 			if (ncp < namebuf + sizeof(namebuf) - 1)
     91  1.1.2.2  nathanw 				*ncp++ = c;
     92  1.1.2.2  nathanw 			cp++;
     93  1.1.2.2  nathanw 		}
     94  1.1.2.2  nathanw 		*ncp = '\0';
     95  1.1.2.2  nathanw 	/*
     96  1.1.2.2  nathanw 	 * XXX
     97  1.1.2.2  nathanw 	 * pulling strchr from the C library, should pull from libkern.
     98  1.1.2.2  nathanw 	 */
     99  1.1.2.2  nathanw 	} else if (strchr(cp, '(')) {
    100  1.1.2.2  nathanw 		/* expect a string like 'rz(0,0,0)vmunix' */
    101  1.1.2.2  nathanw 		while ((c = *cp) != '\0') {
    102  1.1.2.2  nathanw 			if (c == '(') {
    103  1.1.2.2  nathanw 				cp++;
    104  1.1.2.2  nathanw 				break;
    105  1.1.2.2  nathanw 			}
    106  1.1.2.2  nathanw 			if (ncp < namebuf + sizeof(namebuf) - 1)
    107  1.1.2.2  nathanw 				*ncp++ = c;
    108  1.1.2.2  nathanw 			cp++;
    109  1.1.2.2  nathanw 		}
    110  1.1.2.2  nathanw 
    111  1.1.2.2  nathanw 		/* get controller number */
    112  1.1.2.2  nathanw 		if ((c = *cp) >= '0' && c <= '9') {
    113  1.1.2.2  nathanw 			ctlr = c - '0';
    114  1.1.2.2  nathanw 			c = *++cp;
    115  1.1.2.2  nathanw 		}
    116  1.1.2.2  nathanw 
    117  1.1.2.2  nathanw 		if (c == ',') {
    118  1.1.2.2  nathanw 			/* get SCSI device number */
    119  1.1.2.2  nathanw 			if ((c = *++cp) >= '0' && c <= '9') {
    120  1.1.2.2  nathanw 				unit = c - '0';
    121  1.1.2.2  nathanw 				c = *++cp;
    122  1.1.2.2  nathanw 			}
    123  1.1.2.2  nathanw 
    124  1.1.2.2  nathanw 			if (c == ',') {
    125  1.1.2.2  nathanw 				/* get partition number */
    126  1.1.2.2  nathanw 				if ((c = *++cp) >= '0' && c <= '9') {
    127  1.1.2.2  nathanw 					part = c - '0';
    128  1.1.2.2  nathanw 					c = *++cp;
    129  1.1.2.2  nathanw 				}
    130  1.1.2.2  nathanw 			}
    131  1.1.2.2  nathanw 		}
    132  1.1.2.2  nathanw 		if (c != ')')
    133  1.1.2.2  nathanw 			return (ENXIO);
    134  1.1.2.2  nathanw 		cp++;
    135  1.1.2.2  nathanw 		*ncp = '\0';
    136  1.1.2.2  nathanw 	} else {
    137  1.1.2.2  nathanw #endif
    138  1.1.2.2  nathanw 		dp = devsw;
    139  1.1.2.2  nathanw 		ctlr = unit = part = 0;
    140  1.1.2.2  nathanw 		goto fnd;
    141  1.1.2.2  nathanw #if 0
    142  1.1.2.2  nathanw 	}
    143  1.1.2.2  nathanw 
    144  1.1.2.2  nathanw 	for (dp = devsw, i = 0; i < ndevs; dp++, i++)
    145  1.1.2.2  nathanw 		if (dp->dv_name && strcmp(namebuf, dp->dv_name) == 0)
    146  1.1.2.2  nathanw 			goto fnd;
    147  1.1.2.2  nathanw 	printf("Unknown device '%s'\nKnown devices are:", namebuf);
    148  1.1.2.2  nathanw 	for (dp = devsw, i = 0; i < ndevs; dp++, i++)
    149  1.1.2.2  nathanw 		if (dp->dv_name)
    150  1.1.2.2  nathanw 			printf(" %s", dp->dv_name);
    151  1.1.2.2  nathanw 	printf("\n");
    152  1.1.2.2  nathanw 	return (ENXIO);
    153  1.1.2.2  nathanw #endif
    154  1.1.2.2  nathanw 
    155  1.1.2.2  nathanw fnd:
    156  1.1.2.2  nathanw 	rc = (dp->dv_open)(f, ctlr, unit, part);
    157  1.1.2.2  nathanw 	if (rc)
    158  1.1.2.2  nathanw 		return (rc);
    159  1.1.2.2  nathanw 
    160  1.1.2.2  nathanw 	f->f_dev = dp;
    161  1.1.2.2  nathanw 	if (file && *cp != '\0')
    162  1.1.2.2  nathanw 		*file = cp;
    163  1.1.2.2  nathanw 	return (0);
    164  1.1.2.2  nathanw }
    165