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