kern_conf.c (60938) | kern_conf.c (64880) |
---|---|
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 * $FreeBSD: head/sys/kern/kern_conf.c 60938 2000-05-26 02:09:24Z jake $ | 33 * $FreeBSD: head/sys/kern/kern_conf.c 64880 2000-08-20 21:34:39Z phk $ |
34 */ 35 36#include <sys/param.h> 37#include <sys/kernel.h> 38#include <sys/sysctl.h> 39#include <sys/systm.h> 40#include <sys/module.h> 41#include <sys/malloc.h> --- 148 unchanged lines hidden (view full) --- 190makebdev(int x, int y) 191{ 192 193 if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) 194 Debugger("makebdev of NOUDEV"); 195 return (makedev(bmaj2cmaj[x], y)); 196} 197 | 34 */ 35 36#include <sys/param.h> 37#include <sys/kernel.h> 38#include <sys/sysctl.h> 39#include <sys/systm.h> 40#include <sys/module.h> 41#include <sys/malloc.h> --- 148 unchanged lines hidden (view full) --- 190makebdev(int x, int y) 191{ 192 193 if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) 194 Debugger("makebdev of NOUDEV"); 195 return (makedev(bmaj2cmaj[x], y)); 196} 197 |
198static dev_t 199allocdev(void) 200{ 201 static int stashed; 202 struct specinfo *si; 203 204 if (stashed >= DEVT_STASH) { 205 MALLOC(si, struct specinfo *, sizeof(*si), M_DEVT, 206 M_USE_RESERVE); 207 bzero(si, sizeof(*si)); 208 } else if (LIST_FIRST(&dev_free)) { 209 si = LIST_FIRST(&dev_free); 210 LIST_REMOVE(si, si_hash); 211 } else { 212 si = devt_stash + stashed++; 213 si->si_flags |= SI_STASHED; 214 } 215 LIST_INIT(&si->si_names); 216 return (si); 217} 218 |
|
198dev_t 199makedev(int x, int y) 200{ 201 struct specinfo *si; 202 udev_t udev; 203 int hash; | 219dev_t 220makedev(int x, int y) 221{ 222 struct specinfo *si; 223 udev_t udev; 224 int hash; |
204 static int stashed; | |
205 206 if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) 207 Debugger("makedev of NOUDEV"); 208 udev = (x << 8) | y; 209 hash = udev % DEVT_HASH; 210 LIST_FOREACH(si, &dev_hash[hash], si_hash) { 211 if (si->si_udev == udev) 212 return (si); 213 } | 225 226 if (x == umajor(NOUDEV) && y == uminor(NOUDEV)) 227 Debugger("makedev of NOUDEV"); 228 udev = (x << 8) | y; 229 hash = udev % DEVT_HASH; 230 LIST_FOREACH(si, &dev_hash[hash], si_hash) { 231 if (si->si_udev == udev) 232 return (si); 233 } |
214 if (stashed >= DEVT_STASH) { 215 MALLOC(si, struct specinfo *, sizeof(*si), M_DEVT, 216 M_USE_RESERVE); 217 bzero(si, sizeof(*si)); 218 } else if (LIST_FIRST(&dev_free)) { 219 si = LIST_FIRST(&dev_free); 220 LIST_REMOVE(si, si_hash); 221 } else { 222 si = devt_stash + stashed++; 223 si->si_flags |= SI_STASHED; 224 } | 234 si = allocdev(); |
225 si->si_udev = udev; 226 LIST_INSERT_HEAD(&dev_hash[hash], si, si_hash); 227 return (si); 228} 229 230void 231freedev(dev_t dev) 232{ | 235 si->si_udev = udev; 236 LIST_INSERT_HEAD(&dev_hash[hash], si, si_hash); 237 return (si); 238} 239 240void 241freedev(dev_t dev) 242{ |
233 int hash; | 243 dev_t adev; |
234 235 if (!free_devt) 236 return; 237 if (SLIST_FIRST(&dev->si_hlist)) 238 return; 239 if (dev->si_devsw || dev->si_drv1 || dev->si_drv2) 240 return; | 244 245 if (!free_devt) 246 return; 247 if (SLIST_FIRST(&dev->si_hlist)) 248 return; 249 if (dev->si_devsw || dev->si_drv1 || dev->si_drv2) 250 return; |
241 hash = dev->si_udev % DEVT_HASH; | 251 while (!LIST_EMPTY(&dev->si_names)) { 252 adev = LIST_FIRST(&dev->si_names); 253 adev->si_drv1 = NULL; 254 freedev(adev); 255 } |
242 LIST_REMOVE(dev, si_hash); 243 if (dev->si_flags & SI_STASHED) { 244 bzero(dev, sizeof(*dev)); 245 LIST_INSERT_HEAD(&dev_free, dev, si_hash); 246 } else { 247 FREE(dev, M_DEVT); 248 } 249} --- 49 unchanged lines hidden (view full) --- 299 int i; 300 301 dev = makedev(devsw->d_maj, minor); 302 va_start(ap, fmt); 303 i = kvprintf(fmt, NULL, dev->si_name, 32, ap); 304 dev->si_name[i] = '\0'; 305 va_end(ap); 306 dev->si_devsw = devsw; | 256 LIST_REMOVE(dev, si_hash); 257 if (dev->si_flags & SI_STASHED) { 258 bzero(dev, sizeof(*dev)); 259 LIST_INSERT_HEAD(&dev_free, dev, si_hash); 260 } else { 261 FREE(dev, M_DEVT); 262 } 263} --- 49 unchanged lines hidden (view full) --- 313 int i; 314 315 dev = makedev(devsw->d_maj, minor); 316 va_start(ap, fmt); 317 i = kvprintf(fmt, NULL, dev->si_name, 32, ap); 318 dev->si_name[i] = '\0'; 319 va_end(ap); 320 dev->si_devsw = devsw; |
321 dev->si_uid = uid; 322 dev->si_gid = gid; 323 dev->si_mode = perms; |
|
307 308 if (devfs_create_hook) | 324 325 if (devfs_create_hook) |
309 devfs_create_hook(dev, uid, gid, perms); | 326 devfs_create_hook(dev); |
310 return (dev); 311} 312 | 327 return (dev); 328} 329 |
330dev_t 331make_dev_alias(dev_t pdev, char *fmt, ...) 332{ 333 dev_t dev; 334 va_list ap; 335 int i; 336 337 dev = allocdev(); 338 dev->si_flags |= SI_ALIAS; 339 dev->si_drv1 = pdev; 340 LIST_INSERT_HEAD(&pdev->si_names, dev, si_hash); 341 342 va_start(ap, fmt); 343 i = kvprintf(fmt, NULL, dev->si_name, 32, ap); 344 dev->si_name[i] = '\0'; 345 va_end(ap); 346 347 if (devfs_create_hook) 348 devfs_create_hook(dev); 349 return (dev); 350} 351 |
|
313void 314destroy_dev(dev_t dev) 315{ 316 if (devfs_remove_hook) 317 devfs_remove_hook(dev); 318 dev->si_drv1 = 0; 319 dev->si_drv2 = 0; 320 dev->si_devsw = 0; --- 24 unchanged lines hidden --- | 352void 353destroy_dev(dev_t dev) 354{ 355 if (devfs_remove_hook) 356 devfs_remove_hook(dev); 357 dev->si_drv1 = 0; 358 dev->si_drv2 = 0; 359 dev->si_devsw = 0; --- 24 unchanged lines hidden --- |