1 #!/bin/sh - 2 # $NetBSD: MAKEDEV.tmpl,v 1.109 2008/07/13 15:22:39 apb Exp $ 3 # 4 # Copyright (c) 2003,2007,2008 The NetBSD Foundation, Inc. 5 # All rights reserved. 6 # 7 # Redistribution and use in source and binary forms, with or without 8 # modification, are permitted provided that the following conditions 9 # are met: 10 # 1. Redistributions of source code must retain the above copyright 11 # notice, this list of conditions and the following disclaimer. 12 # 2. Redistributions in binary form must reproduce the above copyright 13 # notice, this list of conditions and the following disclaimer in the 14 # documentation and/or other materials provided with the distribution. 15 # 16 # THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 17 # ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 18 # TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 19 # PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 20 # BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 21 # CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 22 # SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 23 # INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 24 # CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 25 # ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 26 # POSSIBILITY OF SUCH DAMAGE. 27 # 28 # 29 ########################################################################### 30 # 31 # PLEASE RUN "cd ../share/man/man8 ; make makedevs" 32 # AFTER CHANGING THIS FILE, AND COMMIT THE UPDATED MANPAGE! 33 # 34 ########################################################################### 35 # 36 # Device "make" file. Valid special arguments: 37 # all makes all known devices, including local devices. 38 # Tries to make the 'standard' number of each type. 39 # init A set of devices that is used for MFS /dev by init. 40 # May be equal to "all". 41 # floppy devices to be put on install floppies 42 # ramdisk devices to be put into INSTALL kernel ramdisks. 43 # std standard devices 44 # local configuration specific devices 45 # wscons make wscons devices 46 # usbs make USB devices 47 # isdns make ISDN devices 48 # 49 # Tapes: 50 # st* SCSI tapes 51 # wt* QIC-interfaced (e.g. not SCSI) 3M cartridge tape 52 # ht* MASSBUS TM03 and TU?? 53 # mt* MSCP tapes (e.g. TU81, TK50) 54 # tm* UNIBUS TM11 and TE10 emulations (e.g. Emulex TC-11) 55 # ts* UNIBUS TS11 56 # ut* UNIBUS TU45 emulations (e.g. si 9700) 57 # uu* TU58 cassettes on DL11 controller 58 # 59 # Disks: 60 # ccd* concatenated disk devices 61 # cd* SCSI or ATAPI CD-ROM 62 # cgd* cryptographic disk devices 63 # raid* RAIDframe disk devices 64 # sd* SCSI disks 65 # wd* "winchester" disk drives (ST506,IDE,ESDI,RLL,...) 66 # bmd* Nereid bank memory disks 67 # ed* IBM PS/2 ESDI disk devices 68 # fd* "floppy" disk drives (3 1/2", 5 1/4") 69 # fss* Files system snapshot devices 70 # gdrom* Dreamcast "gigadisc" CD-ROM drive 71 # hk* UNIBUS RK06 and RK07 72 # hp* MASSBUS RM?? 73 # ld* Logical disk devices (e.g., hardware RAID) 74 # mcd* Mitsumi CD-ROM 75 # md* memory pseudo-disk devices 76 # ofdisk* OpenFirmware disk devices 77 # ra* MSCP disks (RA??, RD??) 78 # rb* 730 IDC w/ RB80 and/or RB02 79 # rd* HDC9224 RD disks on VS2000 80 # rl* UNIBUS RL02 81 # rx* MSCP floppy disk (RX33/50/...) 82 # up* other UNIBUS devices (e.g. on Emulex SC-21V controller) 83 # vnd* "file" pseudo-disks 84 # xbd* Xen virtual disks 85 # xd* Xylogic 753/7053 disks 86 # xy* Xylogic 450/451 disks 87 # 88 # Pointing devices: 89 # wsmouse* wscons mouse events 90 # lms* Logitech bus mouse 91 # mms* Microsoft bus mouse 92 # qms* "quadrature mouse" 93 # pms* PS/2 mouse 94 # mouse mouse (provides events, for X11) 95 # 96 # Keyboard devices: 97 # wskbd* wscons keyboard events 98 # kbd raw keyboard (provides events, for X11) 99 # kbdctl keyboard control 100 # 101 # Terminals/Console ports: 102 # tty[01]* standard serial ports 103 # tty0* SB1250 ("sbscn") serial ports (sbmips) 104 # ttyE* wscons - Workstation console ("wscons") glass-tty emulators 105 # ttyCZ? Cyclades-Z multiport serial boards. Each "unit" 106 # makes 64 ports. 107 # ttyCY? Cyclom-Y multiport serial boards. Each "unit" makes 108 # 32 ports. 109 # ttye* ITE bitmapped consoles 110 # ttyv0 pccons 111 # ttyC? NS16550 ("com") serial ports 112 # ttyS* SA1110 serial port (hpcarm) 113 # ttyTX? TX39 internal serial ports (hpcmips) 114 # ttyB? DEC 3000 ZS8530 ("scc") serial ports (alpha) 115 # ttyA* mfc serial ports (amiga) 116 # ttyB* msc serial ports (amiga) 117 # ttyC* com style serial ports (DraCo, HyperCom) (amiga) 118 # On the DraCo, units 0 and 1 are the built-in "modem" and 119 # "mouse" ports, if configured. 120 # ttyA0 8530 Channel A (formerly ser02) (atari) 121 # ttyA1 8530 Channel B (formerly mdm02) (atari) 122 # ttyB0 UART on first 68901 (formerly mdm01) (atari) 123 # ixpcom IXP12x0 COM ports 124 # epcom EP93xx COM ports 125 # ttyM? HP200/300 4 port serial mux interface (hp300) 126 # ttya "ttya" system console (luna68k) 127 # ttyb second system serial port (luna68k) 128 # tty* Onboard serial ports (mvme68k) 129 # On the mvme147 these are: ttyZ1, ttyZ2 and ttyZ3. 130 # On the mvme167, and '177: ttyC1, ttyC2 and ttyC3. 131 # Note that tty[CZ]0 is grabbed by the console device 132 # so is not created by default 133 # dc* PMAX 4 channel serial interface (kbd, mouse, modem, printer) 134 # scc* 82530 serial interface (pmax) 135 # ttyZ* Zilog 8530 ("zstty") serial ports 136 # tty[abcd] Built-in serial ports (sparc) 137 # tty* Z88530 serial controllers (sparc64) 138 # ttyh* SAB82532 serial controllers (sparc64) 139 # tty[a-j] Built-in serial ports (sun2, sun3) 140 # ttyC? pccons (arc) 141 # dz* UNIBUS DZ11 and DZ32 (vax) 142 # dh* UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11) (vax) 143 # dmf* UNIBUS DMF32 (vax) 144 # dhu* UNIBUS DHU11 (vax) 145 # dmz* UNIBUS DMZ32 (vax) 146 # dl* UNIBUS DL11 (vax) 147 # xencons Xen virtual console 148 # 149 # Terminal multiplexors: 150 # dc* 4 channel serial interface (keyboard, mouse, modem, printer) 151 # dh* UNIBUS DH11 and emulations (e.g. Able DMAX, Emulex CS-11) 152 # dhu* UNIBUS DHU11 153 # dl* UNIBUS DL11 154 # dmf* UNIBUS DMF32 155 # dmz* UNIBUS DMZ32 156 # dz* UNIBUS DZ11 and DZ32 157 # scc* 82530 serial interface 158 # 159 # Call units: 160 # dn* UNIBUS DN11 and emulations (e.g. Able Quadracall) 161 # 162 # Pseudo terminals: 163 # ptm pty multiplexor device, and pts directory 164 # pty* set of 16 master and slave pseudo terminals 165 # opty first 16 ptys, to save inodes on install media 166 # ipty first 2 ptys, for install media use only 167 # 168 # Printers: 169 # arcpp* Archimedes parallel port 170 # lpt* stock lp 171 # lpa* interruptless lp 172 # par* Amiga motherboard parallel port 173 # cpi* Macintosh Nubus CSI parallel printer card 174 # 175 # USB devices: 176 # usb* USB control devices 177 # uhid* USB generic HID devices 178 # ulpt* USB printer devices 179 # ugen* USB generic devices 180 # urio* USB Diamond Rio 500 devices 181 # uscanner* USB scanners 182 # ttyU* USB modems 183 # ttyY* USB serial adapters 184 # 185 # ISDN devices: 186 # isdn communication between userland isdnd and kernel 187 # isdnctl control device 188 # isdnbchan* raw b-channel access 189 # isdntel* telephony device 190 # isdnteld* telephony dialout device 191 # isdntrc* trace device 192 # 193 # Video devices: 194 # bwtwo* monochromatic frame buffer 195 # cgtwo* 8-bit color frame buffer 196 # cgthree* 8-bit color frame buffer 197 # cgfour* 8-bit color frame buffer 198 # cgsix* accelerated 8-bit color frame buffer 199 # cgeight* 24-bit color frame buffer 200 # etvme Tseng et-compatible cards on VME (atari) 201 # ik* UNIBUS interface to Ikonas frame buffer 202 # leo Circad Leonardo VME-bus true color (atari) 203 # ps* UNIBUS interface to Picture System 2 204 # qv* QVSS (MicroVAX) display 205 # tcx* accelerated 8/24-bit color frame buffer 206 # 207 # Maple bus devices: 208 # maple Maple bus control devices 209 # mlcd* Maple bus LCD devices 210 # mmem* Maple bus storage devices 211 # 212 # IEEE1394 bus devices: 213 # fw* IEEE1394 bus generic node access devices 214 # fwmem* IEEE1394 bus physical memory of the remote node access devices 215 # 216 # Special purpose devices: 217 # ad* UNIBUS interface to Data Translation A/D converter 218 # agp* AGP GART devices 219 # altq ALTQ control interface 220 # amr* AMI MegaRaid control device 221 # apm power management device 222 # audio* audio devices 223 # bell* OPM bell device (x68k) 224 # bktr Brooktree 848/849/878/879 based TV cards 225 # bpf packet filter 226 # bthub Bluetooth Device Hub control interface 227 # cfs* Coda file system device 228 # ch* SCSI media changer 229 # cir* Consumer IR 230 # clockctl clock control for non root users 231 # cpuctl CPU control 232 # crypto hardware crypto access driver 233 # dmoverio hardware-assisted data movers 234 # dpt* DPT/Adaptec EATA RAID management interface 235 # dpti* DPT/Adaptec I2O RAID management interface 236 # fb* PMAX generic framebuffer pseudo-device 237 # fd file descriptors 238 # grf* graphics frame buffer device 239 # hil HP300 HIL input devices 240 # icp ICP-Vortex/Intel RAID control interface 241 # iic* IIC bus device 242 # io x86 IOPL access for COMPAT_10, COMPAT_FREEBSD 243 # iop* I2O IOP control interface 244 # ipl IP Filter 245 # irframe* IrDA physical frame 246 # ite* terminal emulator interface to HP300 graphics devices 247 # joy* joystick device 248 # kttcp kernel ttcp helper device 249 # lkm loadable kernel modules interface 250 # lockstat kernel locking statistics 251 # magma* Magma multiport serial/parallel cards 252 # midi* MIDI 253 # mlx* Mylex DAC960 control interface 254 # mly* Mylex AcceleRAID/eXtremeRAID control interface 255 # np* UNIBUS Ethernet co-processor interface, for downloading. 256 # nsmb* SMB requester 257 # openfirm OpenFirmware accessor 258 # pad* Pseudo-audio device driver 259 # pci* PCI bus access devices 260 # pf PF packet filter 261 # pow* power management device (x68k) 262 # putter Pass-to-Userspace Transporter 263 # px* PixelStamp Xserver access 264 # radio* radio devices 265 # random Random number generator 266 # rtc* RealTimeClock 267 # satlink* PlanetConnect satellite receiver driver 268 # scsibus* SCSI busses 269 # se* SCSI Ethernet 270 # ses* SES/SAF-TE SCSI Devices 271 # speaker PC speaker (XXX - installed) 272 # sram battery backuped memory (x68k) 273 # ss* SCSI scanner 274 # stic* PixelStamp interface chip 275 # sysmon System Monitoring hardware 276 # tap* virtual Ethernet device 277 # tun* network tunnel driver 278 # twa 3ware Apache control interface 279 # twe 3ware Escalade control interface 280 # uk* unknown SCSI device 281 # veriexec verified executable fingerprint loader 282 # vmegen* generic VME access 283 # view* generic interface to graphic displays (Amiga) 284 # wsfont* console font control 285 # wsmux* wscons event multiplexor 286 # xenevt Xen event interface 287 288 289 # 290 # Apart from a few lines right at the end, this file should consist 291 # entirely of function definitions. 292 # 293 # This file is used both as a standalone script (via "sh ./MAKEDEV all" 294 # or similar), and as a function library (via "MAKEDEV_AS_LIBRARY=1 . 295 # MAKEDEV" from MAKEDEV.local). 296 # 297 298 usage() 299 { 300 cat 1>&2 << _USAGE_ 301 Usage: ${0##*/} [-fMs] [-m mknod] [-p pax] [-t mtree] special [...] 302 Create listed special devices. Options: 303 -f Force permissions to be updated on existing devices. 304 -M Create memory file system. 305 -m mknod Name of mknod(8) program. [\$TOOL_MKNOD or mknod] 306 -p pax Name of pax(1) program. [\$TOOL_PAX or pax] 307 -s Generate mtree(8) specfile instead of creating devices. 308 -t mtree Name of mtree(8) program. [\$TOOL_MTREE or mtree] 309 310 _USAGE_ 311 exit 1 312 } 313 314 # zeropad width number 315 # display number with a zero (`0') padding of width digits. 316 # 317 zeropad() 318 { 319 case $(($1 - ${#2})) in 320 5) echo 00000$2;; 321 4) echo 0000$2;; 322 3) echo 000$2;; 323 2) echo 00$2;; 324 1) echo 0$2;; 325 0) echo $2;; 326 *) die "bad padding" ;; 327 esac 328 } 329 330 # hexprint number 331 # display (base10) number as hexadecimal 332 # 333 hexprint() 334 { 335 val="$(($1 + 0))" 336 hex= 337 set -- 0 1 2 3 4 5 6 7 8 9 a b c d e f 338 while [ "$val" -gt 0 ]; do 339 eval hex=\$$(($val % 16 + 1))\$hex 340 val="$(($val / 16))" 341 done 342 echo "${hex:-0}" 343 } 344 345 # linecount multiline_string 346 # count the number of lines in the string 347 # 348 linecount() 349 { 350 local IFS=' 351 ' # just a newline, no other white space between the quotes 352 set -- $1 353 echo $# 354 } 355 356 # nooutput -12 cmd [args...] 357 # run a command with stdout and/or stderr ignored. 358 # "nooutput -1 cmd" is like "cmd >/dev/null"; 359 # "nooutput -2 cmd" is like "{ cmd ; } 2>/dev/null"; 360 # "nooutput -12 cmd" is like "{ cmd ; } >/dev/null 2>&1"; 361 # except they should work even if /dev/null doesn't [yet] exist. 362 # 363 # The "{...}" wrapper used in cases where stderr is redirected 364 # serves to capture shell error messages such as "cmd: not found". 365 # 366 nooutput() 367 { 368 local flags="$1" ; shift 369 local junk 370 case "$flags" in 371 "-1") junk="$( "$@" )" ;; 372 "-2") exec 4>&1 ; junk="$( { "$@" ; } 2>&1 1>&4 )" ; exec 4>&- ;; 373 "-12") junk="$( { "$@" ; } 2>&1 )" ;; 374 *) warn "Incorrect use of nooutput" ;; 375 esac 376 } 377 378 # check_pax path_to_pax 379 # Check whether pax exists and supports the command line options 380 # and input format that we will want to use. 381 # 382 check_pax() 383 { 384 local pax="$1" 385 echo ". type=dir optional" | nooutput -12 "${pax}" -r -w -M -pe . 386 } 387 388 # check_mtree path_to_mtree 389 # Check whether mtree exists and supports the command line options 390 # and input format that we will want to use. 391 # 392 check_mtree() 393 { 394 local mtree="$1" 395 echo ". type=dir optional" | nooutput -12 "${mtree}" -e -U 396 } 397 398 # setup args... 399 # Parse command line arguments, exit on error. 400 # Callers should shift $((OPTIND - 1)) afterwards. 401 # 402 setup() 403 { 404 PATH=/sbin:/usr/sbin:/bin:/usr/bin:/rescue 405 406 : ${TOOL_MKNOD:=mknod} 407 : ${TOOL_MTREE:=mtree} 408 : ${TOOL_PAX:=pax} 409 do_create_mfs=false 410 do_force=false 411 do_mknod=false 412 do_pax=false 413 do_mtree=false 414 do_redirect=false 415 do_specfile=false 416 opts= 417 while getopts Mfm:p:st: ch; do 418 # Note that $opts is only for options pased through to 419 # MAKEDEV.local, not for all options. 420 case ${ch} in 421 M) 422 # "-M" sets do_create_mfs; 423 # "-M -M" is for use from init(8), and sets do_redirect 424 do_redirect=$do_create_mfs 425 do_create_mfs=true 426 ;; 427 f) do_force=true 428 opts="${opts} -f" 429 ;; 430 m) TOOL_MKNOD=${OPTARG} 431 do_mknod=true 432 opts="${opts} -m ${OPTARG}" 433 ;; 434 p) TOOL_PAX="${OPTARG}" 435 if check_pax "${TOOL_PAX}"; then 436 do_pax=true 437 # do not add this to $opts; we will later 438 # add "-s" instead. 439 else 440 warn "Ignored -p option:" \ 441 "${TOOL_PAX} is missing or broken" 442 do_mknod=true 443 fi 444 ;; 445 s) do_specfile=true 446 opts="${opts} -s" 447 ;; 448 t) TOOL_MTREE="${OPTARG}" 449 if check_mtree "${TOOL_MTREE}"; then 450 do_mtree=true 451 # do not add this to $opts; we will later 452 # add "-s" instead. 453 else 454 warn "Ignored -t option:" \ 455 "${TOOL_MTREE} is missing or broken" 456 do_mknod=true 457 fi 458 ;; 459 *) usage ;; 460 esac 461 done 462 463 shift $((${OPTIND} - 1)) 464 [ $# -gt 0 ] || usage 465 466 u_root="%uid_root%" 467 u_uucp="%uid_uucp%" 468 g_kmem="%gid_kmem%" 469 g_ntpd="%gid_ntpd%" 470 g_operator="%gid_operator%" 471 g_wheel="%gid_wheel%" 472 dialin=0 473 dialout=524288 474 callunit=262144 475 476 # only allow read&write for owner by default 477 umask 077 478 479 # Check if we have fdesc mounted 480 if [ -d fd ]; then 481 case "$(df fd)" in 482 *fdesc*) nofdesc=false;; 483 *) nofdesc=true;; 484 esac 485 else 486 nofdesc=true 487 fi 488 489 # do_force requires mknod 490 if $do_force; then 491 if $do_mtree || $do_pax || $do_specfile; then 492 die "-f option works only with mknod" 493 fi 494 do_mknod=true 495 fi 496 497 # If no explicit method was specified on the command line or 498 # forced above, then use one of mtree, pax, or mknod, in that 499 # order of preference. 500 # 501 # mtree is preferred because it's fast and designed for the 502 # purpose. However, it's unlikely to be available early in the 503 # boot sequence, when init(8) may invoke MAKEDEV(8). 504 # 505 # pax is usually acceptable, and it's likely to be available 506 # early in the boot sequence. However, it's much slower than mtree. 507 # 508 # mknod is just very slow, because the shell has to fork for 509 # each device node. 510 # 511 if ! ( $do_mtree || $do_pax || $do_mknod || $do_specfile ); then 512 if check_mtree "${TOOL_MTREE}"; then 513 do_mtree=true 514 elif check_pax "${TOOL_PAX}"; then 515 do_pax=true 516 else 517 do_mknod=true 518 fi 519 fi 520 521 # Now we need exactly one node-creation method. 522 case $(( $($do_mtree && echo 1 || echo 0) + \ 523 $($do_pax && echo 1 || echo 0) + \ 524 $($do_mknod && echo 1 || echo 0) + \ 525 $($do_specfile && echo 1 || echo 0) )) 526 in 527 1) : OK ;; 528 *) die "-m, -p, -s, and -t options are mutually exclusive" ;; 529 esac 530 531 # If we are using mknod, then decide what options to pass it. 532 if $do_mknod; then 533 MKNOD="${TOOL_MKNOD:-mknod} -F netbsd" 534 if $do_force; then 535 MKNOD="${MKNOD} -R" 536 else 537 MKNOD="${MKNOD} -r" 538 fi 539 fi 540 541 # do_mtree or do_pax internally implies do_specfile. 542 # This happens after checking for mutually-exclusive options. 543 if ($do_mtree || $do_pax) && ! $do_specfile; then 544 do_specfile=true 545 opts="${opts} -s" 546 fi 547 } 548 549 # wrap_makedev makedev_name ... 550 # Invoke a makedev-like function, with additional processing 551 # as appropriate for use from the outer level. 552 # 553 wrap_makedev() 554 { 555 if $do_specfile; then 556 # "." must appear as the first line of the specfile. 557 # "optional" means do not create the directory itself. 558 echo ". type=dir optional" 559 fi 560 "$@" 561 } 562 563 # makedev_main makedev_name args... 564 # Perform most of the work of the main program. makedev_name 565 # is typically "makedev", but may be the name of some other 566 # makedev-like function (if we are invoked from MAKEDEV.local or 567 # some other script). The other args to this function are the 568 # command line args with which the MAKEDEV (or MAKEDEV.local) 569 # script was invoked. 570 # 571 makedev_main() 572 { 573 local makedev="$1" ; shift 574 575 # Parse command line args 576 setup ${1+"$@"} 577 shift $((${OPTIND}-1)) 578 579 if $do_create_mfs; then 580 # Count inodes and create mfs file system. 581 # The makedev call merely updates $count_nodes. 582 count_nodes=0 583 $makedev ${1+"$@"} 584 create_mfs_dev $count_nodes 585 unset count_nodes 586 fi 587 588 # If using mtree or pax, then wrap_makedev should print an mtree 589 # specification, which we postprocess to create the device nodes. 590 # Otherwise, wrap_makedev should do all the work itself. 591 if $do_mtree ; then 592 wrap_makedev $makedev ${1+"$@"} \ 593 | nooutput -1 "${TOOL_MTREE}" -e -U 594 elif $do_pax ; then 595 wrap_makedev $makedev ${1+"$@"} \ 596 | ( 597 # Run pax in an empty directory, so it pays 598 # attention only to the specfile, without being 599 # confused by the existing contents of the target 600 # directory. Without this, pax would complain "file 601 # would overwrite itself" for already-existing 602 # device nodes. 603 tmpdir=./tmp.$$ 604 mkdir "${tmpdir}" || die "can't create temporary directory" 605 cd "${tmpdir}" || die "can't cd to temporary directory" 606 "${TOOL_PAX}" -r -w -M -pe .. 607 status=$? 608 cd .. # back to where we started 609 rmdir "${tmpdir}" 610 exit $status 611 ) 612 else 613 wrap_makedev $makedev ${1+"$@"} 614 fi 615 } 616 617 # 618 # functions available to create nodes: 619 # 620 # mkdev name [b|c] major minor [mode{=600} [gid{=0} [uid{=0}]]] 621 # create device node `name' with the appropriate permissions 622 # 623 # lndev src target 624 # create a symlink from src to target 625 # 626 # makedir dir mode 627 # create directory with appropriate mode 628 # 629 630 mkdev() 631 { 632 if [ -n "$count_nodes" ]; then 633 count_nodes=$((count_nodes + 1)) 634 return 635 fi 636 if $do_specfile; then 637 case $2 in 638 b) type=block ;; 639 c) type=char ;; 640 esac 641 echo "./$1 type=${type} device=netbsd,$3,$4 mode=${5:-600} gid=${6:-$g_wheel} uid=${7:-$u_root}" 642 else 643 ${MKNOD} -m ${5:-600} -g \#${6:-$g_wheel} -u \#${7:-$u_root} $1 $2 $3 $4 644 fi 645 } 646 647 lndev() 648 { 649 if [ -n "$count_nodes" ]; then 650 count_nodes=$((count_nodes + 1)) 651 return 652 fi 653 if $do_specfile; then 654 echo "./$2 type=link link=$1 mode=0700 gid=$g_wheel uid=$u_root" 655 else 656 ln -f -s $1 $2 657 fi 658 } 659 660 makedir() 661 { 662 if [ -n "$count_nodes" ]; then 663 count_nodes=$((count_nodes + 1)) 664 return 665 fi 666 if $do_specfile; then 667 echo "./$1 type=dir mode=$2 gid=$g_wheel uid=$u_root" 668 else 669 nooutput -2 mkdir $1 670 chmod $2 $1 671 fi 672 } 673 674 warn() 675 { 676 echo 1>&2 "$0: $*" 677 } 678 679 die() 680 { 681 echo 1>&2 "$0: $*" 682 exit 1 683 } 684 685 # makedev special [...] 686 # the main loop 687 # 688 makedev() 689 { 690 691 for i 692 do 693 694 case $i in 695 696 %MD_DEVICES% 697 698 all) 699 makedev all_md 700 makedev std fd ptm pty0 pty1 pty2 pty3 701 makedev ccd0 ccd1 ccd2 ccd3 702 makedev cgd0 cgd1 cgd2 cgd3 703 makedev fss0 fss1 fss2 fss3 704 makedev md0 md1 705 makedev raid0 raid1 raid2 raid3 raid4 raid5 raid6 raid7 706 makedev vnd0 vnd1 vnd2 vnd3 707 makedev bpf 708 makedev tun0 tun1 tun2 tun3 709 makedev ipl pf crypto random 710 makedev lkm lockstat clockctl cpuctl 711 makedev atabus0 atabus1 atabus2 atabus3 712 makedev tap tap0 tap1 tap2 tap3 713 makedev gpio gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7 714 makedev pad pad0 pad1 pad2 pad3 715 makedev bthub 716 makedev cfs 717 makedev putter 718 makedev drvctl 719 makedev local # do this last 720 ;; 721 722 init) 723 # unless overridden by MD entry, this is equal to 'all' 724 makedev all 725 ;; 726 727 %MI_DEVICES_BEGIN% 728 audio) 729 makedev audio0 audio1 audio2 audio3 730 lndev sound0 sound 731 lndev audio0 audio 732 lndev mixer0 mixer 733 lndev audioctl0 audioctl 734 ;; 735 736 gpio) 737 makedev gpio0 gpio1 gpio2 gpio3 gpio4 gpio5 gpio6 gpio7 738 lndev gpio0 gpio 739 ;; 740 741 pad) 742 makedev pad0 pad1 pad2 pad3 743 lndev pad0 pad 744 ;; 745 746 radio) 747 makedev radio0 radio1 748 lndev radio0 radio 749 ;; 750 751 ramdisk) 752 makedev floppy md0 753 ;; 754 755 usbs) 756 makedev usb usb0 usb1 usb2 usb3 usb4 usb5 usb6 usb7 757 makedev uhid0 uhid1 uhid2 uhid3 758 makedev ulpt0 ulpt1 759 makedev ttyU0 ttyU1 760 makedev ttyY0 ttyY1 761 makedev urio0 762 makedev uscanner0 uscanner1 763 makedev utoppy0 utoppy1 764 makedev ugen0 765 ;; 766 767 isdns) 768 makedev isdn isdnctl isdnbchan0 isdnbchan1 isdntel0 isdntel1 isdnteld0 isdnteld1 isdntrc0 isdntrc1 769 ;; 770 771 std) 772 mkdev console c %cons_chr% 0 600 773 mkdev constty c %cons_chr% 1 600 774 mkdev drum c %swap_chr% 0 640 $g_kmem 775 mkdev kmem c %mem_chr% 1 640 $g_kmem 776 mkdev mem c %mem_chr% 0 640 $g_kmem 777 mkdev null c %mem_chr% 2 666 778 mkdev zero c %mem_chr% 12 666 779 mkdev klog c %log_chr% 0 600 780 mkdev ksyms c %ksyms_chr% 0 444 781 if $nofdesc; then 782 mkdev tty c %ctty_chr% 0 666 783 mkdev stdin c %filedesc_chr% 0 666 784 mkdev stdout c %filedesc_chr% 1 666 785 mkdev stderr c %filedesc_chr% 2 666 786 fi 787 ;; 788 789 usb) 790 mkdev usb c %usb_chr% 255 444 791 ;; 792 793 usb*) 794 unit=${i#usb} 795 usb=usb$unit 796 mkdev usb$unit c %usb_chr% $unit 797 ;; 798 799 uhid*) 800 unit=${i#uhid} 801 mkdev uhid$unit c %uhid_chr% $unit 666 802 ;; 803 804 ulpt*) 805 unit=${i#ulpt} 806 mkdev ulpt$unit c %ulpt_chr% $unit 807 mkdev ulpn$unit c %ulpt_chr% $(($unit + 64)) 808 ;; 809 810 urio*) 811 unit=${i#urio} 812 mkdev urio$unit c %urio_chr% $unit 666 813 ;; 814 815 uscanner*) 816 unit=${i#uscanner} 817 mkdev uscanner$unit c %uscanner_chr% $unit 818 ;; 819 820 utoppy*) 821 unit=${i#utoppy} 822 mkdev utoppy$unit c %utoppy_chr% $unit 823 ;; 824 825 ttyY*) 826 unit=${i#ttyY} 827 mkdev ttyY$unit c %ucycom_chr% $(($unit + $dialin )) "" "" $u_uucp 828 mkdev dtyY$unit c %ucycom_chr% $(($unit + $dialout )) "" "" $u_uucp 829 mkdev ctyY$unit c %ucycom_chr% $(($unit + $callunit)) "" "" $u_uucp 830 ;; 831 832 ttyU*) 833 unit=${i#ttyU} 834 mkdev ttyU$unit c %ucom_chr% $(($unit + $dialin )) "" "" $u_uucp 835 mkdev dtyU$unit c %ucom_chr% $(($unit + $dialout )) "" "" $u_uucp 836 mkdev ctyU$unit c %ucom_chr% $(($unit + $callunit)) "" "" $u_uucp 837 ;; 838 839 ugen*) 840 unit=${i#ugen} 841 for j in 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 842 do 843 mkdev ugen$unit.$j c %ugen_chr% $(($unit * 16 + ${j#0})) 844 done 845 ;; 846 847 wscons) 848 makedev ttyE0 ttyE1 ttyE2 ttyE3 ttyE4 ttyE5 ttyE6 ttyE7 849 makedev wsmouse0 wsmouse1 wsmouse2 wsmouse3 850 makedev wskbd0 wskbd1 wskbd2 wskbd3 851 makedev wsmux0 wsmux1 wsmux2 wsmux3 852 makedev wsmouse wskbd 853 makedev ttyEcfg ttyEstat 854 makedev wsfont 855 ;; 856 857 wsmouse) 858 mkdev wsmouse c %wsmux_chr% 0 859 ;; 860 861 wskbd) 862 mkdev wskbd c %wsmux_chr% 1 863 ;; 864 865 wsmux*) 866 unit=${i#wsmux} 867 mkdev wsmux$unit c %wsmux_chr% $unit 868 mkdev wsmuxctl$unit c %wsmux_chr% $(($unit + 128)) 200 869 ;; 870 871 xenevt) 872 mkdev xenevt c %xenevt_chr% 0 873 ;; 874 875 xsd_kva) 876 mkdev xsd_kva c %xenevt_chr% 1 877 ;; 878 879 xencons) 880 mkdev xencons c %xencons_chr% 0 881 ;; 882 883 ttyEstat) 884 mkdev ttyEstat c %wsdisplay_chr% 254 885 ;; 886 887 ttyEcfg) 888 mkdev ttyEcfg c %wsdisplay_chr% 255 889 ;; 890 891 ttyE*) 892 unit=${i#ttyE} 893 mkdev ttyE$unit c %wsdisplay_chr% $unit 894 ;; 895 896 wsmouse*) 897 unit=${i#wsmouse} 898 mkdev wsmouse$unit c %wsmouse_chr% $unit 899 ;; 900 901 wskbd*) 902 unit=${i#wskbd} 903 mkdev wskbd$unit c %wskbd_chr% $unit 904 ;; 905 906 fd) 907 if $nofdesc; then 908 makedir fd 755 909 n=0 910 while [ $n -lt 64 ] 911 do 912 mkdev fd/$n c %filedesc_chr% $n 666 913 n=$(($n + 1)) 914 done 915 fi 916 ;; 917 918 wt*) 919 case $i in 920 wt*) name=wt; unit=${i#wt}; chr=%wt_chr%; blk=%wt_blk%;; 921 esac 922 for sub in $unit $(($unit+8)) $(($unit+16)) 923 do 924 mkdev $name$sub b $blk $(($sub + 0)) 660 $g_operator 925 mkdev n$name$sub b $blk $(($sub + 4)) 660 $g_operator 926 mkdev r$name$sub c $chr $(($sub + 0)) 660 $g_operator 927 mkdev nr$name$sub c $chr $(($sub + 4)) 660 $g_operator 928 done 929 ;; 930 931 md*) 932 makedisk_minimal md ${i#md} %md_blk% %md_chr% 933 ;; 934 935 fss*) 936 case $i in 937 fss*) name=fss; unit=${i#fss}; blk=%fss_blk%; chr=%fss_chr% 938 esac 939 mkdev $name$unit b $blk $unit 660 $g_operator 940 mkdev r$name$unit c $chr $unit 660 $g_operator 941 ;; 942 943 ss*) 944 case $i in 945 ss*) name=ss; unit=${i#ss}; chr=%ss_chr%;; 946 esac 947 mkdev $name$unit c $chr $(($unit * 16 + 0)) 640 $g_operator 948 mkdev n$name$unit c $chr $(($unit * 16 + 1)) 640 $g_operator 949 mkdev en$name$unit c $chr $(($unit * 16 + 3)) 640 $g_operator 950 ;; 951 952 ccd*|cgd*|raid*|vnd*) 953 case $i in 954 ccd*) name=ccd; unit=${i#ccd}; blk=%ccd_blk%; chr=%ccd_chr%;; 955 cgd*) name=cgd; unit=${i#cgd}; blk=%cgd_blk%; chr=%cgd_chr%;; 956 raid*) name=raid; unit=${i#raid}; blk=%raid_blk%; chr=%raid_chr%;; 957 vnd*) name=vnd; unit=${i#vnd}; blk=%vnd_blk%; chr=%vnd_chr%;; 958 esac 959 %MKDISK% $name $unit $blk $chr 960 ;; 961 962 sd*) 963 name=sd; unit=${i#sd}; blk=%sd_blk%; chr=%sd_chr% 964 %MKDISK% $name $unit $blk $chr 965 ;; 966 967 wd*) 968 name=wd; unit=${i#wd}; blk=%wd_blk%; chr=%wd_chr% 969 %MKDISK% $name $unit $blk $chr 970 ;; 971 972 fd*) 973 name=fd; unit=${i#fd}; blk=%fd_blk%; chr=%fd_chr% 974 %MKDISK% $name $unit $blk $chr 975 ;; 976 977 ld*) 978 name=ld; unit=${i#ld}; blk=%ld_blk%; chr=%ld_chr% 979 %MKDISK% $name $unit $blk $chr 980 ;; 981 982 bio) 983 mkdev bio c %bio_chr% 0 984 ;; 985 986 ed*) 987 name=ed; unit=${i#ed}; blk=%ed_blk%; chr=%ed_chr% 988 %MKDISK% $name $unit $blk $chr 989 ;; 990 991 ofdisk*) 992 name=ofdisk; unit=${i#ofdisk}; blk=%ofdisk_blk%; chr=%ofdisk_chr% 993 %MKDISK% $name $unit $blk $chr 994 ;; 995 996 xbd*) 997 name=xbd; unit=${i#xbd}; blk=%xbd_blk%; chr=%xbd_chr% 998 %MKDISK% $name $unit $blk $chr 999 ;; 1000 1001 dk*) 1002 name=dk; unit=${i#dk}; blk=%dk_blk%; chr=%dk_chr% 1003 minor=0 1004 while [ $minor -le ${i#dk} ] 1005 do 1006 mkdev r$name$minor c $chr $minor 0640 $g_operator 1007 mkdev $name$minor b $blk $minor 0640 $g_operator 1008 minor=$(($minor + 1)) 1009 done 1010 ;; 1011 1012 ttyCY*) 1013 name=tyCY; chr=%cy_chr%; off=32 1014 unit=${i#t${name}} 1015 minor=$(($unit * $off)) 1016 eminor=$(($minor + $off)) 1017 while [ $minor -lt $eminor ] 1018 do 1019 nminor=000$minor 1020 nminor=${nminor#${nminor%???}} 1021 mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp 1022 mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp 1023 minor=$(($minor + 1)) 1024 done 1025 ;; 1026 1027 ttyCZ*) 1028 name=tyCZ; chr=%cz_chr%; off=64 1029 unit=${i#t${name}} 1030 minor=$(($unit * $off)) 1031 eminor=$(($minor + $off)) 1032 while [ $minor -lt $eminor ] 1033 do 1034 nminor=0000$minor 1035 nminor=${nminor#${nminor%????}} 1036 mkdev t$name$nminor c $chr $(($minor + $dialin )) "" "" $u_uucp 1037 mkdev d$name$nminor c $chr $(($minor + $dialout)) "" "" $u_uucp 1038 minor=$(($minor + 1)) 1039 done 1040 ;; 1041 1042 1043 tty[0-9]|tty0[0-9]) 1044 # some archs have built-in zstty (major %zstty_chr%) instead 1045 # of NS16550; create ttyZ* and hardlink as [dt]ty0*; this 1046 # needs to be before com entry, for archs which have both 1047 unit=${i#tty} 1048 unit=$(($unit + 0)) 1049 makedev ttyZ${unit} 1050 lndev ttyZ$unit tty0${unit} 1051 lndev dtyZ$unit dty0${unit} 1052 ;; 1053 1054 tty0*|tty1*|tty[0-9]) 1055 unit=${i#tty} 1056 ounit=00$unit 1057 ounit=${ounit#${ounit%??}} 1058 mkdev tty$ounit c %com_chr% $(($unit + $dialin )) "" "" $u_uucp 1059 mkdev dty$ounit c %com_chr% $(($unit + $dialout)) "" "" $u_uucp 1060 ;; 1061 1062 ttyC*) 1063 # some archs call com_chr ttyC traditionally 1064 unit=${i#ttyC}; name=ttyC; dname=dtyC; chr=%com_chr% 1065 mkdev $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp 1066 mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp 1067 ;; 1068 1069 ttyh*) 1070 unit=${i#ttyh}; name=ttyh; dname=dtyh; chr=%sabtty_chr% 1071 mkdev $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp 1072 mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp 1073 ;; 1074 1075 ttyTX*) 1076 unit=${i#ttyTX}; name=ttyTX0; dname=dtyTX0; chr=%txcom_chr% 1077 mkdev $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp 1078 mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp 1079 ;; 1080 1081 ttyZ*) 1082 unit=${i#ttyZ}; name=ttyZ; dname=dtyZ; chr=%zstty_chr% 1083 mkdev $name$unit c $chr $(($unit + $dialin )) "" "" $u_uucp 1084 mkdev $dname$unit c $chr $(($unit + $dialout)) "" "" $u_uucp 1085 ;; 1086 1087 opty) 1088 for j in 0 1 2 3 4 5 6 7 8 9 a b c d e f 1089 do 1090 case $j in 1091 [0-9]) jn=$j ;; 1092 a) jn=10 ;; 1093 b) jn=11 ;; 1094 c) jn=12 ;; 1095 d) jn=13 ;; 1096 e) jn=14 ;; 1097 f) jn=15 ;; 1098 esac 1099 mkdev ttyp$j c %pts_chr% $jn 666 1100 mkdev ptyp$j c %ptc_chr% $jn 666 1101 done 1102 ;; 1103 1104 pty*) 1105 class=${i#pty} 1106 d1="p q r s t u v w x y z P Q R S T" 1107 if [ "$class" -ge 64 ] 1108 then 1109 warn "$i: pty unit must be between 0 and 63" 1110 continue 1111 elif [ "$class" -lt 16 ] 1112 then 1113 offset=0 1114 mult=0 1115 d2="0 1 2 3 4 5 6 7 8 9 a b c d e f" 1116 else 1117