3 # MAKEDEV 3.3 - Make special devices. Author: Kees J. Bot
4 # 3.4 - Rewritten to allow mtree line to be printed, Lionel A. Sambuc
5 # also use getopt for argument parsing
14 # console => lp tty log
15 # boot => kmem mem null ram zero
20 c0d0 c0d0p0 c0d0p0s0 c0d1 c0d1p0 c0d1p0s0
21 c0d2 c0d2p0 c0d2p0s0 c0d3 c0d3p0 c0d3p0s0
22 c0d4 c0d4p0 c0d4p0s0 c0d5 c0d5p0 c0d5p0s0
23 c0d6 c0d6p0 c0d6p0s0 c0d7 c0d7p0 c0d7p0s0
24 c1d0 c1d0p0 c1d0p0s0 c1d1 c1d1p0 c1d1p0s0
25 c1d2 c1d2p0 c1d2p0s0 c1d3 c1d3p0 c1d3p0s0
26 c1d4 c1d4p0 c1d4p0s0 c1d5 c1d5p0 c1d5p0s0
27 c1d6 c1d6p0 c1d6p0s0 c1d7 c1d7p0 c1d7p0s0
30 ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03
36 bmp085b1s77 bmp085b2s77 bmp085b3s77
37 eepromb1s50 eepromb1s51 eepromb1s52 eepromb1s53
38 eepromb1s54 eepromb1s55 eepromb1s56 eepromb1s57
39 eepromb2s50 eepromb2s51 eepromb2s52 eepromb2s53
40 eepromb2s54 eepromb2s55 eepromb2s56 eepromb2s57
41 eepromb3s50 eepromb3s51 eepromb3s52 eepromb3s53
42 eepromb3s54 eepromb3s55 eepromb3s56 eepromb3s57
43 eth fb0 fbd filter hello
46 sht21b1s40 sht21b2s40 sht21b3s40
47 tsl2550b1s39 tsl2550b2s39 tsl2550b3s39
48 ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9
49 ttypa ttypb ttypc ttypd ttype ttypf
50 ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9
51 ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf
53 vnd0 vnd0p0 vnd0p0s0 vnd1 vnd1p0 vnd1p0s0
54 vnd2 vnd3 vnd4 vnd5 vnd6 vnd7
57 #makedev ${dev} $type ${major} ${minor} ${uname} ${gname} ${permissions} [link_target]
58 #When called for a link, major and minor are ignored
61 # Check that all the arguments are there, we trust the caller to put
62 # values which make sens.
63 [ $# -eq 7 ] ||
[ $# -eq 8 ] ||
return 1;
76 l
) _type
=link
; _target
=$8;;
80 if [ ${MTREE} = "yes" ]
82 if [ ${_type} = "link" ]
84 echo .
/dev
/${_dev} type=${_type} \
85 uname
=${_uname} gname=${_gname} mode=${_mode} \
88 echo .
/dev
/${_dev} type=${_type} \
89 uname
=${_uname} gname=${_gname} mode=${_mode} \
90 device
=native
,${_major},${_minor}
93 if [ ${_type} = "link" ]
95 ${ECHO} ln -f ${_target} ${_dev}
97 ${ECHO} mknod ${_dev} ${__type} ${_major} ${_minor}
98 ${ECHO} chmod ${_mode} ${_dev}
99 ${ECHO} chown ${_uname}:${_gname} ${_dev}
108 Usage: $0 [-n|-m] [-s|-r] key ...
109 -n: print the commands instead of executing them
110 -m: print mtree(8) line
111 -s: standard set of devices
112 -r: reduced for ramdisk set of devices
114 Where key is one of the following:
115 ram mem kmem null boot zero # One of these makes all these memory devices
117 i2c-1 i2c-2 i2c-3 # Make /dev/i2c-[1-3]
118 tsl2550b{1,3}s39 # TSL2550 Ambient Light Sensors
119 sht21b{1,3}s40 # SHT21 Relative Humidity and Temperature Sensors
120 bmp085b{1,3}s77 # BMP085 Pressure and Temperature Sensors
121 fd0 fd1 ... # Floppy devices for drive 0, 1, ...
122 fd0p0 fd1p0 ... # Make floppy partitions fd0p[0-3], fd1p[0-3], ...
123 c0d0 c0d1 ... # Make disks c0d0, c0d1, ...
124 c0d0p0 c0d1p0 ... # Make partitions c0d0p[0-3], c0d1p[0-3], ...
125 c0d0p0s0 c0d1p0s0 ... # Subparts c0d0p[0-3]s[0-3], c0d1p[0-3]s[0-3], ...
126 c1d0(p0)(s0) # Likewise for controller 1
127 c0t0 c0t1 c1t0 ... # Make tape devices c0t0, c0t0n, c0t1, ...
128 console lp tty log # One of these makes all four
129 ttyc1 ... ttyc7 # Virtual consoles
130 tty00 ... tty03 # Make serial lines
131 ttyp0 ... ttyq0 ... # Make tty, pty pairs
132 eth ip tcp udp # One of these makes some TCP/IP devices
133 audio mixer # Make audio devices
134 klog # Make /dev/klog
135 ptmx # Make /dev/ptmx
136 random # Make /dev/random, /dev/urandom
138 filter # Make /dev/filter
140 hello # Make /dev/hello
141 video # Make /dev/video
143 vnd0 vnd0p0 vnd0p0s0 .. # Make vnode disks /dev/vnd[0-7] and (sub)partitions
144 input # Make /dev/kbdmux, /dev/kbd[0-3], idem /dev/mouse~
150 while getopts "nmrs" arg
171 if [ ${STD} = "yes" ]
173 DEVICES
=${STD_DEVICES}
174 elif [ ${RAMDISK} = "yes" ]
176 DEVICES
=${RAMDISK_DEVICES}
178 while [ $OPTIND -gt 1 ]
181 OPTIND
=$
((${OPTIND} - 1))
185 DEVICES
="${DEVICES} $1"
190 for dev
in ${DEVICES}
202 vnd
*) # Whole vnode disk devices.
203 disk
=`expr ${dev} : '...\\(.\\)'`
204 major
=`expr ${disk} + 56`
208 # The following is lexicographicaly ordered
212 makedev audio c
13 0 ${uname} ${gname} 666
213 makedev mixer c
13 1 ${uname} ${gname} 666
216 # Weather Cape: temperature & pressure sensor
217 bus
=`expr ${dev} : 'bmp085b\\(.*\\)s77'` #bus number
218 major
=`expr ${bus} + 52`
220 makedev bmp085b
${bus}s77 c ${major} 0 ${uname} ${gname} 444
223 # Whole disk devices.
224 disk
=`expr ${dev} : '...\\(.\\)'`
225 minor
=`expr ${disk} '*' 5`
227 makedev
${dev} b ${major} ${minor} ${uname} ${gname} ${permissions}
230 # Disk primary partitions.
231 prefix
=`expr ${dev} : '\\(.*\\).'`
232 disk
=`expr ${dev} : '...\\(.\\)'`
236 minor
=`expr ${disk} '*' 5 + 1 + ${p}`
237 makedev
${prefix}${p} b ${major} ${minor} \
238 ${uname} ${gname} ${permissions}
241 c
[0-3]d
[0-7]p
[0-3]s
[0-3])
243 prefix
=`expr ${dev} : '\\(.*\\)...'`
244 disk
=`expr ${dev} : '...\\(.\\)'`
250 minor
=`expr 128 + ${disk} '*' 16 + ${p} '*' 4 + ${s}`
251 makedev
${prefix}${p}s${s} b ${major} ${minor} \
252 ${uname} ${gname} ${permissions}
256 c
[0-3]t
[0-7]|c
[0-3]t
[0-7]n
)
258 prefix
=`expr ${dev} : '\\(....\\)'`
259 tape
=`expr ${dev} : '...\\(.\\)'`
260 minor
=`expr 64 + ${tape} '*' 2`
262 makedev
${prefix}n c ${major} ${minor} ${uname} ${gname} 660
263 makedev
${prefix} c ${major} `expr ${minor} + 1` ${uname} ${gname} 660
265 console|
lp|tty|log|video
)
266 # Console, line printer, anonymous tty, diagnostics device, video.
267 makedev console c
4 0 ${uname} tty
${permissions}
268 makedev tty c
5 0 ${uname} ${gname} 666
269 makedev
lp c
6 0 daemon daemon
200
270 makedev log c
4 15 ${uname} ${gname} 222
271 makedev video c
4 125 ${uname} ${gname} ${permissions}
275 bus
=`expr ${dev} : 'eepromb\\(.*\\)s'`
276 # configurable part of slave addr
277 slave_low
=`expr ${dev} : 'eepromb.s5\\(.*\\)'`
278 major
=`expr ${bus} '*' 8 + ${slave_low} + 17`
280 makedev eepromb
${bus}s5${slave_low} b ${major} 0 ${uname} ${gname} ${permissions}
282 eth|ip|tcp|udp|eth0|ip0|tcp0|udp0
)
284 makedev ipstat c
7 0 ${uname} ${gname} 666
285 makedev eth0 c
7 1 ${uname} ${gname} ${permissions}
286 makedev ip0 c
7 2 ${uname} ${gname} ${permissions}
287 makedev tcp0 c
7 3 ${uname} ${gname} 666
288 makedev udp0 c
7 4 ${uname} ${gname} 666
291 makedev eth c
7 1 ${uname} ${gname} ${permissions}
292 makedev ip c
7 2 ${uname} ${gname} ${permissions}
293 makedev tcp c
7 3 ${uname} ${gname} 666
294 makedev udp c
7 4 ${uname} ${gname} 666
298 makedev
${dev} c 19 0 ${uname} ${gname} 644
301 # Faulty block device driver
302 makedev
${dev} b 14 0 ${uname} ${gname} ${permissions}
305 # Floppy disk drive N has minor N.
306 minor
=`expr ${dev} : '..\\(.\\)'`
308 makedev
${dev} b 2 ${minor} ${uname} ${gname} 666
311 # Floppy disk partitions.
312 prefix
=`expr ${dev} : '\\(.*\\).'`
313 drive
=`expr ${dev} : '..\\(.\\)'`
317 minor
=`expr 112 + ${drive} + ${p} '*' 4`
318 makedev
${prefix}${p} b 2 ${minor} \
319 ${uname} ${gname} 666
324 makedev
${dev} b 11 0 ${uname} ${gname} ${permissions}
328 makedev
${dev} c 17 0 ${uname} ${gname} 644
332 bus
=`expr ${dev} : '....\\(.*\\)'` # bus number
333 # least significant digit of major
334 major_low
=`expr ${dev} : '....\\(.*\\)'`
335 major_low
=`expr ${major_low} - 1`
337 makedev
"i2c-${bus}" c 2${major_low} 0 ${uname} ${gname} ${permissions}
341 makedev kbdmux c 64 0 ${uname} ${gname} ${permissions}
342 makedev mousemux c 64 64 ${uname} ${gname} ${permissions}
346 minor_keyboard=`expr ${n} + 1`
347 minor_mouse=`expr ${n} + 65`
349 makedev kbd${n} c 64 ${minor_keyboard} ${uname} ${gname} ${permissions}
350 makedev mouse${n} c 64 ${minor_mouse} ${uname} ${gname} ${permissions}
355 makedev ${dev} c 15 0 ${uname} ${gname} ${permissions}
357 pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3])
358 # Obsolete density locked floppy disk drive n.
359 drive=`expr ${dev} : '.*\\(.\\)'`
362 for prefix in pc at qd ps pat qh PS
364 makedev ${prefix}${drive} b 2 ${minor} \
365 ${uname} ${gname} 666
366 minor=`expr ${minor} + 4`
370 # PCI server, manages PCI buses
371 makedev pci c 134 0 ${uname} ${gname} ${permissions}
374 # Unix98 pseudoterminal master
375 makedev ptmx c 9 0 ${uname} tty 666
377 ram|mem|kmem|null|boot|zero|imgrd)
379 makedev ram b 1 0 ${uname} kmem ${permissions}
380 makedev mem c 1 1 ${uname} kmem 640
381 makedev kmem c 1 2 ${uname} kmem 640
382 makedev null c 1 3 ${uname} kmem 666
383 makedev boot b 1 4 ${uname} kmem ${permissions}
384 makedev zero c 1 5 ${uname} kmem 644
385 makedev imgrd b 1 6 ${uname} kmem ${permissions}
389 minor=`expr ${n} + 7`
391 makedev ram${n} b 1 ${minor} ${uname} kmem ${permissions}
395 # Random data generator.
396 makedev random c 16 0 ${uname} ${gname} 644
397 makedev urandom c 16 0 ${uname} ${gname} 644
400 # Weather Cape: relative humidity & temperature sensor
401 bus=`expr ${dev} : 'sht21b\\(.*\\)s40'`
402 major=`expr ${bus} + 49`
404 makedev sht21b${bus}s40 c ${major} 0 ${uname} ${gname} 444
407 # Weather Cape: ambient light sensor
408 bus=`expr ${dev} : 'tsl2550b\\(.*\\)s39'`
409 major=`expr ${bus} + 46`
411 makedev tsl2550b${bus}s39 c ${major} 0 ${uname} ${gname} 444
415 line=`expr ${dev} : '.*\\(.\\)'`
416 minor=`expr ${line} + 16`
418 makedev ${dev} c 4 ${minor} ${uname} tty 666
420 tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
422 dev=`expr ${dev} : '...\\(..\\)'`
423 group=`expr ${dev} : '\\(.\\)'`
424 group=`echo ${group} | tr 'pqrs' '0123'`
425 pty=`expr ${dev} : '.\\(.\\)'`
427 [a-f]) pty=1`/bin/echo ${pty} | tr 'abcdef' '012345'`
429 minor_tty=`expr ${group} '*' 16 + ${pty} + 128`
430 minor_pty=`expr ${group} '*' 16 + ${pty} + 192`
432 makedev tty${dev} c 9 ${minor_tty} ${uname} tty 666
433 makedev pty${dev} c 9 ${minor_pty} ${uname} tty 666
437 minor=`expr ${dev} : '....\\(.*\\)'`
439 makedev ${dev} c 4 ${minor} ${uname} tty ${permissions}
442 # Unix domain sockets device
443 makedev ${dev} c 18 0 ${uname} ${gname} 666
446 # Whole vnode disk devices.
447 makedev ${dev} b ${major} 0 ${uname} ${gname} ${permissions}
450 # Vnode disk primary partitions.
451 prefix=`expr ${dev} : '\\(.*\\).'`
452 disk=`expr ${dev} : '...\\(.\\)'`
456 minor=`expr 1 + ${p}`
458 makedev ${prefix}${p} b ${major} ${minor} \
459 ${uname} ${gname} ${permissions}
462 vnd[0-7]p[0-3]s[0-3])
463 # Vnode disk subpartition.
464 prefix=`expr ${dev} : '\\(.*\\)...'`
465 disk=`expr ${dev} : '...\\(.\\)'`
471 minor=`expr 128 + ${p} '*' 4 + ${s}`
473 makedev ${prefix}${p}s${s} b ${major} ${minor} \
474 ${uname} ${gname} ${permissions}
479 echo "$0: don
't know about ${dev}" >&2