devopen.c revision 1.3.2.2 1 1.3.2.2 yamt /* $NetBSD: devopen.c,v 1.3.2.2 2013/01/23 00:05:53 yamt Exp $ */
2 1.3.2.2 yamt
3 1.3.2.2 yamt /*
4 1.3.2.2 yamt * Copyright (c) 1992 OMRON Corporation.
5 1.3.2.2 yamt *
6 1.3.2.2 yamt * This code is derived from software contributed to Berkeley by
7 1.3.2.2 yamt * OMRON Corporation.
8 1.3.2.2 yamt *
9 1.3.2.2 yamt * Redistribution and use in source and binary forms, with or without
10 1.3.2.2 yamt * modification, are permitted provided that the following conditions
11 1.3.2.2 yamt * are met:
12 1.3.2.2 yamt * 1. Redistributions of source code must retain the above copyright
13 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer.
14 1.3.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
15 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer in the
16 1.3.2.2 yamt * documentation and/or other materials provided with the distribution.
17 1.3.2.2 yamt * 3. All advertising materials mentioning features or use of this software
18 1.3.2.2 yamt * must display the following acknowledgement:
19 1.3.2.2 yamt * This product includes software developed by the University of
20 1.3.2.2 yamt * California, Berkeley and its contributors.
21 1.3.2.2 yamt * 4. Neither the name of the University nor the names of its contributors
22 1.3.2.2 yamt * may be used to endorse or promote products derived from this software
23 1.3.2.2 yamt * without specific prior written permission.
24 1.3.2.2 yamt *
25 1.3.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
26 1.3.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 1.3.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
28 1.3.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
29 1.3.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
30 1.3.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
31 1.3.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 1.3.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
33 1.3.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
34 1.3.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 1.3.2.2 yamt * SUCH DAMAGE.
36 1.3.2.2 yamt *
37 1.3.2.2 yamt * @(#)conf.c 8.1 (Berkeley) 6/10/93
38 1.3.2.2 yamt */
39 1.3.2.2 yamt /*
40 1.3.2.2 yamt * Copyright (c) 1992, 1993
41 1.3.2.2 yamt * The Regents of the University of California. All rights reserved.
42 1.3.2.2 yamt *
43 1.3.2.2 yamt * This code is derived from software contributed to Berkeley by
44 1.3.2.2 yamt * OMRON Corporation.
45 1.3.2.2 yamt *
46 1.3.2.2 yamt * Redistribution and use in source and binary forms, with or without
47 1.3.2.2 yamt * modification, are permitted provided that the following conditions
48 1.3.2.2 yamt * are met:
49 1.3.2.2 yamt * 1. Redistributions of source code must retain the above copyright
50 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer.
51 1.3.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
52 1.3.2.2 yamt * notice, this list of conditions and the following disclaimer in the
53 1.3.2.2 yamt * documentation and/or other materials provided with the distribution.
54 1.3.2.2 yamt * 3. Neither the name of the University nor the names of its contributors
55 1.3.2.2 yamt * may be used to endorse or promote products derived from this software
56 1.3.2.2 yamt * without specific prior written permission.
57 1.3.2.2 yamt *
58 1.3.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
59 1.3.2.2 yamt * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
60 1.3.2.2 yamt * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
61 1.3.2.2 yamt * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
62 1.3.2.2 yamt * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
63 1.3.2.2 yamt * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
64 1.3.2.2 yamt * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
65 1.3.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
66 1.3.2.2 yamt * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
67 1.3.2.2 yamt * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
68 1.3.2.2 yamt * SUCH DAMAGE.
69 1.3.2.2 yamt *
70 1.3.2.2 yamt * @(#)conf.c 8.1 (Berkeley) 6/10/93
71 1.3.2.2 yamt */
72 1.3.2.2 yamt
73 1.3.2.2 yamt #include <lib/libkern/libkern.h>
74 1.3.2.2 yamt #include <luna68k/stand/boot/samachdep.h>
75 1.3.2.2 yamt #include <machine/disklabel.h>
76 1.3.2.2 yamt
77 1.3.2.2 yamt static int make_device(const char *, int *, int *, int *, char **);
78 1.3.2.2 yamt
79 1.3.2.2 yamt int
80 1.3.2.2 yamt devopen(struct open_file *f, const char *fname, char **file)
81 1.3.2.2 yamt {
82 1.3.2.2 yamt int dev, unit, part;
83 1.3.2.2 yamt int error;
84 1.3.2.2 yamt struct devsw *dp;
85 1.3.2.2 yamt int i;
86 1.3.2.2 yamt
87 1.3.2.2 yamt if (make_device(fname, &dev, &unit, &part, file) != 0)
88 1.3.2.2 yamt return ENXIO;
89 1.3.2.2 yamt
90 1.3.2.2 yamt #ifdef DEBUG
91 1.3.2.2 yamt printf("%s: %s(%d,%d)%s\n", __func__,
92 1.3.2.2 yamt devsw[dev].dv_name, unit, part, *file);
93 1.3.2.2 yamt #endif
94 1.3.2.2 yamt dp = &devsw[dev];
95 1.3.2.2 yamt error = (*dp->dv_open)(f, unit, part);
96 1.3.2.2 yamt if (error != 0) {
97 1.3.2.2 yamt #ifdef DEBUG
98 1.3.2.2 yamt printf("%s: open %s(%d,%d)%s failed (%s)\n", __func__,
99 1.3.2.2 yamt devsw[dev].dv_name, unit, part, *file, strerror(error));
100 1.3.2.2 yamt #endif
101 1.3.2.2 yamt return error;
102 1.3.2.2 yamt }
103 1.3.2.2 yamt
104 1.3.2.2 yamt for (i = 0; i < nfsys_disk; i++)
105 1.3.2.2 yamt file_system[i] = file_system_disk[i];
106 1.3.2.2 yamt nfsys = nfsys_disk;
107 1.3.2.2 yamt
108 1.3.2.2 yamt #ifdef SUPPORT_ETHERNET
109 1.3.2.2 yamt if (strcmp(dp->dv_name, "le") == 0) {
110 1.3.2.2 yamt /* XXX mixing local fs_ops on netboot could be troublesome */
111 1.3.2.2 yamt file_system[0] = file_system_nfs[0];
112 1.3.2.2 yamt nfsys = 1;
113 1.3.2.2 yamt }
114 1.3.2.2 yamt #endif
115 1.3.2.2 yamt
116 1.3.2.2 yamt f->f_dev = dp;
117 1.3.2.2 yamt
118 1.3.2.2 yamt return 0;
119 1.3.2.2 yamt }
120 1.3.2.2 yamt
121 1.3.2.2 yamt int
122 1.3.2.2 yamt make_device(const char *str, int *devp, int *unitp, int *partp, char **fname)
123 1.3.2.2 yamt {
124 1.3.2.2 yamt const char *cp;
125 1.3.2.2 yamt struct devsw *dp;
126 1.3.2.2 yamt int major, unit, part;
127 1.3.2.2 yamt int i;
128 1.3.2.2 yamt char devname[MAXDEVNAME + 1];
129 1.3.2.2 yamt
130 1.3.2.2 yamt /*
131 1.3.2.2 yamt * parse path strings
132 1.3.2.2 yamt */
133 1.3.2.2 yamt /* find end of dev type name */
134 1.3.2.2 yamt for (cp = str, i = 0; *cp != '\0' && *cp != '(' && i < MAXDEVNAME; i++)
135 1.3.2.2 yamt devname[i] = *cp++;
136 1.3.2.2 yamt if (*cp != '(') {
137 1.3.2.2 yamt return (-1);
138 1.3.2.2 yamt }
139 1.3.2.2 yamt devname[i] = '\0';
140 1.3.2.2 yamt /* compare dev type name */
141 1.3.2.2 yamt for (dp = devsw; dp->dv_name; dp++)
142 1.3.2.2 yamt if (!strcmp(devname, dp->dv_name))
143 1.3.2.2 yamt break;
144 1.3.2.2 yamt cp++;
145 1.3.2.2 yamt if (dp->dv_name == NULL) {
146 1.3.2.2 yamt return (-1);
147 1.3.2.2 yamt }
148 1.3.2.2 yamt major = dp - devsw;
149 1.3.2.2 yamt /* get unit number */
150 1.3.2.2 yamt unit = *cp++ - '0';
151 1.3.2.2 yamt if (*cp >= '0' && *cp <= '9')
152 1.3.2.2 yamt unit = unit * 10 + *cp++ - '0';
153 1.3.2.2 yamt if (unit < 0 || unit > 63) {
154 1.3.2.2 yamt #ifdef DEBUG
155 1.3.2.2 yamt printf("%s: invalid unit number (%d)\n", __func__, unit);
156 1.3.2.2 yamt #endif
157 1.3.2.2 yamt return (-1);
158 1.3.2.2 yamt }
159 1.3.2.2 yamt /* get partition offset */
160 1.3.2.2 yamt if (*cp++ != ',') {
161 1.3.2.2 yamt return (-1);
162 1.3.2.2 yamt }
163 1.3.2.2 yamt part = *cp - '0';
164 1.3.2.2 yamt /* check out end of dev spec */
165 1.3.2.2 yamt for (;;) {
166 1.3.2.2 yamt if (*cp == ')')
167 1.3.2.2 yamt break;
168 1.3.2.2 yamt if (*cp++)
169 1.3.2.2 yamt continue;
170 1.3.2.2 yamt return (-1);
171 1.3.2.2 yamt }
172 1.3.2.2 yamt if (part < 0 || part > MAXPARTITIONS) {
173 1.3.2.2 yamt #ifdef DEBUG
174 1.3.2.2 yamt printf("%s: invalid partition number (%d)\n", __func__, part);
175 1.3.2.2 yamt #endif
176 1.3.2.2 yamt return (-1);
177 1.3.2.2 yamt }
178 1.3.2.2 yamt
179 1.3.2.2 yamt *devp = major;
180 1.3.2.2 yamt *unitp = unit;
181 1.3.2.2 yamt *partp = part;
182 1.3.2.2 yamt *fname = __UNCONST(cp + 1);
183 1.3.2.2 yamt #ifdef DEBUG
184 1.3.2.2 yamt printf("%s: major = %d, unit = %d, part = %d, fname = %s\n",
185 1.3.2.2 yamt __func__, major, unit, part, *fname);
186 1.3.2.2 yamt #endif
187 1.3.2.2 yamt
188 1.3.2.2 yamt return 0;
189 1.3.2.2 yamt }
190