Improve the process for GNU tools
[minix3.git] / minix / commands / MAKEDEV / MAKEDEV.sh
blob81330b6fa8032859d6842f531fe5a0bccb9e76f0
1 #!/bin/sh
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
6 umask 077
8 MTREE=false
9 STD=false
10 RAMDISK=false
11 ECHO=
12 EXIT=0
14 # console => lp tty log
15 # boot => kmem mem null ram zero
16 RAMDISK_DEVICES="
17 boot
18 console
19 input
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
28 fd0 fd1 fd0p0 fd1p0
29 pci
30 ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03
33 #eth => ip tcp udp
34 STD_DEVICES="
35 ${RAMDISK_DEVICES}
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
44 i2c-1 i2c-2 i2c-3
45 klog ptmx random
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 uds
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
59 makedev()
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;
65 local _dev=$1
66 local __type=$2
67 local _major=$3
68 local _minor=$4
69 local _uname=$5
70 local _gname=$6
71 local _mode=$7
73 case ${__type} in
74 b)_type=block;;
75 c) _type=char;;
76 l) _type=link; _target=$8;;
77 *) return 2;;
78 esac
80 if [ ${MTREE} = "yes" ]
81 then
82 if [ ${_type} = "link" ]
83 then
84 echo ./dev/${_dev} type=${_type} \
85 uname=${_uname} gname=${_gname} mode=${_mode} \
86 link=${_target}
87 else
88 echo ./dev/${_dev} type=${_type} \
89 uname=${_uname} gname=${_gname} mode=${_mode} \
90 device=native,${_major},${_minor}
92 else
93 if [ ${_type} = "link" ]
94 then
95 ${ECHO} ln -f ${_target} ${_dev}
96 else
97 ${ECHO} mknod ${_dev} ${__type} ${_major} ${_minor}
98 ${ECHO} chmod ${_mode} ${_dev}
99 ${ECHO} chown ${_uname}:${_gname} ${_dev}
104 # no_return usage()
105 usage()
107 cat >&2 <<EOF
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
116 fb0 # Make /dev/fb0
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
137 uds # Make /dev/uds
138 filter # Make /dev/filter
139 fbd # Make /dev/fbd
140 hello # Make /dev/hello
141 video # Make /dev/video
142 pci # Make /dev/pci
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~
146 exit 1
149 # Parse options
150 while getopts "nmrs" arg
152 case "$arg" in
154 ECHO=echo
157 MTREE=yes
160 RAMDISK=yes
163 STD=yes
165 h|\?)
166 usage
168 esac
169 done
171 if [ ${STD} = "yes" ]
172 then
173 DEVICES=${STD_DEVICES}
174 elif [ ${RAMDISK} = "yes" ]
175 then
176 DEVICES=${RAMDISK_DEVICES}
177 else
178 while [ $OPTIND -gt 1 ]
180 shift
181 OPTIND=$((${OPTIND} - 1))
182 done
183 while [ ! -z "$1" ]
185 DEVICES="${DEVICES} $1"
186 shift
187 done
190 for dev in ${DEVICES}
192 # Reset the defaults
193 uname=root
194 gname=operator
195 permissions=600
197 case ${dev} in
198 c0*) major=3 ;;
199 c1*) major=8 ;;
200 c2*) major=10 ;;
201 c3*) major=12 ;;
202 vnd*) # Whole vnode disk devices.
203 disk=`expr ${dev} : '...\\(.\\)'`
204 major=`expr ${disk} + 56`
206 esac
208 # The following is lexicographicaly ordered
209 case ${dev} in
210 audio|mixer)
211 # Audio devices.
212 makedev audio c 13 0 ${uname} ${gname} 666
213 makedev mixer c 13 1 ${uname} ${gname} 666
215 bmp085b[1-3]s77)
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
222 c[0-3]d[0-7])
223 # Whole disk devices.
224 disk=`expr ${dev} : '...\\(.\\)'`
225 minor=`expr ${disk} '*' 5`
227 makedev ${dev} b ${major} ${minor} ${uname} ${gname} ${permissions}
229 c[0-3]d[0-7]p[0-3])
230 # Disk primary partitions.
231 prefix=`expr ${dev} : '\\(.*\\).'`
232 disk=`expr ${dev} : '...\\(.\\)'`
234 for p in 0 1 2 3
236 minor=`expr ${disk} '*' 5 + 1 + ${p}`
237 makedev ${prefix}${p} b ${major} ${minor} \
238 ${uname} ${gname} ${permissions}
239 done
241 c[0-3]d[0-7]p[0-3]s[0-3])
242 # Disk subpartition.
243 prefix=`expr ${dev} : '\\(.*\\)...'`
244 disk=`expr ${dev} : '...\\(.\\)'`
246 for p in 0 1 2 3
248 for s in 0 1 2 3
250 minor=`expr 128 + ${disk} '*' 16 + ${p} '*' 4 + ${s}`
251 makedev ${prefix}${p}s${s} b ${major} ${minor} \
252 ${uname} ${gname} ${permissions}
253 done
254 done
256 c[0-3]t[0-7]|c[0-3]t[0-7]n)
257 # Tape devices.
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}
273 eepromb[1-3]s5[0-7])
274 # cat24c256 driver
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)
283 # TCP/IP devices.
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
290 # Default interface
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
296 fb0)
297 # Framebuffer driver
298 makedev ${dev} c 19 0 ${uname} ${gname} 644
300 fbd)
301 # Faulty block device driver
302 makedev ${dev} b 14 0 ${uname} ${gname} ${permissions}
304 fd[0-3])
305 # Floppy disk drive N has minor N.
306 minor=`expr ${dev} : '..\\(.\\)'`
308 makedev ${dev} b 2 ${minor} ${uname} ${gname} 666
310 fd[0-3]p[0-3])
311 # Floppy disk partitions.
312 prefix=`expr ${dev} : '\\(.*\\).'`
313 drive=`expr ${dev} : '..\\(.\\)'`
315 for p in 0 1 2 3
317 minor=`expr 112 + ${drive} + ${p} '*' 4`
318 makedev ${prefix}${p} b 2 ${minor} \
319 ${uname} ${gname} 666
320 done
322 filter)
323 # Filter driver
324 makedev ${dev} b 11 0 ${uname} ${gname} ${permissions}
326 hello)
327 # Hello driver
328 makedev ${dev} c 17 0 ${uname} ${gname} 644
330 i2c-[1-3])
331 # i2c driver
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}
339 input)
340 # Input server
341 makedev kbdmux c 64 0 ${uname} ${gname} ${permissions}
342 makedev mousemux c 64 64 ${uname} ${gname} ${permissions}
344 for n in 0 1 2 3
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}
351 done
353 klog)
354 # Logging device.
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} : '.*\\(.\\)'`
360 minor=${drive}
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`
367 done
369 pci)
370 # PCI server, manages PCI buses
371 makedev pci c 134 0 ${uname} ${gname} ${permissions}
373 ptmx)
374 # Unix98 pseudoterminal master
375 makedev ptmx c 9 0 ${uname} tty 666
377 ram|mem|kmem|null|boot|zero|imgrd)
378 # Memory devices.
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}
387 for n in 0 1 2 3 4 5
389 minor=`expr ${n} + 7`
391 makedev ram${n} b 1 ${minor} ${uname} kmem ${permissions}
392 done
394 random|urandom)
395 # Random data generator.
396 makedev random c 16 0 ${uname} ${gname} 644
397 makedev urandom c 16 0 ${uname} ${gname} 644
399 sht21b[1-3]s40)
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
406 tsl2550b[1-3]s39)
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
413 tty0[0-3])
414 # Serial lines.
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])
421 # Pseudo ttys.
422 dev=`expr ${dev} : '...\\(..\\)'`
423 group=`expr ${dev} : '\\(.\\)'`
424 group=`echo ${group} | tr 'pqrs' '0123'`
425 pty=`expr ${dev} : '.\\(.\\)'`
426 case ${pty} in
427 [a-f]) pty=1`/bin/echo ${pty} | tr 'abcdef' '012345'`
428 esac
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
435 ttyc[1-7])
436 # Virtual consoles.
437 minor=`expr ${dev} : '....\\(.*\\)'`
439 makedev ${dev} c 4 ${minor} ${uname} tty ${permissions}
441 uds)
442 # Unix domain sockets device
443 makedev ${dev} c 18 0 ${uname} ${gname} 666
445 vnd[0-7])
446 # Whole vnode disk devices.
447 makedev ${dev} b ${major} 0 ${uname} ${gname} ${permissions}
449 vnd[0-7]p[0-3])
450 # Vnode disk primary partitions.
451 prefix=`expr ${dev} : '\\(.*\\).'`
452 disk=`expr ${dev} : '...\\(.\\)'`
454 for p in 0 1 2 3
456 minor=`expr 1 + ${p}`
458 makedev ${prefix}${p} b ${major} ${minor} \
459 ${uname} ${gname} ${permissions}
460 done
462 vnd[0-7]p[0-3]s[0-3])
463 # Vnode disk subpartition.
464 prefix=`expr ${dev} : '\\(.*\\)...'`
465 disk=`expr ${dev} : '...\\(.\\)'`
467 for p in 0 1 2 3
469 for s in 0 1 2 3
471 minor=`expr 128 + ${p} '*' 4 + ${s}`
473 makedev ${prefix}${p}s${s} b ${major} ${minor} \
474 ${uname} ${gname} ${permissions}
475 done
476 done
479 echo "$0: don't know about ${dev}" >&2
480 EXIT=1
481 esac
482 done
484 exit $EXIT