kern_conf.c revision 12968
1189251Ssam/*- 2189251Ssam * Parts Copyright (c) 1995 Terrence R. Lambert 3189251Ssam * Copyright (c) 1995 Julian R. Elischer 4189251Ssam * All rights reserved. 5252726Srpaulo * 6252726Srpaulo * Redistribution and use in source and binary forms, with or without 7189251Ssam * modification, are permitted provided that the following conditions 8189251Ssam * are met: 9189251Ssam * 1. Redistributions of source code must retain the above copyright 10189251Ssam * notice, this list of conditions and the following disclaimer. 11189251Ssam * 2. Redistributions in binary form must reproduce the above copyright 12189251Ssam * notice, this list of conditions and the following disclaimer in the 13214734Srpaulo * documentation and/or other materials provided with the distribution. 14214734Srpaulo * 3. All advertising materials mentioning features or use of this software 15214734Srpaulo * must display the following acknowledgement: 16189251Ssam * This product includes software developed by Terrence R. Lambert. 17189251Ssam * 4. The name Terrence R. Lambert may not be used to endorse or promote 18189251Ssam * products derived from this software without specific prior written 19189251Ssam * permission. 20189251Ssam * 21189251Ssam * THIS SOFTWARE IS PROVIDED BY Julian R. Elischer ``AS IS'' AND ANY 22189251Ssam * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23189251Ssam * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24189251Ssam * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE 25189251Ssam * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26189251Ssam * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27189251Ssam * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28189251Ssam * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29189251Ssam * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30189251Ssam * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31189251Ssam * SUCH DAMAGE. 32189251Ssam * 33189251Ssam * $Id: kern_conf.c,v 1.8 1995/12/21 20:09:39 julian Exp $ 34189251Ssam */ 35189251Ssam 36189251Ssam#include <sys/param.h> 37189251Ssam#include <sys/types.h> 38189251Ssam#include <sys/systm.h> 39189251Ssam#include <sys/conf.h> 40189251Ssam#include <sys/vnode.h> 41189251Ssam 42189251Ssam#define NUMCDEV 96 43189251Ssam#define NUMBDEV 32 44189251Ssam 45189251Ssamstruct bdevsw *bdevsw[NUMBDEV]; 46189251Ssamint nblkdev = NUMBDEV; 47189251Ssamstruct cdevsw *cdevsw[NUMCDEV]; 48189251Ssamint nchrdev = NUMCDEV; 49189251Ssam 50189251Ssam 51189251Ssam 52189251Ssam/* 53189251Ssam * Routine to determine if a device is a disk. 54189251Ssam * 55189251Ssam * KLUDGE XXX add flags to cdevsw entries for disks XXX 56189251Ssam * A minimal stub routine can always return 0. 57189251Ssam */ 58189251Ssamint 59189251Ssamisdisk(dev, type) 60189251Ssam dev_t dev; 61189251Ssam int type; 62189251Ssam{ 63189251Ssam 64189251Ssam switch (major(dev)) { 65189251Ssam case 15: /* VBLK: vn, VCHR: cd */ 66189251Ssam return (1); 67189251Ssam case 0: /* wd */ 68189251Ssam case 2: /* fd */ 69189251Ssam case 4: /* sd */ 70189251Ssam case 6: /* cd */ 71189251Ssam case 7: /* mcd */ 72189251Ssam case 16: /* scd */ 73189251Ssam case 17: /* matcd */ 74189251Ssam case 18: /* ata */ 75189251Ssam case 19: /* wcd */ 76189251Ssam case 20: /* od */ 77189251Ssam if (type == VBLK) 78189251Ssam return (1); 79189251Ssam return (0); 80189251Ssam case 3: /* wd */ 81189251Ssam case 9: /* fd */ 82189251Ssam case 13: /* sd */ 83189251Ssam case 29: /* mcd */ 84189251Ssam case 43: /* vn */ 85189251Ssam case 45: /* scd */ 86189251Ssam case 46: /* matcd */ 87189251Ssam case 69: /* wcd */ 88189251Ssam case 70: /* od */ 89189251Ssam if (type == VCHR) 90189251Ssam return (1); 91189251Ssam /* fall through */ 92189251Ssam default: 93189251Ssam return (0); 94189251Ssam } 95189251Ssam /* NOTREACHED */ 96189251Ssam} 97189251Ssam 98189251Ssam 99189251Ssam/* 100189251Ssam * Routine to convert from character to block device number. 101189251Ssam * 102189251Ssam * A minimal stub routine can always return NODEV. 103189251Ssam */ 104189251Ssamdev_t 105189251Ssamchrtoblk(dev_t dev) 106189251Ssam{ 107189251Ssam struct bdevsw *bd; 108189251Ssam struct cdevsw *cd; 109189251Ssam 110189251Ssam if(cd = cdevsw[major(dev)]) { 111189251Ssam if ( (bd = cd->d_bdev) ) 112189251Ssam return(makedev(bd->d_maj,minor(dev))); 113189251Ssam } 114189251Ssam return(NODEV); 115189251Ssam} 116189251Ssam 117189251Ssam/* 118189251Ssam * (re)place an entry in the bdevsw or cdevsw table 119189251Ssam * return the slot used in major(*descrip) 120189251Ssam */ 121189251Ssam#define ADDENTRY(TTYPE,NXXXDEV) \ 122189251Ssamint TTYPE##_add(dev_t *descrip, \ 123189251Ssam struct TTYPE *newentry, \ 124189251Ssam struct TTYPE **oldentry) \ 125189251Ssam{ \ 126189251Ssam int i ; \ 127189251Ssam if ( (int)*descrip == -1) { /* auto (0 is valid) */ \ 128189251Ssam /* \ 129189251Ssam * Search the table looking for a slot... \ 130189251Ssam */ \ 131189251Ssam for (i = 0; i < NXXXDEV; i++) \ 132189251Ssam if (TTYPE[i] == NULL) \ 133189251Ssam break; /* found one! */ \ 134189251Ssam /* out of allocable slots? */ \ 135189251Ssam if (i == NXXXDEV) { \ 136189251Ssam return ENFILE; \ 137189251Ssam } \ 138189251Ssam } else { /* assign */ \ 139189251Ssam i = major(*descrip); \ 140189251Ssam if (i < 0 || i >= NXXXDEV) { \ 141189251Ssam return EINVAL; \ 142189251Ssam } \ 143189251Ssam } \ 144189251Ssam \ 145189251Ssam /* maybe save old */ \ 146189251Ssam if (oldentry) { \ 147189251Ssam *oldentry = TTYPE[i]; \ 148189251Ssam } \ 149189251Ssam newentry->d_maj = i; \ 150189251Ssam /* replace with new */ \ 151189251Ssam TTYPE[i] = newentry; \ 152189251Ssam \ 153189251Ssam /* done! let them know where we put it */ \ 154189251Ssam *descrip = makedev(i,0); \ 155189251Ssam return 0; \ 156189251Ssam} \ 157189251Ssam 158189251SsamADDENTRY(bdevsw, nblkdev) 159189251SsamADDENTRY(cdevsw, nchrdev) 160189251Ssam