Deleted Added
full compact
kern_conf.c (47300) kern_conf.c (47640)
1/*-
2 * Parts Copyright (c) 1995 Terrence R. Lambert
3 * Copyright (c) 1995 Julian R. Elischer
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 16 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
1/*-
2 * Parts Copyright (c) 1995 Terrence R. Lambert
3 * Copyright (c) 1995 Julian R. Elischer
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 16 unchanged lines hidden (view full) ---

25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 *
33 * $Id: kern_conf.c,v 1.39 1999/05/12 13:06:34 phk Exp $
33 * $Id: kern_conf.c,v 1.40 1999/05/18 13:14:43 luoqi Exp $
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/module.h>
39#include <sys/conf.h>
40#include <sys/vnode.h>
41
34 */
35
36#include <sys/param.h>
37#include <sys/systm.h>
38#include <sys/module.h>
39#include <sys/conf.h>
40#include <sys/vnode.h>
41
42#define NUMCDEV 256
43#define cdevsw_ALLOCSTART (NUMCDEV/2)
42#define cdevsw_ALLOCSTART (NUMCDEVSW/2)
44
43
45struct cdevsw *cdevsw[NUMCDEV];
46int nchrdev = NUMCDEV;
44struct cdevsw *cdevsw[NUMCDEVSW];
47
45
48int bmaj2cmaj[NUMCDEV];
49int nblkdev = NUMCDEV;
46int bmaj2cmaj[NUMCDEVSW];
50
51/*
52 * Routine to convert from character to block device number.
53 *
54 * A minimal stub routine can always return NODEV.
55 */
56dev_t
57chrtoblk(dev_t dev)
58{
59 struct cdevsw *cd;
60
61 if((cd = devsw(dev)) != NULL) {
62 if (cd->d_bmaj != -1)
63 return(makedev(cd->d_bmaj,minor(dev)));
64 }
65 return(NODEV);
66}
67
47
48/*
49 * Routine to convert from character to block device number.
50 *
51 * A minimal stub routine can always return NODEV.
52 */
53dev_t
54chrtoblk(dev_t dev)
55{
56 struct cdevsw *cd;
57
58 if((cd = devsw(dev)) != NULL) {
59 if (cd->d_bmaj != -1)
60 return(makedev(cd->d_bmaj,minor(dev)));
61 }
62 return(NODEV);
63}
64
65struct cdevsw *
66devsw(dev_t dev)
67{
68 return(cdevsw[major(dev)]);
69}
70
71struct cdevsw *
72bdevsw(dev_t dev)
73{
74 struct cdevsw *c;
75 int i = major(dev);
76
77 if (bmaj2cmaj[i] == 254)
78 return 0;
79
80 c = cdevsw[bmaj2cmaj[major(dev)]];
81 if (!c) {
82 printf("bogus bdev dev_t %p, no cdev\n", (void *)dev);
83 Debugger("Bummer");
84 return 0;
85 }
86 /* CMAJ zero is the console, which has no strategy so this works */
87 if (c->d_strategy)
88 return (c);
89 return (0);
90}
91
92/*
93 * Add a cdevsw entry
94 */
95
68int
96int
69cdevsw_add(dev_t *descrip,
70 struct cdevsw *newentry,
71 struct cdevsw **oldentry)
97cdevsw_add(struct cdevsw *newentry)
72{
73 int i;
74 static int setup;
75
76 if (!setup) {
98{
99 int i;
100 static int setup;
101
102 if (!setup) {
77 for (i = 0; i < NUMCDEV; i++)
103 for (i = 0; i < NUMCDEVSW; i++)
78 if (!bmaj2cmaj[i])
79 bmaj2cmaj[i] = 254;
80 setup++;
81 }
82
104 if (!bmaj2cmaj[i])
105 bmaj2cmaj[i] = 254;
106 setup++;
107 }
108
83 if ( *descrip == NODEV) { /* auto (0 is valid) */
84 /*
85 * Search the table looking for a slot...
86 */
87 for (i = cdevsw_ALLOCSTART; i < nchrdev; i++)
88 if (cdevsw[i] == NULL)
89 break; /* found one! */
90 /* out of allocable slots? */
91 if (i >= nchrdev) {
92 return ENFILE;
93 }
94 } else { /* assign */
95 i = major(*descrip);
96 if (i < 0 || i >= nchrdev) {
97 return EINVAL;
98 }
109 if (newentry->d_maj < 0 || newentry->d_maj >= NUMCDEVSW) {
110 printf("%s: ERROR: driver has bogus cdevsw->d_maj = %d\n",
111 newentry->d_name, newentry->d_maj);
112 return EINVAL;
99 }
100
113 }
114
101 /* maybe save old */
102 if (oldentry) {
103 *oldentry = cdevsw[i];
104 }
105 if (newentry) {
106 newentry->d_bmaj = -1;
107 newentry->d_maj = i;
108 }
109 /* replace with new */
110 cdevsw[i] = newentry;
115 cdevsw[newentry->d_maj] = newentry;
111
116
112 /* done! let them know where we put it */
113 *descrip = makedev(i,0);
117 if (newentry->d_bmaj >= 0 || newentry->d_bmaj < NUMCDEVSW)
118 bmaj2cmaj[newentry->d_bmaj] = newentry->d_maj;
119
114 return 0;
115}
116
120 return 0;
121}
122
117void
118cdevsw_add_generic(int bmaj, int cmaj, struct cdevsw *devsw)
119{
120 dev_t dev;
121
122 dev = makedev(cmaj, 0);
123 cdevsw_add(&dev, devsw, NULL);
124 cdevsw[cmaj]->d_bmaj = bmaj;
125 bmaj2cmaj[bmaj] = cmaj;
126}
127
128int
129devsw_module_handler(module_t mod, int what, void* arg)
130{
131 struct devsw_module_data* data = (struct devsw_module_data*) arg;
132 int error;
133
134 if (data->cmaj == NOMAJ)
135 data->cdev = NODEV;
136 else
137 data->cdev = makedev(data->cmaj, 0);
138 switch (what) {
139 case MOD_LOAD:
123int
124devsw_module_handler(module_t mod, int what, void* arg)
125{
126 struct devsw_module_data* data = (struct devsw_module_data*) arg;
127 int error;
128
129 if (data->cmaj == NOMAJ)
130 data->cdev = NODEV;
131 else
132 data->cdev = makedev(data->cmaj, 0);
133 switch (what) {
134 case MOD_LOAD:
140 error = cdevsw_add(&data->cdev, data->cdevsw, NULL);
135 error = cdevsw_add(data->cdevsw);
141 if (!error && data->cdevsw->d_strategy != nostrategy) {
142 if (data->bmaj == NOMAJ) {
143 data->bdev = data->cdev;
144 data->bmaj = data->cmaj;
145 } else {
146 data->bdev = makedev(data->bmaj, 0);
147 }
148 data->cdevsw->d_maj = data->bmaj;

--- 6 unchanged lines hidden (view full) ---

155 case MOD_UNLOAD:
156 if (data->chainevh) {
157 error = data->chainevh(mod, what, data->chainarg);
158 if (error)
159 return error;
160 }
161 if (data->cdevsw->d_strategy != nostrategy)
162 bmaj2cmaj[major(data->bdev)] = 0;
136 if (!error && data->cdevsw->d_strategy != nostrategy) {
137 if (data->bmaj == NOMAJ) {
138 data->bdev = data->cdev;
139 data->bmaj = data->cmaj;
140 } else {
141 data->bdev = makedev(data->bmaj, 0);
142 }
143 data->cdevsw->d_maj = data->bmaj;

--- 6 unchanged lines hidden (view full) ---

150 case MOD_UNLOAD:
151 if (data->chainevh) {
152 error = data->chainevh(mod, what, data->chainarg);
153 if (error)
154 return error;
155 }
156 if (data->cdevsw->d_strategy != nostrategy)
157 bmaj2cmaj[major(data->bdev)] = 0;
163 error = cdevsw_add(&data->cdev, NULL, NULL);
164 return error;
165 }
166
167 if (data->chainevh)
168 return data->chainevh(mod, what, data->chainarg);
169 else
170 return 0;
171}

--- 67 unchanged lines hidden ---
158 return error;
159 }
160
161 if (data->chainevh)
162 return data->chainevh(mod, what, data->chainarg);
163 else
164 return 0;
165}

--- 67 unchanged lines hidden ---