devopen.c revision 1.2 1 1.1 igy /* $NetBSD: devopen.c,v 1.2 2003/08/09 08:01:46 igy Exp $ */
2 1.1 igy
3 1.1 igy /*
4 1.2 igy * Copyright (c) 2003 Naoto Shimazaki.
5 1.1 igy * All rights reserved.
6 1.1 igy *
7 1.1 igy * Redistribution and use in source and binary forms, with or without
8 1.1 igy * modification, are permitted provided that the following conditions
9 1.1 igy * are met:
10 1.1 igy * 1. Redistributions of source code must retain the above copyright
11 1.1 igy * notice, this list of conditions and the following disclaimer.
12 1.1 igy * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 igy * notice, this list of conditions and the following disclaimer in the
14 1.1 igy * documentation and/or other materials provided with the distribution.
15 1.1 igy *
16 1.2 igy * THIS SOFTWARE IS PROVIDED BY NAOTO SHIMAZAKI AND CONTRIBUTORS ``AS IS''
17 1.2 igy * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
18 1.2 igy * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 1.2 igy * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE NAOTO OR CONTRIBUTORS BE
20 1.2 igy * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 1.1 igy * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 1.1 igy * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 1.1 igy * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 1.1 igy * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 1.2 igy * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
26 1.2 igy * THE POSSIBILITY OF SUCH DAMAGE.
27 1.1 igy */
28 1.1 igy #include <sys/cdefs.h>
29 1.2 igy __KERNEL_RCSID(0, "$NetBSD: devopen.c,v 1.2 2003/08/09 08:01:46 igy Exp $");
30 1.1 igy
31 1.1 igy #include <lib/libsa/stand.h>
32 1.2 igy #include <lib/libkern/libkern.h>
33 1.1 igy
34 1.1 igy #include "extern.h"
35 1.1 igy
36 1.1 igy int
37 1.1 igy devopen(struct open_file *f, const char *fname, char **file)
38 1.1 igy {
39 1.2 igy int i;
40 1.2 igy char devname[IFNAME_SIZE];
41 1.2 igy const char *basename;
42 1.2 igy
43 1.2 igy for (i = 0; i < IFNAME_SIZE; i++) {
44 1.2 igy if (fname[i] == '\0') {
45 1.2 igy devname[i] = '\0';
46 1.2 igy basename = &fname[i];
47 1.2 igy break;
48 1.2 igy }
49 1.2 igy if (fname[i] == ':') {
50 1.2 igy devname[i] = '\0';
51 1.2 igy basename = &fname[i + 1];
52 1.2 igy break;
53 1.2 igy }
54 1.2 igy devname[i] = fname[i];
55 1.2 igy }
56 1.2 igy
57 1.2 igy for (i = 0; i < ndevs; i++) {
58 1.2 igy if (strcmp(devname, devsw[i].dv_name) == 0) {
59 1.2 igy f->f_dev = &devsw[i];
60 1.2 igy return DEV_OPEN(f->f_dev)(f, basename, file);
61 1.2 igy }
62 1.2 igy }
63 1.2 igy
64 1.2 igy printf("No such device - Configured devices are:\n");
65 1.2 igy for (i = 0; i < ndevs; i++) {
66 1.2 igy if (devsw[i].dv_name)
67 1.2 igy printf(" %s", devsw[i].dv_name);
68 1.2 igy }
69 1.2 igy printf("\n");
70 1.2 igy
71 1.2 igy return ENODEV;
72 1.1 igy }
73