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