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
35 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
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
52 vnd0 vnd0p0 vnd0p0s0 vnd1 vnd1p0 vnd1p0s0
53 vnd2 vnd3 vnd4 vnd5 vnd6 vnd7
56 #makedev ${dev} $type ${major} ${minor} ${uname} ${gname} ${permissions} [link_target]
57 #When called for a link, major and minor are ignored
60 # Check that all the arguments are there, we trust the caller to put
61 # values which make sens.
62 [ $# -eq 7 ] ||
[ $# -eq 8 ] ||
return 1;
75 l
) _type
=link
; _target
=$8;;
79 if [ ${MTREE} = "yes" ]
81 if [ ${_type} = "link" ]
83 echo .
/dev
/${_dev} type=${_type} \
84 uname
=${_uname} gname=${_gname} mode=${_mode} \
87 echo .
/dev
/${_dev} type=${_type} \
88 uname
=${_uname} gname=${_gname} mode=${_mode} \
89 device
=native
,${_major},${_minor}
92 if [ ${_type} = "link" ]
94 ${ECHO} ln -f ${_target} ${_dev}
96 ${ECHO} mknod ${_dev} ${__type} ${_major} ${_minor}
97 ${ECHO} chmod ${_mode} ${_dev}
98 ${ECHO} chown ${_uname}:${_gname} ${_dev}
107 Usage: $0 [-n|-m] [-s|-r] key ...
108 -n: print the commands instead of executing them
109 -m: print mtree(8) line
110 -s: standard set of devices
111 -r: reduced for ramdisk set of devices
113 Where key is one of the following:
114 ram mem kmem null boot zero # One of these makes all these memory devices
116 i2c-1 i2c-2 i2c-3 # Make /dev/i2c-[1-3]
117 tsl2550b{1,3}s39 # TSL2550 Ambient Light Sensors
118 sht21b{1,3}s40 # SHT21 Relative Humidity and Temperature Sensors
119 bmp085b{1,3}s77 # BMP085 Pressure and Temperature Sensors
120 fd0 fd1 ... # Floppy devices for drive 0, 1, ...
121 fd0p0 fd1p0 ... # Make floppy partitions fd0p[0-3], fd1p[0-3], ...
122 c0d0 c0d1 ... # Make disks c0d0, c0d1, ...
123 c0d0p0 c0d1p0 ... # Make partitions c0d0p[0-3], c0d1p[0-3], ...
124 c0d0p0s0 c0d1p0s0 ... # Subparts c0d0p[0-3]s[0-3], c0d1p[0-3]s[0-3], ...
125 c1d0(p0)(s0) # Likewise for controller 1
126 c0t0 c0t1 c1t0 ... # Make tape devices c0t0, c0t0n, c0t1, ...
127 console lp tty log # One of these makes all four
128 ttyc1 ... ttyc7 # Virtual consoles
129 tty00 ... tty03 # Make serial lines
130 ttyp0 ... ttyq0 ... # Make tty, pty pairs
131 audio mixer # Make audio devices
133 klog # Make /dev/klog
134 ptmx # Make /dev/ptmx
135 random # Make /dev/random, /dev/urandom
136 filter # Make /dev/filter
138 hello # Make /dev/hello
139 video # Make /dev/video
141 vnd0 vnd0p0 vnd0p0s0 .. # Make vnode disks /dev/vnd[0-7] and (sub)partitions
142 input # Make /dev/kbdmux, /dev/kbd[0-3], idem /dev/mouse~
148 while getopts "nmrs" arg
169 if [ ${STD} = "yes" ]
171 DEVICES
=${STD_DEVICES}
172 elif [ ${RAMDISK} = "yes" ]
174 DEVICES
=${RAMDISK_DEVICES}
176 while [ $OPTIND -gt 1 ]
179 OPTIND
=$
((${OPTIND} - 1))
183 DEVICES
="${DEVICES} $1"
188 for dev
in ${DEVICES}
200 vnd
*) # Whole vnode disk devices.
201 disk
=`expr ${dev} : '...\\(.\\)'`
202 major
=`expr ${disk} + 56`
206 # The following is lexicographicaly ordered
210 makedev audio c
13 0 ${uname} ${gname} 666
211 makedev mixer c
13 1 ${uname} ${gname} 666
214 # Weather Cape: temperature & pressure sensor
215 bus
=`expr ${dev} : 'bmp085b\\(.*\\)s77'` #bus number
216 major
=`expr ${bus} + 52`
218 makedev bmp085b
${bus}s77 c ${major} 0 ${uname} ${gname} 444
221 # Berkeley Packet Filter device, for the LWIP service
222 # This is a cloning device, but some programs (e.g., dhclient)
223 # assume individual devices are numbered, so also create bpf0.
224 makedev
${dev} c 7 0 ${uname} ${gname} 600
225 makedev
${dev}0 c 7 0 ${uname} ${gname} 600
228 # Whole disk devices.
229 disk
=`expr ${dev} : '...\\(.\\)'`
230 minor
=`expr ${disk} '*' 5`
232 makedev
${dev} b ${major} ${minor} ${uname} ${gname} ${permissions}
235 # Disk primary partitions.
236 prefix
=`expr ${dev} : '\\(.*\\).'`
237 disk
=`expr ${dev} : '...\\(.\\)'`
241 minor
=`expr ${disk} '*' 5 + 1 + ${p}`
242 makedev
${prefix}${p} b ${major} ${minor} \
243 ${uname} ${gname} ${permissions}
246 c
[0-3]d
[0-7]p
[0-3]s
[0-3])
248 prefix
=`expr ${dev} : '\\(.*\\)...'`
249 disk
=`expr ${dev} : '...\\(.\\)'`
255 minor
=`expr 128 + ${disk} '*' 16 + ${p} '*' 4 + ${s}`
256 makedev
${prefix}${p}s${s} b ${major} ${minor} \
257 ${uname} ${gname} ${permissions}
261 c
[0-3]t
[0-7]|c
[0-3]t
[0-7]n
)
263 prefix
=`expr ${dev} : '\\(....\\)'`
264 tape
=`expr ${dev} : '...\\(.\\)'`
265 minor
=`expr 64 + ${tape} '*' 2`
267 makedev
${prefix}n c ${major} ${minor} ${uname} ${gname} 660
268 makedev
${prefix} c ${major} `expr ${minor} + 1` ${uname} ${gname} 660
270 console|
lp|tty|log|video
)
271 # Console, line printer, anonymous tty, diagnostics device, video.
272 makedev console c
4 0 ${uname} tty
${permissions}
273 makedev tty c
5 0 ${uname} ${gname} 666
274 makedev
lp c
6 0 daemon daemon
200
275 makedev log c
4 15 ${uname} ${gname} 222
276 makedev video c
4 125 ${uname} ${gname} ${permissions}
280 bus
=`expr ${dev} : 'eepromb\\(.*\\)s'`
281 # configurable part of slave addr
282 slave_low
=`expr ${dev} : 'eepromb.s5\\(.*\\)'`
283 major
=`expr ${bus} '*' 8 + ${slave_low} + 17`
285 makedev eepromb
${bus}s5${slave_low} b ${major} 0 ${uname} ${gname} ${permissions}
289 makedev
${dev} c 19 0 ${uname} ${gname} 644
292 # Faulty block device driver
293 makedev
${dev} b 14 0 ${uname} ${gname} ${permissions}
296 # Floppy disk drive N has minor N.
297 minor
=`expr ${dev} : '..\\(.\\)'`
299 makedev
${dev} b 2 ${minor} ${uname} ${gname} 666
302 # Floppy disk partitions.
303 prefix
=`expr ${dev} : '\\(.*\\).'`
304 drive
=`expr ${dev} : '..\\(.\\)'`
308 minor
=`expr 112 + ${drive} + ${p} '*' 4`
309 makedev
${prefix}${p} b 2 ${minor} \
310 ${uname} ${gname} 666
315 makedev
${dev} b 11 0 ${uname} ${gname} ${permissions}
319 makedev
${dev} c 17 0 ${uname} ${gname} 644
323 bus
=`expr ${dev} : '....\\(.*\\)'` # bus number
324 # least significant digit of major
325 major_low
=`expr ${dev} : '....\\(.*\\)'`
326 major_low
=`expr ${major_low} - 1`
328 makedev
"i2c-${bus}" c 2${major_low} 0 ${uname} ${gname} ${permissions}
332 makedev kbdmux c 64 0 ${uname} ${gname} ${permissions}
333 makedev mousemux c 64 64 ${uname} ${gname} ${permissions}
337 minor_keyboard=`expr ${n} + 1`
338 minor_mouse=`expr ${n} + 65`
340 makedev kbd${n} c 64 ${minor_keyboard} ${uname} ${gname} ${permissions}
341 makedev mouse${n} c 64 ${minor_mouse} ${uname} ${gname} ${permissions}
346 makedev ${dev} c 15 0 ${uname} ${gname} ${permissions}
348 pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3])
349 # Obsolete density locked floppy disk drive n.
350 drive=`expr ${dev} : '.*\\(.\\)'`
353 for prefix in pc at qd ps pat qh PS
355 makedev ${prefix}${drive} b 2 ${minor} \
356 ${uname} ${gname} 666
357 minor=`expr ${minor} + 4`
361 # PCI server, manages PCI buses
362 makedev pci c 134 0 ${uname} ${gname} ${permissions}
365 # Unix98 pseudoterminal master
366 makedev ptmx c 9 0 ${uname} tty 666
368 ram|mem|kmem|null|boot|zero|imgrd)
370 makedev ram b 1 0 ${uname} kmem ${permissions}
371 makedev mem c 1 1 ${uname} kmem 640
372 makedev kmem c 1 2 ${uname} kmem 640
373 makedev null c 1 3 ${uname} kmem 666
374 makedev boot b 1 4 ${uname} kmem ${permissions}
375 makedev zero c 1 5 ${uname} kmem 644
376 makedev imgrd b 1 6 ${uname} kmem ${permissions}
380 minor=`expr ${n} + 7`
382 makedev ram${n} b 1 ${minor} ${uname} kmem ${permissions}
386 # Random data generator.
387 makedev random c 16 0 ${uname} ${gname} 644
388 makedev urandom c 16 0 ${uname} ${gname} 644
391 # Weather Cape: relative humidity & temperature sensor
392 bus=`expr ${dev} : 'sht21b\\(.*\\)s40'`
393 major=`expr ${bus} + 49`
395 makedev sht21b${bus}s40 c ${major} 0 ${uname} ${gname} 444
398 # Weather Cape: ambient light sensor
399 bus=`expr ${dev} : 'tsl2550b\\(.*\\)s39'`
400 major=`expr ${bus} + 46`
402 makedev tsl2550b${bus}s39 c ${major} 0 ${uname} ${gname} 444
406 line=`expr ${dev} : '.*\\(.\\)'`
407 minor=`expr ${line} + 16`
409 makedev ${dev} c 4 ${minor} ${uname} tty 666
411 tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
413 dev=`expr ${dev} : '...\\(..\\)'`
414 group=`expr ${dev} : '\\(.\\)'`
415 group=`echo ${group} | tr 'pqrs' '0123'`
416 pty=`expr ${dev} : '.\\(.\\)'`
418 [a-f]) pty=1`/bin/echo ${pty} | tr 'abcdef' '012345'`
420 minor_tty=`expr ${group} '*' 16 + ${pty} + 128`
421 minor_pty=`expr ${group} '*' 16 + ${pty} + 192`
423 makedev tty${dev} c 9 ${minor_tty} ${uname} tty 666
424 makedev pty${dev} c 9 ${minor_pty} ${uname} tty 666
428 minor=`expr ${dev} : '....\\(.*\\)'`
430 makedev ${dev} c 4 ${minor} ${uname} tty ${permissions}
433 # Whole vnode disk devices.
434 makedev ${dev} b ${major} 0 ${uname} ${gname} ${permissions}
437 # Vnode disk primary partitions.
438 prefix=`expr ${dev} : '\\(.*\\).'`
439 disk=`expr ${dev} : '...\\(.\\)'`
443 minor=`expr 1 + ${p}`
445 makedev ${prefix}${p} b ${major} ${minor} \
446 ${uname} ${gname} ${permissions}
449 vnd[0-7]p[0-3]s[0-3])
450 # Vnode disk subpartition.
451 prefix=`expr ${dev} : '\\(.*\\)...'`
452 disk=`expr ${dev} : '...\\(.\\)'`
458 minor=`expr 128 + ${p} '*' 4 + ${s}`
460 makedev ${prefix}${p}s${s} b ${major} ${minor} \
461 ${uname} ${gname} ${permissions}
466 echo "$0: don
't know about ${dev}" >&2