kern_conf.c (37172) | kern_conf.c (37389) |
---|---|
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.25 1998/06/25 11:27:34 phk Exp $ | 33 * $Id: kern_conf.c,v 1.26 1998/06/26 18:14:25 phk 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 42#define NUMBDEV 128 43#define NUMCDEV 256 44#define bdevsw_ALLOCSTART (NUMBDEV/2) 45#define cdevsw_ALLOCSTART (NUMCDEV/2) 46 | 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 NUMBDEV 128 43#define NUMCDEV 256 44#define bdevsw_ALLOCSTART (NUMBDEV/2) 45#define cdevsw_ALLOCSTART (NUMCDEV/2) 46 |
47struct bdevsw *bdevsw[NUMBDEV]; | 47struct cdevsw *bdevsw[NUMBDEV]; |
48int nblkdev = NUMBDEV; 49struct cdevsw *cdevsw[NUMCDEV]; 50int nchrdev = NUMCDEV; 51 | 48int nblkdev = NUMBDEV; 49struct cdevsw *cdevsw[NUMCDEV]; 50int nchrdev = NUMCDEV; 51 |
52static void cdevsw_make __P((struct bdevsw *from)); 53 | |
54/* 55 * Routine to convert from character to block device number. 56 * 57 * A minimal stub routine can always return NODEV. 58 */ 59dev_t 60chrtoblk(dev_t dev) 61{ 62 struct bdevsw *bd; 63 struct cdevsw *cd; 64 65 if(cd = cdevsw[major(dev)]) { | 52/* 53 * Routine to convert from character to block device number. 54 * 55 * A minimal stub routine can always return NODEV. 56 */ 57dev_t 58chrtoblk(dev_t dev) 59{ 60 struct bdevsw *bd; 61 struct cdevsw *cd; 62 63 if(cd = cdevsw[major(dev)]) { |
66 if ( (bd = cd->d_bdev) ) 67 return(makedev(bd->d_maj,minor(dev))); | 64 if (cd->d_bmaj != -1) 65 return(makedev(cd->d_bmaj,minor(dev))); |
68 } 69 return(NODEV); 70} 71 72/* 73 * (re)place an entry in the bdevsw or cdevsw table 74 * return the slot used in major(*descrip) 75 */ | 66 } 67 return(NODEV); 68} 69 70/* 71 * (re)place an entry in the bdevsw or cdevsw table 72 * return the slot used in major(*descrip) 73 */ |
76#define ADDENTRY(TTYPE,NXXXDEV,ALLOCSTART) \ 77int TTYPE##_add(dev_t *descrip, \ 78 struct TTYPE *newentry, \ 79 struct TTYPE **oldentry) \ 80{ \ 81 int i ; \ 82 if ( (int)*descrip == NODEV) { /* auto (0 is valid) */ \ 83 /* \ 84 * Search the table looking for a slot... \ 85 */ \ 86 for (i = ALLOCSTART; i < NXXXDEV; i++) \ 87 if (TTYPE[i] == NULL) \ 88 break; /* found one! */ \ 89 /* out of allocable slots? */ \ 90 if (i >= NXXXDEV) { \ 91 return ENFILE; \ 92 } \ 93 } else { /* assign */ \ 94 i = major(*descrip); \ 95 if (i < 0 || i >= NXXXDEV) { \ 96 return EINVAL; \ 97 } \ 98 } \ 99 \ 100 /* maybe save old */ \ 101 if (oldentry) { \ 102 *oldentry = TTYPE[i]; \ 103 } \ 104 if (newentry) \ 105 newentry->d_maj = i; \ 106 /* replace with new */ \ 107 TTYPE[i] = newentry; \ 108 \ 109 /* done! let them know where we put it */ \ 110 *descrip = makedev(i,0); \ 111 return 0; \ 112} \ | 74static int 75bdevsw_add(dev_t *descrip, 76 struct cdevsw *newentry, 77 struct cdevsw **oldentry) 78{ 79 int i ; |
113 | 80 |
114static ADDENTRY(bdevsw, nblkdev,bdevsw_ALLOCSTART) 115ADDENTRY(cdevsw, nchrdev,cdevsw_ALLOCSTART) | 81 if ( (int)*descrip == NODEV) { /* auto (0 is valid) */ 82 /* 83 * Search the table looking for a slot... 84 */ 85 for (i = bdevsw_ALLOCSTART; i < nblkdev; i++) 86 if (bdevsw[i] == NULL) 87 break; /* found one! */ 88 /* out of allocable slots? */ 89 if (i >= nblkdev) { 90 return ENFILE; 91 } 92 } else { /* assign */ 93 i = major(*descrip); 94 if (i < 0 || i >= nblkdev) { 95 return EINVAL; 96 } 97 } |
116 | 98 |
117/* 118 * Since the bdevsw struct for a disk contains all the information 119 * needed to create a cdevsw entry, these two routines do that, rather 120 * than specifying it by hand. 121 */ | 99 /* maybe save old */ 100 if (oldentry) { 101 *oldentry = bdevsw[i]; 102 } 103 if (newentry) { 104 newentry->d_bmaj = i; 105 } 106 /* replace with new */ 107 bdevsw[i] = newentry; |
122 | 108 |
123static void 124cdevsw_make(struct bdevsw *from) | 109 /* done! let them know where we put it */ 110 *descrip = makedev(i,0); 111 return 0; 112} 113 114int 115cdevsw_add(dev_t *descrip, 116 struct cdevsw *newentry, 117 struct cdevsw **oldentry) |
125{ | 118{ |
126 struct cdevsw *to = from->d_cdev; | 119 int i ; |
127 | 120 |
128 if (!to) 129 panic("No target cdevsw in bdevsw"); 130 to->d_open = from->d_open; 131 to->d_close = from->d_close; 132 to->d_read = rawread; 133 to->d_write = rawwrite; 134 to->d_ioctl = from->d_ioctl; 135 to->d_stop = nostop; 136 to->d_reset = nullreset; 137 to->d_devtotty = nodevtotty; 138 to->d_poll = seltrue; 139 to->d_mmap = nommap; 140 to->d_strategy = from->d_strategy; 141 to->d_name = from->d_name; 142 to->d_bdev = from; 143 to->d_maj = -1; 144 to->d_bmaj = from->d_maj; 145 to->d_maxio = from->d_maxio; 146 to->d_dump = from->d_dump; 147 to->d_psize = from->d_psize; 148 to->d_flags = from->d_flags; 149} | 121 if ( (int)*descrip == NODEV) { /* auto (0 is valid) */ 122 /* 123 * Search the table looking for a slot... 124 */ 125 for (i = cdevsw_ALLOCSTART; i < nchrdev; i++) 126 if (cdevsw[i] == NULL) 127 break; /* found one! */ 128 /* out of allocable slots? */ 129 if (i >= nchrdev) { 130 return ENFILE; 131 } 132 } else { /* assign */ 133 i = major(*descrip); 134 if (i < 0 || i >= nchrdev) { 135 return EINVAL; 136 } 137 } |
150 | 138 |
139 /* maybe save old */ 140 if (oldentry) { 141 *oldentry = cdevsw[i]; 142 } 143 if (newentry) { 144 newentry->d_bmaj = -1; 145 newentry->d_maj = i; 146 } 147 /* replace with new */ 148 cdevsw[i] = newentry; 149 150 /* done! let them know where we put it */ 151 *descrip = makedev(i,0); 152 return 0; 153} 154 155/* 156 * note must call cdevsw_add before bdevsw_add due to d_bmaj hack. 157 */ |
|
151void | 158void |
152bdevsw_add_generic(int bdev, int cdev, struct bdevsw *bdevsw) | 159cdevsw_add_generic(int bdev, int cdev, struct cdevsw *cdevsw) |
153{ 154 dev_t dev; 155 | 160{ 161 dev_t dev; 162 |
156 cdevsw_make(bdevsw); | |
157 dev = makedev(cdev, 0); | 163 dev = makedev(cdev, 0); |
158 cdevsw_add(&dev, bdevsw->d_cdev, NULL); | 164 cdevsw_add(&dev, cdevsw, NULL); |
159 dev = makedev(bdev, 0); | 165 dev = makedev(bdev, 0); |
160 bdevsw_add(&dev, bdevsw , NULL); | 166 bdevsw_add(&dev, cdevsw, NULL); |
161} 162 163int 164cdevsw_module_handler(module_t mod, modeventtype_t what, void* arg) 165{ 166 struct cdevsw_module_data* data = (struct cdevsw_module_data*) arg; 167 int error; 168 --- 18 unchanged lines hidden (view full) --- 187int 188bdevsw_module_handler(module_t mod, modeventtype_t what, void* arg) 189{ 190 struct bdevsw_module_data* data = (struct bdevsw_module_data*) arg; 191 int error; 192 193 switch (what) { 194 case MOD_LOAD: | 167} 168 169int 170cdevsw_module_handler(module_t mod, modeventtype_t what, void* arg) 171{ 172 struct cdevsw_module_data* data = (struct cdevsw_module_data*) arg; 173 int error; 174 --- 18 unchanged lines hidden (view full) --- 193int 194bdevsw_module_handler(module_t mod, modeventtype_t what, void* arg) 195{ 196 struct bdevsw_module_data* data = (struct bdevsw_module_data*) arg; 197 int error; 198 199 switch (what) { 200 case MOD_LOAD: |
195 cdevsw_make(data->bdevsw); 196 if (error = cdevsw_add(&data->cdev, data->bdevsw->d_cdev, NULL)) | 201 if (error = cdevsw_add(&data->cdev, data->cdevsw, NULL)) |
197 return error; | 202 return error; |
198 if (error = bdevsw_add(&data->bdev, data->bdevsw, NULL)) | 203 if (error = bdevsw_add(&data->bdev, data->cdevsw, NULL)) { 204 cdevsw_add(&data->bdev, NULL, NULL); |
199 return error; | 205 return error; |
206 } |
|
200 break; 201 202 case MOD_UNLOAD: | 207 break; 208 209 case MOD_UNLOAD: |
203 if (error = cdevsw_add(&data->cdev, NULL, NULL)) 204 return error; | |
205 if (error = bdevsw_add(&data->bdev, NULL, NULL)) 206 return error; | 210 if (error = bdevsw_add(&data->bdev, NULL, NULL)) 211 return error; |
212 if (error = cdevsw_add(&data->cdev, NULL, NULL)) 213 return error; |
|
207 break; 208 } 209 210 if (data->chainevh) 211 return data->chainevh(mod, what, data->chainarg); 212 else 213 return 0; 214} | 214 break; 215 } 216 217 if (data->chainevh) 218 return data->chainevh(mod, what, data->chainarg); 219 else 220 return 0; 221} |