|
|
1.1 root 1: /*
2: * Copyright (c) 1999 Apple Computer, Inc. All rights reserved.
3: *
4: * @APPLE_LICENSE_HEADER_START@
5: *
6: * Portions Copyright (c) 1999 Apple Computer, Inc. All Rights
7: * Reserved. This file contains Original Code and/or Modifications of
8: * Original Code as defined in and that are subject to the Apple Public
9: * Source License Version 1.1 (the "License"). You may not use this file
10: * except in compliance with the License. Please obtain a copy of the
11: * License at http://www.apple.com/publicsource and read it before using
12: * this file.
13: *
14: * The Original Code and all software distributed under the License are
15: * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
16: * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
17: * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
18: * FITNESS FOR A PARTICULAR PURPOSE OR NON- INFRINGEMENT. Please see the
19: * License for the specific language governing rights and limitations
20: * under the License.
21: *
22: * @APPLE_LICENSE_HEADER_END@
23: */
24: /* Copyright (c) 1991 NeXT Computer, Inc. All rights reserved.
25: *
26: * devswAndVfssw.m - Kernel-level functions to allow adding entries
27: * to cdevsw, bdevsw, and vfssw.
28: *
29: * HISTORY
30: * 20-Jan-93 Doug Mitchell at NeXT
31: * Created.
32: */
33:
34: #import <driverkit/devsw.h>
35: #import <bsd/sys/conf.h>
36: #import <bsd/sys/systm.h>
37:
38: #ifndef NULL
39: #define NULL ((void *)0)
40: #endif NULL
41:
42: /*
43: * Empty devsw slots are explicitly set to actual stub functions in the
44: * kernel.
45: */
46:
47: static struct cdevsw no_cdev = NO_CDEVICE;
48: static struct bdevsw no_bdev = NO_BDEVICE;
49:
50: /*
51: * Add an entry to bdevsw. Returns the index into bdevsw at which the entry
52: * was created, or -1 of no space can be found.
53: */
54:
55: int IOAddToBdevswAt(
56: int index,
57: IOSwitchFunc openFunc,
58: IOSwitchFunc closeFunc,
59: IOSwitchFunc strategyFunc,
60: IOSwitchFunc ioctlFunc,
61: IOSwitchFunc dumpFunc,
62: IOSwitchFunc psizeFunc,
63: BOOL isTape // TRUE if device is a tape device
64: )
65: {
66: struct bdevsw *devsw;
67:
68: if (index == -1) {
69: devsw = bdevsw;
70: for(index=0; index<nblkdev; index++, devsw++) {
71: if(memcmp((char *)devsw,
72: (char *)&no_bdev,
73: sizeof(struct bdevsw)) == 0)
74: break;
75: }
76: }
77: devsw = &bdevsw[index];
78: if ((index < 0) || (index >= nblkdev) ||
79: (memcmp((char *)devsw,
80: (char *)&no_bdev,
81: sizeof(struct bdevsw)) != 0)) {
82: return -1;
83: }
84: devsw->d_open = openFunc;
85: devsw->d_close = closeFunc;
86: devsw->d_strategy = (strategy_fcn_t *)strategyFunc;
87: devsw->d_ioctl = ioctlFunc;
88: devsw->d_dump = dumpFunc;
89: devsw->d_psize = psizeFunc;
90: devsw->d_type = 0;
91: if(isTape) {
92: /*
93: * This is pure bullshit. This flag is
94: * defined in sys/buf.h, and is only used
95: * in ufs_vfsops.c, in the bdevsw flags!
96: */
97: devsw->d_type |= D_TAPE;
98: }
99: return index;
100: }
101:
102: int IOAddToBdevsw(
103: IOSwitchFunc openFunc,
104: IOSwitchFunc closeFunc,
105: IOSwitchFunc strategyFunc,
106: IOSwitchFunc ioctlFunc,
107: IOSwitchFunc dumpFunc,
108: IOSwitchFunc psizeFunc,
109: BOOL isTape) // TRUE if device is a tape device
110: {
111: return IOAddToBdevswAt( -1,
112: openFunc,
113: closeFunc,
114: strategyFunc,
115: ioctlFunc,
116: dumpFunc,
117: psizeFunc,
118: isTape);
119: }
120:
121: /*
122: * Remove an entry from bdevsw, replace it with a null entry.
123: */
124: void IORemoveFromBdevsw(int bdevswNumber)
125: {
126: bdevsw[bdevswNumber] = no_bdev;
127: }
128:
129: /*
130: * Add an entry to cdevsw. Returns the index into cdevsw at which the entry
131: * was created, or -1 of no space can be found.
132: */
133: int IOAddToCdevswAt(
134: int index,
135: IOSwitchFunc openFunc,
136: IOSwitchFunc closeFunc,
137: IOSwitchFunc readFunc,
138: IOSwitchFunc writeFunc,
139: IOSwitchFunc ioctlFunc,
140: IOSwitchFunc stopFunc,
141: IOSwitchFunc resetFunc,
142: IOSwitchFunc selectFunc,
143: IOSwitchFunc mmapFunc,
144: IOSwitchFunc getcFunc,
145: IOSwitchFunc putcFunc
146: )
147: {
148: struct cdevsw *devsw;
149:
150: if (index == -1) {
151: devsw = cdevsw;
152: for(index=0; index<nchrdev; index++, devsw++) {
153: if (memcmp((char *)devsw,
154: (char *)&no_cdev,
155: sizeof(struct cdevsw)) == 0)
156: break;
157: }
158: }
159: devsw = &cdevsw[index];
160: if ((index < 0) || (index >= nchrdev) ||
161: (memcmp((char *)devsw,
162: (char *)&no_cdev,
163: sizeof(struct cdevsw)) != 0)) {
164: return -1;
165: }
166: devsw->d_open = openFunc;
167: devsw->d_close = closeFunc;
168: devsw->d_read = readFunc;
169: devsw->d_write = writeFunc;
170: devsw->d_ioctl = ioctlFunc;
171: devsw->d_stop = stopFunc;
172: devsw->d_reset = resetFunc;
173: devsw->d_select = selectFunc;
174: devsw->d_mmap = mmapFunc;
175: devsw->d_getc = getcFunc;
176: devsw->d_putc = (putc_fcn_t *)putcFunc;
177: return index;
178: }
179:
180: int IOAddToCdevsw(
181: IOSwitchFunc openFunc,
182: IOSwitchFunc closeFunc,
183: IOSwitchFunc readFunc,
184: IOSwitchFunc writeFunc,
185: IOSwitchFunc ioctlFunc,
186: IOSwitchFunc stopFunc,
187: IOSwitchFunc resetFunc,
188: IOSwitchFunc selectFunc,
189: IOSwitchFunc mmapFunc,
190: IOSwitchFunc getcFunc,
191: IOSwitchFunc putcFunc)
192: {
193: return IOAddToCdevswAt( -1,
194: openFunc,
195: closeFunc,
196: readFunc,
197: writeFunc,
198: ioctlFunc,
199: stopFunc,
200: resetFunc,
201: selectFunc,
202: mmapFunc,
203: getcFunc,
204: putcFunc);
205: }
206:
207: /*
208: * Remove an entry from cdevsw, replace it with a null entry.
209: */
210: void IORemoveFromCdevsw(int cdevswNumber)
211: {
212: cdevsw[cdevswNumber] = no_cdev;
213: }
214:
215: #warning removed vfssw support
216: #if 0
217:
218: /*
219: * Add an entry to vfssw. Returns the index into vfssw at which the entry
220: * was created, or -1 of no space can be found.
221: */
222: int IOAddToVfsswAt(
223: int index,
224: const char *vfsswName,
225: const struct vfsops *vfsswOps
226: )
227: {
228: struct vfssw *sw = &vfssw[index];
229: if ((index < 0) || (index >= (vfsNVFS - vfssw))
230: || (sw->vsw_name != NULL) || (sw->vsw_ops != NULL))
231: return -1;
232: sw->vsw_name = (char *)vfsswName;
233: sw->vsw_ops = (struct vfsops *)vfsswOps;
234: return index;
235: }
236: int IOAddToVfssw(
237: const char *vfsswName,
238: const struct vfsops *vfsswOps)
239: {
240: int index;
241: struct vfssw *sw = vfssw;
242:
243: for(index=0; sw<vfsNVFS; index++, sw++) {
244: if((sw->vsw_name == NULL) && (sw->vsw_ops == NULL)) {
245: return IOAddToVfsswAt(index, vfsswName, vfsswOps);
246: }
247: }
248: return -1;
249: }
250:
251: /*
252: * Remove an entry from vfssw, replace it with a null entry.
253: */
254: void IORemoveFromVfssw(int vfsswNumber)
255: {
256: vfssw[vfsswNumber].vsw_name = NULL;
257: vfssw[vfsswNumber].vsw_ops = NULL;
258: }
259:
260: #endif
261:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.