Source code pulled from OpenBSD for OpenNTPD. The place to contribute to this code is via the OpenBSD CVS tree.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

507 lines
11 KiB

26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
26 years ago
28 years ago
  1. #!/bin/sh -
  2. # $OpenBSD: MAKEDEV,v 1.37 2001/06/28 02:58:57 kjc Exp $
  3. #
  4. # Copyright (c) 1990 The Regents of the University of California.
  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. # 3. All advertising materials mentioning features or use of this software
  16. # must display the following acknowledgement:
  17. # This product includes software developed by the University of
  18. # California, Berkeley and its contributors.
  19. # 4. Neither the name of the University nor the names of its contributors
  20. # may be used to endorse or promote products derived from this software
  21. # without specific prior written permission.
  22. #
  23. # THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  24. # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  25. # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  26. # ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  27. # FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  28. # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  29. # OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  30. # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  31. # LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  32. # OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  33. # SUCH DAMAGE.
  34. #
  35. # @(#)MAKEDEV 5.5 (Berkeley) 5/28/91
  36. #
  37. # Device "make" file. Valid arguments:
  38. # all makes all known devices, including local devices.
  39. # Tries to make the ``standard'' number of each type.
  40. # std standard devices
  41. # local configuration specific devices
  42. #
  43. # Tapes:
  44. # st* SCSI tapes
  45. #
  46. # Disks:
  47. # sd* SCSI disks
  48. # cd* SCSI cdrom drives
  49. # xy* Xylogic 450/451 disks
  50. # rd* "ramdisk" pseudo-disks
  51. # xd* Xylogic 753/7053 disks
  52. # vnd* "file" pseudo-disks
  53. # ccd* concatenated disk devices
  54. #
  55. # Pseudo terminals:
  56. # pty* set of 16 master and slave pseudo terminals
  57. #
  58. # Printers:
  59. #
  60. # Terminal ports:
  61. # tty[a-b] onboard zs serial ports
  62. #
  63. # Special purpose devices:
  64. # uk* SCSI Unknown device
  65. # ss* SCSI scanners
  66. # bwtwo*
  67. # cgtwo*
  68. # cgfour*
  69. # bpf* Berkeley Packet Filter
  70. # tun* network tunnel driver
  71. # *random inkernal random data source
  72. # xfs* XFS filesystem devices
  73. # altq ALTQ control interface
  74. PATH=/sbin:/bin:/usr/bin:/usr/sbin
  75. this=$0
  76. umask 77
  77. if ! [ "$os" ]; then
  78. os=OpenBSD
  79. fi
  80. # SunOS shell support functions
  81. if [ "$os" = "SunOS" ]
  82. then
  83. PATH=$PATH:/usr/etc # SunOS has chown is /usr/etc
  84. add ()
  85. {
  86. expr $1 + $2
  87. }
  88. mult ()
  89. {
  90. expr $1 '*' $2
  91. }
  92. hex ()
  93. {
  94. case $1 in
  95. [0-9]) echo -n $1;;
  96. 10) echo -n a;;
  97. 11) echo -n b;;
  98. 12) echo -n c;;
  99. 13) echo -n d;;
  100. 14) echo -n e;;
  101. 15) echo -n f;;
  102. esac
  103. }
  104. trunc ()
  105. {
  106. expr $1 : $2'\(.*\)'
  107. }
  108. unt ()
  109. {
  110. expr $1 : '[a-z]*\([0-9]*\)[a-p]*'
  111. }
  112. fi
  113. # OpenBSD shell support functions
  114. if [ "$os" = "OpenBSD" ]
  115. then
  116. add ()
  117. {
  118. tmp=0
  119. while [ "$1" ]
  120. do
  121. tmp=$(( $1 + $tmp ))
  122. shift
  123. done
  124. echo $tmp
  125. }
  126. mult ()
  127. {
  128. echo "$(( $1 * $2 ))"
  129. }
  130. hex ()
  131. {
  132. case $1 in
  133. [0-9]) echo -n $1;;
  134. 10) echo -n a;;
  135. 11) echo -n b;;
  136. 12) echo -n c;;
  137. 13) echo -n d;;
  138. 14) echo -n e;;
  139. 15) echo -n f;;
  140. esac
  141. }
  142. trunc ()
  143. {
  144. # XXX pdksh can't seem to deal with locally scoped variables
  145. # in ${foo#$bar} expansions
  146. arg1="$1"
  147. arg2="$2"
  148. echo ${arg1#$arg2}
  149. }
  150. unt ()
  151. {
  152. # XXX pdksh can't seem to deal with locally scoped variables
  153. # in ${foo#$bar} expansions
  154. arg1="$1"
  155. tmp="${arg1#[a-z]*}"
  156. while [ "$tmp" != "$arg1" ]
  157. do
  158. arg1=$tmp
  159. tmp="${arg1#[a-z]*}"
  160. done
  161. tmp="${arg1%*[a-z]}"
  162. while [ "$tmp" != "$arg1" ]
  163. do
  164. arg1=$tmp
  165. tmp="${arg1%*[a-z]}"
  166. done
  167. echo $arg1
  168. }
  169. fi
  170. for i
  171. do
  172. unit=`unt $i`
  173. [ "$unit" ] || unit=0
  174. case $i in
  175. all)
  176. sh $this std sd0 sd1 sd2 sd3 sd4 xd0 xd1 xd2 xd3 xy0 xy1 xy2 xy3
  177. sh $this cd0 st0 st1 rd0
  178. sh $this uk0 uk1
  179. sh $this ss0 ss1
  180. sh $this pty0 vnd0 vnd1 vnd2 vnd3 pf tun0 tun1 tun2 tun3
  181. sh $this ccd0 ccd1 ccd2 ccd3
  182. sh $this bpf0 bpf1 bpf2 bpf3 bpf4 bpf5 bpf6 bpf7 bpf8 bpf9
  183. sh $this bwtwo0 cgtwo0 cgfour0
  184. sh $this random local
  185. sh $this xfs0 altq
  186. ;;
  187. ramdisk)
  188. sh $this std random
  189. sh $this sd0 sd1 sd2 sd3 sd4 rd0 cd0 st0 st1
  190. # sh $this xd0 xd1 xd2 xd3 xy0 xy1 xy2 xy3
  191. sh $this bpf0
  192. ;;
  193. std)
  194. rm -f console drum mem kmem xf86 null zero io tty klog stdin stdout stderr ksyms
  195. rm -f eeprom kd ttya ttyb fb mouse kbd leds
  196. rm -f vme16d16 vme24d16 vme32d16 vme16d32 vme24d32 vme32d32 vme16 vme24 vme32
  197. mknod console c 0 0
  198. mknod kd c 1 0
  199. mknod tty c 2 0 ; chmod 666 tty
  200. mknod kmem c 3 1 ; chmod 640 kmem ; chown root.kmem kmem
  201. mknod mem c 3 0 ; chmod 640 mem ; chown root.kmem mem
  202. mknod null c 3 2 ; chmod 666 null
  203. mknod vme16d16 c 3 5 ; chmod 600 vme16d16
  204. ln -s vme16d16 vme16
  205. mknod vme24d16 c 3 6 ; chmod 600 vme24d16
  206. ln -s vme24d16 vme24
  207. mknod vme32d16 c 3 7 ; chmod 600 vme32d16
  208. mknod vme16d32 c 3 8 ; chmod 600 vme16d32
  209. mknod vme24d32 c 3 9 ; chmod 600 vme24d32
  210. mknod vme32d32 c 3 10 ; chmod 600 vme32d32
  211. ln -s vme32d32 vme32
  212. mknod zero c 3 12 ; chmod 666 zero
  213. mknod eeprom c 3 11 ; chmod 640 eeprom ; chown root.kmem eeprom
  214. mknod leds c 3 13 ; chmod 644 leds
  215. mknod drum c 7 0 ; chmod 640 drum ; chown root.kmem drum
  216. mknod klog c 16 0 ; chmod 600 klog
  217. mknod stdin c 23 0 ; chmod 666 stdin
  218. mknod stdout c 23 1 ; chmod 666 stdout
  219. mknod stderr c 23 2 ; chmod 666 stderr
  220. sh $this ttya ttyb
  221. mknod fb c 22 0 ; chmod 666 fb
  222. mknod mouse c 13 0 ; chmod 666 mouse
  223. mknod kbd c 29 0 ; chmod 666 kbd
  224. mknod ksyms c 37 0 ; chmod 640 ksyms ; chown root.kmem ksyms
  225. ;;
  226. fd)
  227. rm -f fd/*
  228. mkdir fd > /dev/null 2>&1
  229. n=0
  230. (cd fd && while [ $n -lt 64 ]; do mknod $n c 23 $n; n=`add $n 1`; done )
  231. chown -R root.wheel fd
  232. chmod 555 fd
  233. chmod 666 fd/*
  234. ;;
  235. bwtwo*)
  236. rm -f bwtwo$unit
  237. mknod bwtwo$unit c 27 $unit; chmod 666 bwtwo$unit
  238. ;;
  239. cgtwo*)
  240. rm -f cgtwo$unit
  241. mknod cgtwo$unit c 31 $unit; chmod 666 cgtwo$unit
  242. ;;
  243. cgfour[0-9]*)
  244. rm -f cgfour$unit
  245. mknod cgfour$unit c 39 $unit; chmod 666 cgfour$unit
  246. ;;
  247. xfs*)
  248. rm -f xfs$unit
  249. mknod xfs$unit c 51 $unit
  250. chmod 600 xfs$unit
  251. chown root.wheel xfs$unit
  252. ;;
  253. bpf*)
  254. rm -f bpf$unit
  255. mknod bpf$unit c 36 $unit
  256. chmod 600 bpf$unit
  257. chown root.wheel bpf$unit
  258. ;;
  259. pf)
  260. rm -f pf
  261. mknod pf c 75 0
  262. chown root.wheel pf
  263. chmod 600 pf
  264. ;;
  265. tun*)
  266. rm -f tun$unit
  267. mknod tun$unit c 24 $unit
  268. chmod 600 tun$unit
  269. chown root.wheel tun$unit
  270. ;;
  271. ccd*|sd*|xd*|xy*|cd*)
  272. umask 2
  273. unit=`unt $i`
  274. if [ 0$unit -gt 15 ]
  275. then
  276. echo bad disk unit: $i - $unit
  277. exit 127
  278. fi
  279. case $i in
  280. ccd*) name=ccd; blk=9; chr=33;;
  281. sd*) name=sd; blk=7; chr=17;;
  282. xd*) name=xd; blk=10; chr=42;;
  283. xy*) name=xy; blk=3; chr=9;;
  284. cd*) name=cd; blk=18; chr=58;;
  285. *) echo bad unit for disk in: $i;;
  286. esac
  287. if [ "$unit" = "" ]
  288. then
  289. n=0
  290. while [ $n -lt 32 ]
  291. do
  292. sh $this $name$n
  293. n=`add $n 1`
  294. done
  295. fi
  296. rm -f $name$unit? r$name$unit?
  297. minor=`mult $unit 16`
  298. for slice in a b c d e f g h i j k l m n o p
  299. do
  300. dev=$name$unit$slice
  301. mknod $dev b $blk $minor
  302. mknod r$dev c $chr $minor
  303. minor=`add $minor 1`
  304. done
  305. chown root.operator $name$unit? r$name$unit?
  306. chmod 640 $name$unit? r$name$unit?
  307. umask 77
  308. ;;
  309. vnd*)
  310. umask 2
  311. unit=`unt $i`
  312. if [ 0$unit -gt 15 ]
  313. then
  314. echo bad disk unit: $i - $unit
  315. exit 127
  316. fi
  317. blk=5; chr=19;
  318. for name in vnd svnd; do
  319. case $name in
  320. vnd) off=0;;
  321. svnd) off=128;;
  322. esac
  323. if [ "$unit" = "" ]
  324. then
  325. n=0
  326. while [ $n -lt 32 ]
  327. do
  328. sh $this $name$n
  329. n=`add $n 1`
  330. done
  331. fi
  332. rm -f $name$unit? r$name$unit?
  333. minor=`mult $unit 16`
  334. minor=`add $minor $off`
  335. for slice in a b c d e f g h i j k l m n o p
  336. do
  337. dev=$name$unit$slice
  338. mknod $dev b $blk $minor
  339. mknod r$dev c $chr $minor
  340. minor=`add $minor 1`
  341. done
  342. chown root.operator $name$unit? r$name$unit?
  343. chmod 640 $name$unit? r$name$unit?
  344. done
  345. umask 77
  346. ;;
  347. rd*)
  348. umask 2 ; unit=`expr $i : '.*d\(.*\)'`
  349. rm -f rd${unit}* rrd${unit}*
  350. mknod rd${unit}a b 13 `expr $unit '*' 16 + 0`
  351. mknod rd${unit}c b 13 `expr $unit '*' 16 + 2`
  352. mknod rrd${unit}a c 52 `expr $unit '*' 16 + 0`
  353. mknod rrd${unit}c c 52 `expr $unit '*' 16 + 2`
  354. chown root.operator rd${unit}[ac] rrd${unit}[ac]
  355. chmod 640 rd${unit}[ac] rrd${unit}[ac]
  356. umask 77
  357. ;;
  358. st*)
  359. umask 2
  360. case $i in
  361. st*) name=st; blk=11; chr=18;;
  362. esac
  363. rm -f $name$unit n$name$unit e$name$unit en$name$unit \
  364. r$name$unit nr$name$unit er$name$unit enr$name$unit
  365. sixt=`mult $unit 16`
  366. mknod $name$unit b $blk `add $sixt 0`
  367. mknod n$name$unit b $blk `add $sixt 1`
  368. mknod e$name$unit b $blk `add $sixt 2`
  369. mknod en$name$unit b $blk `add $sixt 3`
  370. mknod r$name$unit c $chr `add $sixt 0`
  371. mknod nr$name$unit c $chr `add $sixt 1`
  372. mknod er$name$unit c $chr `add $sixt 2`
  373. mknod enr$name$unit c $chr `add $sixt 3`
  374. chown root.operator $name$unit n$name$unit \
  375. e$name$unit en$name$unit \
  376. r$name$unit nr$name$unit \
  377. er$name$unit enr$name$unit
  378. chmod 660 $name$unit n$name$unit \
  379. e$name$unit en$name$unit \
  380. r$name$unit nr$name$unit \
  381. er$name$unit enr$name$unit
  382. umask 77
  383. ;;
  384. tty[a-z])
  385. unit=`expr $i : 'tty\([a-z]\)'`
  386. rm -f tty$unit
  387. case $unit in
  388. a) n=0 ;;
  389. b) n=1 ;;
  390. *) echo unknown tty device $i ;;
  391. esac
  392. mknod tty$unit c 12 $n
  393. chown uucp.dialer tty$unit
  394. chmod 660 tty$unit
  395. ;;
  396. pty*)
  397. case $unit in
  398. 0) offset=0 name=p;;
  399. 1) offset=16 name=q;;
  400. 2) offset=32 name=r;;
  401. 3) offset=48 name=s;;
  402. 4) offset=64 name=t;;
  403. 5) offset=80 name=u;;
  404. 6) offset=96 name=v;;
  405. 7) offset=112 name=w;;
  406. 8) offset=128 name=x;;
  407. 9) offset=144 name=y;;
  408. 10) offset=160 name=z;;
  409. 11) offset=176 name=P;;
  410. 12) offset=192 name=Q;;
  411. 13) offset=208 name=R;;
  412. 14) offset=224 name=S;;
  413. 15) offset=240 name=T;;
  414. *) echo bad unit for pty in: $i;;
  415. esac
  416. case $unit in
  417. 0|1|2|3|4|5|6|7|8|9|10|11|12|13|14|15)
  418. umask 0
  419. n=0
  420. while [ $n -lt 16 ]
  421. do
  422. nam=$name`hex $n`
  423. rm -f {tty,pty}$nam
  424. mknod tty$nam c 20 `add $offset $n`
  425. mknod pty$nam c 21 `add $offset $n`
  426. n=`add $n 1`
  427. done
  428. umask 77
  429. ;;
  430. esac
  431. ;;
  432. random|srandom|urandom|prandom|arandom)
  433. rm -f random urandom srandom prandom arandom
  434. mknod random c 72 0
  435. mknod srandom c 72 1
  436. mknod urandom c 72 2
  437. mknod prandom c 72 3
  438. mknod arandom c 72 4
  439. chown root.wheel random srandom urandom prandom arandom
  440. chmod 644 random srandom urandom prandom arandom
  441. ;;
  442. uk*)
  443. unit=`trunc $i uk`
  444. rm -f uk$unit
  445. mknod uk$unit c 98 $unit
  446. chown root.operator uk$unit
  447. chmod 640 uk$unit
  448. ;;
  449. ss*)
  450. unit=`trunc $i ss`
  451. rm -f ss$unit
  452. mknod ss$unit c 99 $unit
  453. chown root.operator ss$unit
  454. chmod 440 ss$unit
  455. # backwards compatibility with older PINTs
  456. rm -f scan$unit
  457. ln -s ss$unit scan$unit
  458. ;;
  459. altq)
  460. mkdir -p altq
  461. chmod 755 altq
  462. unit=0
  463. for dev in altq cbq wfq afm fifoq red rio localq hfsc \
  464. cdnr blue priq; do
  465. rm -f altq/$dev
  466. mknod altq/$dev c 85 $unit
  467. chmod 644 altq/$dev
  468. unit=$(($unit + 1))
  469. done
  470. ;;
  471. local)
  472. umask 0
  473. test -s MAKEDEV.local && sh MAKEDEV.local
  474. ;;
  475. *)
  476. echo $i: unknown device
  477. ;;
  478. esac
  479. done