1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
|
/*
* Mach Operating System
* Copyright (c) 1991,1990,1989 Carnegie Mellon University
* All Rights Reserved.
*
* Permission to use, copy, modify and distribute this software and its
* documentation is hereby granted, provided that both the copyright
* notice and this permission notice appear in all copies of the
* software, derivative works or modified versions, and any portions
* thereof, and that both notices appear in supporting documentation.
*
* CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
* CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
* ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
*
* Carnegie Mellon requests users of this software to return to
*
* Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
* School of Computer Science
* Carnegie Mellon University
* Pittsburgh PA 15213-3890
*
* any improvements or extensions that they make and grant Carnegie Mellon
* the rights to redistribute these changes.
*/
/*
* Author: David B. Golub, Carnegie Mellon University
* Date: 8/89
*/
#include <kern/printf.h>
#include <string.h>
#include <device/device_types.h>
#include <device/dev_hdr.h>
#include <device/conf.h>
/*
* Routines placed in empty entries in the device tables
*/
int nulldev(void)
{
return (D_SUCCESS);
}
int nodev(void)
{
return (D_INVALID_OPERATION);
}
vm_offset_t
nomap(void)
{
return (D_INVALID_OPERATION);
}
/*
* Name comparison routine.
* Compares first 'len' characters of 'src'
* with 'target', which is zero-terminated.
* Returns TRUE if strings are equal:
* src and target are equal in first 'len' characters
* next character of target is 0 (end of string).
*/
boolean_t
name_equal(src, len, target)
const char *src;
int len;
const char *target;
{
while (--len >= 0)
if (*src++ != *target++)
return FALSE;
return *target == 0;
}
/*
* device name lookup
*/
boolean_t dev_name_lookup(name, ops, unit)
char *name;
dev_ops_t *ops; /* out */
int *unit; /* out */
{
/*
* Assume that block device names are of the form
*
* <device_name><unit_number>[[<slice num>]<partition>]
*
* where
* <device_name> is the name in the device table
* <unit_number> is an integer
* <slice num> * is 's' followed by a number (disks only!)
* <partition> is a letter in [a-h] (disks only?)
*/
char *cp = name;
int len;
int j = 0;
int c;
dev_ops_t dev;
boolean_t found;
int slice_num = 0;
/*
* Find device type name (characters before digit)
*/
while ((c = *cp) != '\0' &&
!(c >= '0' && c <= '9'))
cp++;
len = cp - name;
if (c != '\0') {
/*
* Find unit number
*/
while ((c = *cp) != '\0' &&
c >= '0' && c <= '9') {
j = j * 10 + (c - '0');
cp++;
}
}
found = FALSE;
dev_search(dev) {
if (name_equal(name, len, dev->d_name)) {
found = TRUE;
break;
}
}
if (!found) {
/* name not found - try indirection list */
dev_indirect_t di;
dev_indirect_search(di) {
if (name_equal(name, len, di->d_name)) {
/*
* Return device and unit from indirect vector.
*/
*ops = di->d_ops;
*unit = di->d_unit;
return (TRUE);
}
}
/* Not found in either list. */
return (FALSE);
}
*ops = dev;
*unit = j;
/*
* Find sub-device number
*/
j = dev->d_subdev;
if (j > 0) {
/* if no slice string, slice num = 0 */
/* <subdev_count>*unit + <slice_number>*16 -- I know it's bad */
*unit *= j;
/* find slice ? */
if (c == 's') {
cp++;
while ((c = *cp) != '\0' &&
c >= '0' && c <= '9') {
slice_num = slice_num * 10 + (c - '0');
cp++;
}
}
*unit += (slice_num << 4);
/* if slice==0, it is either compatability or whole device */
if (c >= 'a' && c < 'a' + j) { /* note: w/o this -> whole slice */
/*
* Minor number is <subdev_count>*unit + letter.
* NOW it is slice result + letter
*/
*unit += (c - 'a' +1);
}
}
return (TRUE);
}
/*
* Change an entry in the indirection list.
*/
void
dev_set_indirection(name, ops, unit)
const char *name;
dev_ops_t ops;
int unit;
{
dev_indirect_t di;
dev_indirect_search(di) {
if (!strcmp(di->d_name, name)) {
di->d_ops = ops;
di->d_unit = unit;
break;
}
}
}
boolean_t dev_change_indirect(iname, dname, unit)
const char *iname;
const char *dname;
int unit;
{
struct dev_ops *dp;
struct dev_indirect *di;
boolean_t found = FALSE;
dev_search(dp) {
if (!strcmp(dp->d_name, dname)) {
found = TRUE;
break;
}
}
if (!found) return FALSE;
dev_indirect_search(di) {
if (!strcmp(di->d_name, iname)) {
di->d_ops = dp;
di->d_unit = unit;
return TRUE;
}
}
return FALSE;
}
|