xref: /netbsd-src/sys/arch/hpcmips/stand/lcboot/devopen.c (revision 95e1ffb15694e54f29f8baaa4232152b703c2a5a)
1*95e1ffb1Schristos /* $NetBSD: devopen.c,v 1.3 2005/12/11 12:17:34 christos Exp $ */
21625aa91Sigy 
31625aa91Sigy /*
48f53455cSigy  * Copyright (c) 2003 Naoto Shimazaki.
51625aa91Sigy  * All rights reserved.
61625aa91Sigy  *
71625aa91Sigy  * Redistribution and use in source and binary forms, with or without
81625aa91Sigy  * modification, are permitted provided that the following conditions
91625aa91Sigy  * are met:
101625aa91Sigy  * 1. Redistributions of source code must retain the above copyright
111625aa91Sigy  *    notice, this list of conditions and the following disclaimer.
121625aa91Sigy  * 2. Redistributions in binary form must reproduce the above copyright
131625aa91Sigy  *    notice, this list of conditions and the following disclaimer in the
141625aa91Sigy  *    documentation and/or other materials provided with the distribution.
151625aa91Sigy  *
168f53455cSigy  * THIS SOFTWARE IS PROVIDED BY NAOTO SHIMAZAKI AND CONTRIBUTORS ``AS IS''
178f53455cSigy  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
188f53455cSigy  * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
198f53455cSigy  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE NAOTO OR CONTRIBUTORS BE
208f53455cSigy  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
211625aa91Sigy  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
221625aa91Sigy  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
231625aa91Sigy  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
241625aa91Sigy  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
258f53455cSigy  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
268f53455cSigy  * THE POSSIBILITY OF SUCH DAMAGE.
271625aa91Sigy  */
281625aa91Sigy #include <sys/cdefs.h>
29*95e1ffb1Schristos __KERNEL_RCSID(0, "$NetBSD: devopen.c,v 1.3 2005/12/11 12:17:34 christos Exp $");
301625aa91Sigy 
311625aa91Sigy #include <lib/libsa/stand.h>
328f53455cSigy #include <lib/libkern/libkern.h>
331625aa91Sigy 
341625aa91Sigy #include "extern.h"
351625aa91Sigy 
361625aa91Sigy int
devopen(struct open_file * f,const char * fname,char ** file)371625aa91Sigy devopen(struct open_file *f, const char *fname, char **file)
381625aa91Sigy {
398f53455cSigy 	int		i;
408f53455cSigy 	char		devname[IFNAME_SIZE];
418f53455cSigy 	const char	*basename;
428f53455cSigy 
438f53455cSigy 	for (i = 0; i < IFNAME_SIZE; i++) {
448f53455cSigy 		if (fname[i] == '\0') {
458f53455cSigy 			devname[i] = '\0';
468f53455cSigy 			basename = &fname[i];
478f53455cSigy 			break;
488f53455cSigy 		}
498f53455cSigy 		if (fname[i] == ':') {
508f53455cSigy 			devname[i] = '\0';
518f53455cSigy 			basename = &fname[i + 1];
528f53455cSigy 			break;
538f53455cSigy 		}
548f53455cSigy 		devname[i] = fname[i];
558f53455cSigy 	}
568f53455cSigy 
578f53455cSigy 	for (i = 0; i < ndevs; i++) {
588f53455cSigy 		if (strcmp(devname, devsw[i].dv_name) == 0) {
598f53455cSigy 			f->f_dev = &devsw[i];
608f53455cSigy 			return DEV_OPEN(f->f_dev)(f, basename, file);
618f53455cSigy 		}
628f53455cSigy 	}
638f53455cSigy 
648f53455cSigy 	printf("No such device - Configured devices are:\n");
658f53455cSigy 	for (i = 0; i < ndevs; i++) {
668f53455cSigy 		if (devsw[i].dv_name)
678f53455cSigy 			printf(" %s", devsw[i].dv_name);
688f53455cSigy 	}
698f53455cSigy 	printf("\n");
708f53455cSigy 
718f53455cSigy 	return ENODEV;
721625aa91Sigy }
73