Remove building with NOCRYPTO option
[minix3.git] / minix / commands / MAKEDEV / MAKEDEV.sh
blob4039a0114e7fb090000673ce0974c377d89140f0
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 STD_DEVICES="
34 ${RAMDISK_DEVICES}
35 bmp085b1s77 bmp085b2s77 bmp085b3s77
36 bpf
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 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 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
58 makedev()
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;
64 local _dev=$1
65 local __type=$2
66 local _major=$3
67 local _minor=$4
68 local _uname=$5
69 local _gname=$6
70 local _mode=$7
72 case ${__type} in
73 b)_type=block;;
74 c) _type=char;;
75 l) _type=link; _target=$8;;
76 *) return 2;;
77 esac
79 if [ ${MTREE} = "yes" ]
80 then
81 if [ ${_type} = "link" ]
82 then
83 echo ./dev/${_dev} type=${_type} \
84 uname=${_uname} gname=${_gname} mode=${_mode} \
85 link=${_target}
86 else
87 echo ./dev/${_dev} type=${_type} \
88 uname=${_uname} gname=${_gname} mode=${_mode} \
89 device=native,${_major},${_minor}
91 else
92 if [ ${_type} = "link" ]
93 then
94 ${ECHO} ln -f ${_target} ${_dev}
95 else
96 ${ECHO} mknod ${_dev} ${__type} ${_major} ${_minor}
97 ${ECHO} chmod ${_mode} ${_dev}
98 ${ECHO} chown ${_uname}:${_gname} ${_dev}
103 # no_return usage()
104 usage()
106 cat >&2 <<EOF
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
115 fb0 # Make /dev/fb0
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
132 bpf # Make /dev/bpf
133 klog # Make /dev/klog
134 ptmx # Make /dev/ptmx
135 random # Make /dev/random, /dev/urandom
136 filter # Make /dev/filter
137 fbd # Make /dev/fbd
138 hello # Make /dev/hello
139 video # Make /dev/video
140 pci # Make /dev/pci
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~
144 exit 1
147 # Parse options
148 while getopts "nmrs" arg
150 case "$arg" in
152 ECHO=echo
155 MTREE=yes
158 RAMDISK=yes
161 STD=yes
163 h|\?)
164 usage
166 esac
167 done
169 if [ ${STD} = "yes" ]
170 then
171 DEVICES=${STD_DEVICES}
172 elif [ ${RAMDISK} = "yes" ]
173 then
174 DEVICES=${RAMDISK_DEVICES}
175 else
176 while [ $OPTIND -gt 1 ]
178 shift
179 OPTIND=$((${OPTIND} - 1))
180 done
181 while [ ! -z "$1" ]
183 DEVICES="${DEVICES} $1"
184 shift
185 done
188 for dev in ${DEVICES}
190 # Reset the defaults
191 uname=root
192 gname=wheel
193 permissions=600
195 case ${dev} in
196 c0*) major=3 ;;
197 c1*) major=8 ;;
198 c2*) major=10 ;;
199 c3*) major=12 ;;
200 vnd*) # Whole vnode disk devices.
201 disk=`expr ${dev} : '...\\(.\\)'`
202 major=`expr ${disk} + 56`
204 esac
206 # The following is lexicographicaly ordered
207 case ${dev} in
208 audio|mixer)
209 # Audio devices.
210 makedev audio c 13 0 ${uname} ${gname} 666
211 makedev mixer c 13 1 ${uname} ${gname} 666
213 bmp085b[1-3]s77)
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
220 bpf)
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
227 c[0-3]d[0-7])
228 # Whole disk devices.
229 disk=`expr ${dev} : '...\\(.\\)'`
230 minor=`expr ${disk} '*' 5`
232 makedev ${dev} b ${major} ${minor} ${uname} ${gname} ${permissions}
234 c[0-3]d[0-7]p[0-3])
235 # Disk primary partitions.
236 prefix=`expr ${dev} : '\\(.*\\).'`
237 disk=`expr ${dev} : '...\\(.\\)'`
239 for p in 0 1 2 3
241 minor=`expr ${disk} '*' 5 + 1 + ${p}`
242 makedev ${prefix}${p} b ${major} ${minor} \
243 ${uname} ${gname} ${permissions}
244 done
246 c[0-3]d[0-7]p[0-3]s[0-3])
247 # Disk subpartition.
248 prefix=`expr ${dev} : '\\(.*\\)...'`
249 disk=`expr ${dev} : '...\\(.\\)'`
251 for p in 0 1 2 3
253 for s in 0 1 2 3
255 minor=`expr 128 + ${disk} '*' 16 + ${p} '*' 4 + ${s}`
256 makedev ${prefix}${p}s${s} b ${major} ${minor} \
257 ${uname} ${gname} ${permissions}
258 done
259 done
261 c[0-3]t[0-7]|c[0-3]t[0-7]n)
262 # Tape devices.
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}
278 eepromb[1-3]s5[0-7])
279 # cat24c256 driver
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}
287 fb0)
288 # Framebuffer driver
289 makedev ${dev} c 19 0 ${uname} ${gname} 644
291 fbd)
292 # Faulty block device driver
293 makedev ${dev} b 14 0 ${uname} ${gname} ${permissions}
295 fd[0-3])
296 # Floppy disk drive N has minor N.
297 minor=`expr ${dev} : '..\\(.\\)'`
299 makedev ${dev} b 2 ${minor} ${uname} ${gname} 666
301 fd[0-3]p[0-3])
302 # Floppy disk partitions.
303 prefix=`expr ${dev} : '\\(.*\\).'`
304 drive=`expr ${dev} : '..\\(.\\)'`
306 for p in 0 1 2 3
308 minor=`expr 112 + ${drive} + ${p} '*' 4`
309 makedev ${prefix}${p} b 2 ${minor} \
310 ${uname} ${gname} 666
311 done
313 filter)
314 # Filter driver
315 makedev ${dev} b 11 0 ${uname} ${gname} ${permissions}
317 hello)
318 # Hello driver
319 makedev ${dev} c 17 0 ${uname} ${gname} 644
321 i2c-[1-3])
322 # i2c driver
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}
330 input)
331 # Input server
332 makedev kbdmux c 64 0 ${uname} ${gname} ${permissions}
333 makedev mousemux c 64 64 ${uname} ${gname} ${permissions}
335 for n in 0 1 2 3
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}
342 done
344 klog)
345 # Logging device.
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} : '.*\\(.\\)'`
351 minor=${drive}
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`
358 done
360 pci)
361 # PCI server, manages PCI buses
362 makedev pci c 134 0 ${uname} ${gname} ${permissions}
364 ptmx)
365 # Unix98 pseudoterminal master
366 makedev ptmx c 9 0 ${uname} tty 666
368 ram|mem|kmem|null|boot|zero|imgrd)
369 # Memory devices.
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}
378 for n in 0 1 2 3 4 5
380 minor=`expr ${n} + 7`
382 makedev ram${n} b 1 ${minor} ${uname} kmem ${permissions}
383 done
385 random|urandom)
386 # Random data generator.
387 makedev random c 16 0 ${uname} ${gname} 644
388 makedev urandom c 16 0 ${uname} ${gname} 644
390 sht21b[1-3]s40)
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
397 tsl2550b[1-3]s39)
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
404 tty0[0-3])
405 # Serial lines.
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])
412 # Pseudo ttys.
413 dev=`expr ${dev} : '...\\(..\\)'`
414 group=`expr ${dev} : '\\(.\\)'`
415 group=`echo ${group} | tr 'pqrs' '0123'`
416 pty=`expr ${dev} : '.\\(.\\)'`
417 case ${pty} in
418 [a-f]) pty=1`/bin/echo ${pty} | tr 'abcdef' '012345'`
419 esac
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
426 ttyc[1-7])
427 # Virtual consoles.
428 minor=`expr ${dev} : '....\\(.*\\)'`
430 makedev ${dev} c 4 ${minor} ${uname} tty ${permissions}
432 vnd[0-7])
433 # Whole vnode disk devices.
434 makedev ${dev} b ${major} 0 ${uname} ${gname} ${permissions}
436 vnd[0-7]p[0-3])
437 # Vnode disk primary partitions.
438 prefix=`expr ${dev} : '\\(.*\\).'`
439 disk=`expr ${dev} : '...\\(.\\)'`
441 for p in 0 1 2 3
443 minor=`expr 1 + ${p}`
445 makedev ${prefix}${p} b ${major} ${minor} \
446 ${uname} ${gname} ${permissions}
447 done
449 vnd[0-7]p[0-3]s[0-3])
450 # Vnode disk subpartition.
451 prefix=`expr ${dev} : '\\(.*\\)...'`
452 disk=`expr ${dev} : '...\\(.\\)'`
454 for p in 0 1 2 3
456 for s in 0 1 2 3
458 minor=`expr 128 + ${p} '*' 4 + ${s}`
460 makedev ${prefix}${p}s${s} b ${major} ${minor} \
461 ${uname} ${gname} ${permissions}
462 done
463 done
466 echo "$0: don't know about ${dev}" >&2
467 EXIT=1
468 esac
469 done
471 exit $EXIT