1: /* 2: * Copyright (c) 1986 Regents of the University of California. 3: * All rights reserved. The Berkeley software License Agreement 4: * specifies the terms and conditions for redistribution. 5: * 6: * @(#)conf.c 3.2 (2.11BSD GTE) 1997/11/12 7: */ 8: 9: #include "param.h" 10: #include "conf.h" 11: #include "buf.h" 12: #include "time.h" 13: #include "ioctl.h" 14: #include "resource.h" 15: #include "inode.h" 16: #include "proc.h" 17: #include "clist.h" 18: #include "tty.h" 19: 20: int nulldev(); 21: int nodev(); 22: int rawrw(); 23: 24: #include "rk.h" 25: #if NRK > 0 26: int rkopen(), rkstrategy(); 27: daddr_t rksize(); 28: #define rkclose nulldev 29: #else 30: #define rkopen nodev 31: #define rkclose nodev 32: #define rkstrategy nodev 33: #define rksize NULL 34: #endif 35: 36: #include "tm.h" 37: #if NTM > 0 38: int tmopen(), tmclose(), tmioctl(), tmstrategy(); 39: #else 40: #define tmopen nodev 41: #define tmclose nodev 42: #define tmioctl nodev 43: #define tmstrategy nodev 44: #endif 45: 46: #include "hk.h" 47: #if NHK > 0 48: int hkopen(), hkstrategy(), hkroot(), hkclose(); 49: daddr_t hksize(); 50: #else 51: #define hkopen nodev 52: #define hkclose nodev 53: #define hkroot nulldev 54: #define hkstrategy nodev 55: #define hksize NULL 56: #endif 57: 58: #include "xp.h" 59: #if NXPD > 0 60: int xpopen(), xpstrategy(), xproot(), xpclose(), xpioctl(); 61: daddr_t xpsize(); 62: #else 63: #define xpopen nodev 64: #define xpclose nodev 65: #define xpioctl nodev 66: #define xproot nulldev 67: #define xpstrategy nodev 68: #define xpsize NULL 69: #endif 70: 71: #include "br.h" 72: #if NBR > 0 73: int bropen(), brstrategy(), brroot(); 74: daddr_t brsize(); 75: #define brclose nulldev 76: #else 77: #define bropen nodev 78: #define brclose nodev 79: #define brroot nulldev 80: #define brstrategy nodev 81: #define brsize NULL 82: #endif 83: 84: #include "ht.h" 85: #if NHT > 0 86: int htopen(), htclose(), htstrategy(), htioctl(); 87: #else 88: #define htopen nodev 89: #define htclose nodev 90: #define htioctl nodev 91: #define htstrategy nodev 92: #endif 93: 94: #include "rl.h" 95: #if NRL > 0 96: int rlopen(), rlstrategy(), rlroot(), rlclose(), rlioctl(); 97: daddr_t rlsize(); 98: #else 99: #define rlroot nulldev 100: #define rlopen nodev 101: #define rlclose nodev 102: #define rlioctl nodev 103: #define rlstrategy nodev 104: #define rlsize NULL 105: #endif 106: 107: #include "ts.h" 108: #if NTS > 0 109: int tsopen(), tsclose(), tsstrategy(), tsioctl(); 110: #else 111: #define tsopen nodev 112: #define tsclose nodev 113: #define tsioctl nodev 114: #define tsstrategy nodev 115: #endif 116: 117: #include "tms.h" 118: #if NTMS > 0 119: int tmscpopen(), tmscpclose(), tmscpstrategy(), tmscpioctl(); 120: #else 121: #define tmscpopen nodev 122: #define tmscpclose nodev 123: #define tmscpioctl nodev 124: #define tmscpstrategy nodev 125: #endif 126: 127: #include "si.h" 128: #if NSI > 0 129: int siopen(), sistrategy(), siroot(); 130: daddr_t sisize(); 131: #define siclose nulldev 132: #else 133: #define siopen nodev 134: #define siclose nodev 135: #define siroot nulldev 136: #define sistrategy nodev 137: #define sisize NULL 138: #endif 139: 140: #include "ra.h" 141: #if NRAC > 0 142: int rastrategy(), raroot(), raopen(), raclose(), raioctl(); 143: daddr_t rasize(); 144: #else 145: #define raopen nodev 146: #define raclose nodev 147: #define raioctl nodev 148: #define raroot nulldev 149: #define rastrategy nodev 150: #define rasize nodev 151: #endif 152: 153: #include "rx.h" 154: #if NRX > 0 155: int rxopen(), rxstrategy(), rxioctl(); 156: #define rxclose nulldev 157: #else 158: #define rxopen nodev 159: #define rxclose nodev 160: #define rxstrategy nodev 161: #define rxioctl nodev 162: #endif 163: 164: #include "ram.h" 165: #if NRAM > 0 166: int ramopen(), ramstrategy(); 167: #define ramclose nulldev 168: #else 169: #define ramopen nodev 170: #define ramclose nodev 171: #define ramstrategy nodev 172: #endif 173: 174: struct bdevsw bdevsw[] = { 175: /* ht = 0 */ 176: htopen, htclose, htstrategy, nulldev, NULL, 177: B_TAPE, 178: /* tm = 1 */ 179: tmopen, tmclose, tmstrategy, nulldev, NULL, 180: B_TAPE, 181: /* ts = 2 */ 182: tsopen, tsclose, tsstrategy, nulldev, NULL, 183: B_TAPE, 184: /* ram = 3 */ 185: ramopen, ramclose, ramstrategy, nulldev, NULL, 186: 0, 187: /* hk = 4 */ 188: hkopen, hkclose, hkstrategy, hkroot, hksize, 189: 0, 190: /* ra = 5 */ 191: raopen, raclose, rastrategy, raroot, rasize, 192: 0, 193: /* rk = 6 */ 194: rkopen, rkclose, rkstrategy, nulldev, rksize, 195: 0, 196: /* rl = 7 */ 197: rlopen, rlclose, rlstrategy, rlroot, rlsize, 198: 0, 199: /* rx = 8 */ 200: rxopen, rxclose, rxstrategy, nulldev, NULL, 201: 0, 202: /* si = 9 */ 203: siopen, siclose, sistrategy, siroot, sisize, 204: 0, 205: /* xp = 10 */ 206: xpopen, xpclose, xpstrategy, xproot, xpsize, 207: 0, 208: /* br = 11 */ 209: bropen, brclose, brstrategy, brroot, brsize, 210: 0, 211: /* tmscp = 12 (tu81/tk50) */ 212: tmscpopen, tmscpclose, tmscpstrategy, nulldev, NULL, 213: B_TAPE, 214: }; 215: int nblkdev = sizeof(bdevsw) / sizeof(bdevsw[0]); 216: 217: int cnopen(), cnclose(), cnread(), cnwrite(), cnioctl(); 218: extern struct tty cons[]; 219: 220: #include "lp.h" 221: #if NLP > 0 222: int lpopen(), lpclose(), lpwrite(); 223: #else 224: #define lpopen nodev 225: #define lpclose nodev 226: #define lpwrite nodev 227: #endif 228: 229: #include "dh.h" 230: #if NDH > 0 231: int dhopen(), dhclose(), dhread(), dhwrite(), dhioctl(), dhstop(); 232: int dhselect(); 233: extern struct tty dh11[]; 234: #else 235: #define dhopen nodev 236: #define dhclose nodev 237: #define dhread nodev 238: #define dhwrite nodev 239: #define dhioctl nodev 240: #define dhstop nodev 241: #define dhselect nodev 242: #define dh11 ((struct tty *) NULL) 243: #endif 244: 245: #include "dz.h" 246: #if NDZ > 0 247: int dzopen(), dzclose(), dzread(), dzwrite(), dzioctl(); 248: int dzstop(); 249: extern struct tty dz_tty[]; 250: #else 251: #define dzopen nodev 252: #define dzclose nodev 253: #define dzread nodev 254: #define dzwrite nodev 255: #define dzioctl nodev 256: #define dzstop nodev 257: #define dz_tty ((struct tty *) NULL) 258: #endif 259: 260: #include "pty.h" 261: #if NPTY > 0 262: int ptsopen(), ptsclose(), ptsread(), ptswrite(), ptsstop(); 263: int ptcopen(), ptcclose(), ptcread(), ptcwrite(), ptyioctl(); 264: int ptcselect(); 265: extern struct tty pt_tty[]; 266: #else 267: #define ptsopen nodev 268: #define ptsclose nodev 269: #define ptsread nodev 270: #define ptswrite nodev 271: #define ptsstop nodev 272: #define ptcopen nodev 273: #define ptcclose nodev 274: #define ptcread nodev 275: #define ptcwrite nodev 276: #define ptyioctl nodev 277: #define ptcselect nodev 278: #define pt_tty ((struct tty *)NULL) 279: #endif 280: 281: #include "dr.h" 282: #if NDR > 0 283: int dropen(), drclose(), drioctl(), drstrategy(); 284: #else 285: #define dropen nodev 286: #define drclose nodev 287: #define drioctl nodev 288: #define drstrategy nodev 289: #endif 290: 291: #include "dhu.h" 292: #if NDHU > 0 293: int dhuopen(), dhuclose(), dhuread(), dhuwrite(), dhuioctl(), dhustop(); 294: int dhuselect(); 295: extern struct tty dhu_tty[]; 296: #else 297: #define dhuopen nodev 298: #define dhuclose nodev 299: #define dhuread nodev 300: #define dhuwrite nodev 301: #define dhuioctl nodev 302: #define dhustop nodev 303: #define dhuselect nodev 304: #define dhu_tty ((struct tty *) NULL) 305: #endif 306: 307: #include "dhv.h" 308: #if NDHV > 0 309: int dhvopen(), dhvclose(), dhvread(), dhvwrite(), dhvioctl(), dhvstop(); 310: int dhvselect(); 311: extern struct tty dhv_tty[]; 312: #else 313: #define dhvopen nodev 314: #define dhvclose nodev 315: #define dhvread nodev 316: #define dhvwrite nodev 317: #define dhvioctl nodev 318: #define dhvstop nodev 319: #define dhvselect nodev 320: #define dhv_tty ((struct tty *) NULL) 321: #endif 322: 323: #include "dn.h" 324: #if NDN > 0 325: int dnopen(), dnclose(), dnwrite(); 326: #define dnread nodev 327: #define dnioctl nodev 328: #else 329: #define dnopen nodev 330: #define dnclose nodev 331: #define dnread nodev 332: #define dnwrite nodev 333: #define dnioctl nodev 334: #endif 335: 336: int logopen(), logclose(), logread(), logioctl(), logselect(); 337: int syopen(), syread(), sywrite(), syioctl(), syselect(); 338: 339: int mmrw(); 340: #define mmselect seltrue 341: 342: #include "ingres.h" 343: #if NINGRES > 0 344: int ingres_open(), ingres_write(); 345: #define ingres_read nodev 346: #define ingres_ioctl nodev 347: #define ingres_close nulldev 348: #else 349: #define ingres_open nodev 350: #define ingres_close nodev 351: #define ingres_read nodev 352: #define ingres_write nodev 353: #define ingres_ioctl nodev 354: #endif 355: 356: int fdopen(); 357: int ttselect(), seltrue(); 358: 359: struct cdevsw cdevsw[] = { 360: /* cn = 0 */ 361: cnopen, cnclose, cnread, cnwrite, 362: cnioctl, nulldev, cons, ttselect, 363: nulldev, 364: /* mem = 1 */ 365: nulldev, nulldev, mmrw, mmrw, 366: nodev, nulldev, 0, mmselect, 367: nulldev, 368: /* dz = 2 */ 369: dzopen, dzclose, dzread, dzwrite, 370: dzioctl, dzstop, dz_tty, ttselect, 371: nulldev, 372: /* dh = 3 */ 373: dhopen, dhclose, dhread, dhwrite, 374: dhioctl, dhstop, dh11, dhselect, 375: nulldev, 376: /* dhu = 4 */ 377: dhuopen, dhuclose, dhuread, dhuwrite, 378: dhuioctl, dhustop, dhu_tty, dhuselect, 379: nulldev, 380: /* lp = 5 */ 381: lpopen, lpclose, nodev, lpwrite, 382: nodev, nulldev, 0, nodev, 383: nulldev, 384: /* ht = 6 */ 385: htopen, htclose, rawrw, rawrw, 386: htioctl, nulldev, 0, seltrue, 387: htstrategy, 388: /* tm = 7 */ 389: tmopen, tmclose, rawrw, rawrw, 390: tmioctl, nulldev, 0, seltrue, 391: tmstrategy, 392: /* ts = 8 */ 393: tsopen, tsclose, rawrw, rawrw, 394: tsioctl, nulldev, 0, seltrue, 395: tsstrategy, 396: /* tty = 9 */ 397: syopen, nulldev, syread, sywrite, 398: syioctl, nulldev, 0, syselect, 399: nulldev, 400: /* ptc = 10 */ 401: ptcopen, ptcclose, ptcread, ptcwrite, 402: ptyioctl, nulldev, pt_tty, ptcselect, 403: nulldev, 404: /* pts = 11 */ 405: ptsopen, ptsclose, ptsread, ptswrite, 406: ptyioctl, ptsstop, pt_tty, ttselect, 407: nulldev, 408: /* dr = 12 */ 409: dropen, drclose, rawrw, rawrw, 410: drioctl, nulldev, 0, seltrue, 411: drstrategy, 412: /* hk = 13 */ 413: hkopen, hkclose, rawrw, rawrw, 414: nodev, nulldev, 0, seltrue, 415: hkstrategy, 416: /* ra = 14 */ 417: raopen, raclose, rawrw, rawrw, 418: raioctl, nulldev, 0, seltrue, 419: rastrategy, 420: /* rk = 15 */ 421: rkopen, rkclose, rawrw, rawrw, 422: nodev, nulldev, 0, seltrue, 423: rkstrategy, 424: /* rl = 16 */ 425: rlopen, rlclose, rawrw, rawrw, 426: rlioctl, nulldev, 0, seltrue, 427: rlstrategy, 428: /* rx = 17 */ 429: rxopen, rxclose, rawrw, rawrw, 430: rxioctl, nulldev, 0, seltrue, 431: rxstrategy, 432: /* si = 18 */ 433: siopen, siclose, rawrw, rawrw, 434: nodev, nulldev, 0, seltrue, 435: sistrategy, 436: /* xp = 19 */ 437: xpopen, xpclose, rawrw, rawrw, 438: xpioctl, nulldev, 0, seltrue, 439: xpstrategy, 440: /* br = 20 */ 441: bropen, brclose, rawrw, rawrw, 442: nodev, nulldev, 0, seltrue, 443: brstrategy, 444: /* dn = 21 */ 445: dnopen, dnclose, dnread, dnwrite, 446: dnioctl, nulldev, 0, seltrue, 447: nulldev, 448: /* log = 22 */ 449: logopen, logclose, logread, nodev, 450: logioctl, nulldev, 0, logselect, 451: nulldev, 452: /* tmscp = 23 (tu81/tk50) */ 453: tmscpopen, tmscpclose, rawrw, rawrw, 454: tmscpioctl, nulldev, 0, seltrue, 455: tmscpstrategy, 456: /* dhv = 24 */ 457: dhvopen, dhvclose, dhvread, dhvwrite, 458: dhvioctl, dhvstop, dhv_tty, dhvselect, 459: nulldev, 460: /* ingres = 25 */ 461: ingres_open, ingres_close, ingres_read, ingres_write, 462: ingres_ioctl, nulldev, 0, seltrue, 463: nulldev, 464: /* fd = 26 */ 465: fdopen, nodev, nodev, nodev, 466: nodev, nodev, 0, nodev, 467: nodev, 468: }; 469: 470: int nchrdev = sizeof(cdevsw) / sizeof(cdevsw[0]); 471: 472: /* 473: * Routine that identifies /dev/mem and /dev/kmem. 474: * 475: * A minimal stub routine can always return 0. 476: */ 477: iskmemdev(dev) 478: register dev_t dev; 479: { 480: 481: if (major(dev) == 1 && (minor(dev) == 0 || minor(dev) == 1)) 482: return (1); 483: return (0); 484: } 485: 486: /* 487: * Routine to determine if a device is a disk. 488: * 489: * A minimal stub routine can always return 0. 490: */ 491: isdisk(dev, type) 492: dev_t dev; 493: register int type; 494: { 495: 496: switch (major(dev)) { 497: case 3: /* ram */ 498: case 4: /* hk */ 499: case 5: /* ra */ 500: case 6: /* rk */ 501: case 7: /* rl */ 502: case 8: /* rx */ 503: case 9: /* si */ 504: case 10: /* xp */ 505: case 11: /* br */ 506: if (type == IFBLK) 507: return (1); 508: return (0); 509: case 13: /* rhk */ 510: case 14: /* rra */ 511: case 15: /* rrk */ 512: case 16: /* rrl */ 513: case 17: /* rrx */ 514: case 18: /* rsi */ 515: case 19: /* rxp */ 516: case 20: /* rbr */ 517: if (type == IFCHR) 518: return (1); 519: /* fall through */ 520: default: 521: return (0); 522: } 523: /* NOTREACHED */ 524: } 525: 526: #define MAXDEV 27 527: static char chrtoblktbl[MAXDEV] = { 528: /* CHR */ /* BLK */ 529: /* 0 */ NODEV, 530: /* 1 */ NODEV, 531: /* 2 */ NODEV, 532: /* 3 */ NODEV, 533: /* 4 */ NODEV, 534: /* 5 */ NODEV, 535: /* 6 */ 0, /* ht */ 536: /* 7 */ 1, /* tm */ 537: /* 8 */ 2, /* ts */ 538: /* 9 */ NODEV, 539: /* 10 */ NODEV, 540: /* 11 */ NODEV, 541: /* 12 */ NODEV, 542: /* 13 */ 4, /* hk */ 543: /* 14 */ 5, /* ra */ 544: /* 15 */ 6, /* rk */ 545: /* 16 */ 7, /* rl */ 546: /* 17 */ 8, /* rx */ 547: /* 18 */ 9, /* si */ 548: /* 19 */ 10, /* xp */ 549: /* 20 */ 11, /* br */ 550: /* 21 */ NODEV, 551: /* 22 */ NODEV, 552: /* 23 */ 12, /* tmscp */ 553: /* 24 */ NODEV, 554: /* 25 */ NODEV, 555: /* 26 */ NODEV 556: }; 557: 558: /* 559: * Routine to convert from character to block device number. 560: * 561: * A minimal stub routine can always return NODEV. 562: */ 563: chrtoblk(dev) 564: register dev_t dev; 565: { 566: register int blkmaj; 567: 568: if (major(dev) >= MAXDEV || (blkmaj = chrtoblktbl[major(dev)]) == NODEV) 569: return (NODEV); 570: return (makedev(blkmaj, minor(dev))); 571: } 572: 573: /* 574: * This routine returns the cdevsw[] index of the block device 575: * specified by the input parameter. Used by init_main and ufs_mount to 576: * find the diskdriver's ioctl entry point so that the label and partition 577: * information can be obtained for 'block' (instead of 'character') disks. 578: * 579: * Rather than create a whole separate table 'chrtoblktbl' is scanned 580: * looking for a match. This routine is only called a half dozen times during 581: * a system's life so efficiency isn't a big concern. 582: */ 583: 584: blktochr(dev) 585: register dev_t dev; 586: { 587: register int maj = major(dev); 588: register int i; 589: 590: for (i = 0; i < MAXDEV; i++) 591: { 592: if (maj == chrtoblktbl[i]) 593: return(i); 594: } 595: return(NODEV); 596: }