kern_conf.c revision 12520
155682Smarkm/*- 2233294Sstas * Parts Copyright (c) 1995 Terrence R. Lambert 3233294Sstas * Copyright (c) 1995 Julian R. Elischer 4233294Sstas * All rights reserved. 555682Smarkm * 6233294Sstas * Redistribution and use in source and binary forms, with or without 7233294Sstas * modification, are permitted provided that the following conditions 8233294Sstas * are met: 955682Smarkm * 1. Redistributions of source code must retain the above copyright 10233294Sstas * notice, this list of conditions and the following disclaimer. 11233294Sstas * 2. Redistributions in binary form must reproduce the above copyright 1255682Smarkm * notice, this list of conditions and the following disclaimer in the 13233294Sstas * documentation and/or other materials provided with the distribution. 14233294Sstas * 3. All advertising materials mentioning features or use of this software 15233294Sstas * must display the following acknowledgement: 1655682Smarkm * This product includes software developed by Terrence R. Lambert. 17233294Sstas * 4. The name Terrence R. Lambert may not be used to endorse or promote 18233294Sstas * products derived from this software without specific prior written 19233294Sstas * permission. 2055682Smarkm * 21233294Sstas * THIS SOFTWARE IS PROVIDED BY Julian R. Elischer ``AS IS'' AND ANY 22233294Sstas * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23233294Sstas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24233294Sstas * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE 25233294Sstas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26233294Sstas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27233294Sstas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28233294Sstas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29233294Sstas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30233294Sstas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31233294Sstas * SUCH DAMAGE. 3255682Smarkm * 3355682Smarkm * $Id: kern_conf.c,v 1.3 1995/10/04 08:58:00 julian Exp $ 3455682Smarkm */ 3555682Smarkm 3655682Smarkm#include <sys/param.h> 3755682Smarkm#include <sys/types.h> 38233294Sstas#include <sys/systm.h> 3955682Smarkm#include <sys/conf.h> 4055682Smarkm 4155682Smarkm/* 4255682Smarkm * (re)place an entry in the bdevsw or cdevsw table 43233294Sstas * return the slot used in major(*descrip) 4455682Smarkm */ 45233294Sstas#define ADDENTRY(TTYPE,NXXXDEV) \ 4655682Smarkmint TTYPE##_add(dev_t *descrip, \ 4755682Smarkm struct TTYPE *newentry, \ 48178825Sdfr struct TTYPE *oldentry) \ 4955682Smarkm{ \ 5055682Smarkm int i ; \ 5155682Smarkm if ( (int)*descrip == -1) { /* auto (0 is valid) */ \ 5255682Smarkm /* \ 5355682Smarkm * Search the table looking for a slot... \ 54233294Sstas */ \ 55233294Sstas for (i = 0; i < NXXXDEV; i++) \ 5655682Smarkm if (TTYPE[i].d_open == NULL) \ 57233294Sstas break; /* found one! */ \ 5855682Smarkm /* out of allocable slots? */ \ 59233294Sstas if (i == NXXXDEV) { \ 60233294Sstas return ENFILE; \ 6155682Smarkm } \ 6255682Smarkm } else { /* assign */ \ 6355682Smarkm i = major(descrip); \ 6455682Smarkm if (i < 0 || i >= NXXXDEV) { \ 6555682Smarkm return EINVAL; \ 6655682Smarkm } \ 6755682Smarkm } \ 6855682Smarkm \ 6955682Smarkm /* maybe save old */ \ 7055682Smarkm if (oldentry) { \ 71233294Sstas bcopy(&TTYPE[i], oldentry, sizeof(struct TTYPE)); \ 7255682Smarkm } \ 7355682Smarkm /* replace with new */ \ 74233294Sstas bcopy(newentry, &TTYPE[i], sizeof(struct TTYPE)); \ 75233294Sstas \ 76233294Sstas /* done! */ \ 77233294Sstas *descrip = makedev(i,0); \ 7855682Smarkm return 0; \ 79233294Sstas} \ 8055682Smarkm 8155682SmarkmADDENTRY(bdevsw, nblkdev) 82233294SstasADDENTRY(cdevsw, nchrdev) 8355682Smarkm