Improve the process for GNU tools
[minix3.git] / minix / commands / DESCRIBE / DESCRIBE.sh
blobe826052abf56b78f56f55ec3f26759371d5f407e
1 #!/bin/sh
3 # DESCRIBE 2.2 - Describe the given devices. Author: Kees J. Bot
5 # BUGS
6 # - Arguments may not contain shell metacharacters.
8 case $# in
9 0) flag=; set -$- /dev ;;
10 *) flag=d ;;
11 esac
13 ls -l$flag $* | \
14 sed -e '/^total/d' \
15 -e '/^l/d' \
16 -e '/^[^bc]/s/.* /BAD BAD /' \
17 -e '/^[bc]/s/.* \([0-9][0-9]*\), *\([0-9][0-9]*\).* /\1 \2 /' \
18 | {
19 ex=0 # exit code
21 while read major minor path
23 case $path in
24 /*) name=`expr $path : '.*/\\(.*\\)$'`
26 *) name=$path
27 esac
28 dev= des=
30 case $major in # One of the controllers? What is its controller nr?
31 3) ctrlr=0 ;;
32 8) ctrlr=1 ;;
33 10) ctrlr=2 ;;
34 12) ctrlr=3 ;;
35 esac
37 case $major,$minor in
38 1,0) des="RAM disk" dev=ram
40 1,1) des="memory" dev=mem
42 1,2) des="kernel memory" dev=kmem
44 1,3) des="null device, data sink" dev=null
46 1,4) des="boot device loaded from boot image" dev=boot
48 1,5) des="null byte stream generator" dev=zero
50 1,6) des="boot image RAM disk" dev=imgrd
52 1,[789]|1,1[012])
53 ramdisk=`expr $minor - 7`
54 des="RAM disk $ramdisk" dev=ram$ramdisk
56 2,*) drive=`expr $minor % 4`
57 case `expr $minor - $drive` in
58 0) des='auto density' dev="fd$drive"
60 4) des='360k, 5.25"' dev="pc$drive"
62 8) des='1.2M, 5.25"' dev="at$drive"
64 12) des='360k in 720k, 5.25"' dev="qd$drive"
66 16) des='720k, 3.5"' dev="ps$drive"
68 20) des='360k in 1.2M, 5.25"' dev="pat$drive"
70 24) des='720k in 1.2M, 5.25"' dev="qh$drive"
72 28) des='1.44M, 3.5"' dev="PS$drive"
74 112) des='auto partition 0' dev="fd${drive}p0"
76 116) des='auto partition 1' dev="fd${drive}p1"
78 120) des='auto partition 2' dev="fd${drive}p2"
80 124) des='auto partition 3' dev="fd${drive}p3"
82 *) dev=BAD
83 esac
84 des="floppy drive $drive ($des)"
86 [38],[05]|[38],[123][05]|1[02],[05]|1[02],[123][05])
87 drive=`expr $minor / 5`
88 des="controller $ctrlr disk $drive" dev=c${ctrlr}d${drive}
90 [38],?|[38],[123]?|1[02],?|1[02],[123]?)
91 drive=`expr $minor / 5`
92 par=`expr $minor % 5 - 1`
93 des="controller $ctrlr disk $drive partition $par"
94 dev=c${ctrlr}d${drive}p${par}
96 [38],12[89]|[38],1[3-9]?|[38],2??|1[02],12[89]|1[02],1[3-9]?|1[02],2??)
97 drive=`expr \\( $minor - 128 \\) / 16`
98 par=`expr \\( \\( $minor - 128 \\) / 4 \\) % 4`
99 sub=`expr \\( $minor - 128 \\) % 4`
100 des="hard disk $drive, partition $par, subpartition $sub"
101 des="controller $ctrlr disk $drive partition $par slice $sub"
102 #par=`expr $drive '*' 5 + $par`
103 dev=c${ctrlr}d${drive}p${par}s${sub}
105 [38],6[4-9]|[38],7?|1[02],6[4-9]|1[02],7?)
106 tape=`expr \\( $minor - 64 \\) / 2`
107 case $minor in
108 *[02468])
109 des="controller $ctrlr tape $tape (non-rewinding)"
110 dev=c${ctrlr}t${tape}n
112 *[13579])
113 des="controller $ctrlr tape $tape (rewinding)"
114 dev=c${ctrlr}t${tape}
115 esac
117 4,0) des="console device" dev=console
119 4,[1-7])des="virtual console $minor" dev=ttyc$minor
121 4,15) des="diagnostics device" dev=log
123 4,1[6-9])
124 line=`expr $minor - 16`
125 des="serial line $line" dev=tty0$line
127 4,125) des="video output" dev=video
129 5,0) des="anonymous tty" dev=tty
131 6,0) des="line printer, parallel port" dev=lp
133 7,*)
134 d=`expr $minor % 8`
135 n=`expr $minor / 8`
136 case $d in
137 0) des="IP stat" dev=ipstat
139 1) case $name in
140 psip*)
141 des="Pseudo IP #$n" dev=psip
143 *) des="raw ethernet #$n" dev=eth
144 esac
146 2) des="raw IP #$n" dev=ip
148 3) des="TCP/IP #$n" dev=tcp
150 4) des="UDP #$n" dev=udp
151 esac
152 case $d in
153 [0123])
154 if [ "$name" = "$dev" ]
155 then
156 des="$des (default)"
157 else
158 dev=$dev$n
160 esac
162 9,0)
163 des="unix98 pseudoterminal master" dev=ptmx
165 9,12[89]|9,1[3-8]?|9,19[01])
166 p=`expr \\( $minor - 128 \\) / 16 | tr '0123' 'pqrs'`
167 n=`expr $minor % 16`
168 test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
169 des="pseudo tty `expr $minor - 128`" dev=tty$p$n
171 9,???)
172 p=`expr \\( $minor - 192 \\) / 16 | tr '0123' 'pqrs'`
173 n=`expr $minor % 16`
174 test $n -ge 10 && n=`expr $n - 10 | tr '012345' 'abcdef'`
175 des="controller of tty$p$n" dev=pty$p$n
177 11,0)
178 des="block filter" dev=filter
180 13,0)
181 des="audio" dev=audio
183 14,0)
184 des="faulty block device driver" dev=fbd
186 15,0)
187 des="kernel log" dev=klog
189 16,0)
190 des="pseudo random number generator" dev=urandom
192 17,0)
193 des="hello" dev=hello
195 18,0)
196 des="UNIX domain socket" dev=uds
198 5[6-9],0|6[0-3],0)
199 drive=`expr $major - 56`
200 des="vnode disk $drive" dev=vnd$drive
202 5[6-9],[1-4]|6[0-3],[1-4])
203 drive=`expr $major - 56`
204 par=`expr $minor - 1`
205 des="vnode disk $drive partition $par" dev=vnd${drive}p${par}
207 5[6-9],12[89]|5[6-9],13[0-9]|5[6-9],14[0-3]|6[0-3],12[89]|5[6-9],13[0-9]|5[6-9],14[0-3])
208 drive=`expr $major - 56`
209 par=`expr \\( \\( $minor - 128 \\) / 4 \\) % 4`
210 sub=`expr \\( $minor - 128 \\) % 4`
211 des="vnode disk $drive partition $par slice $sub"
212 dev=vnd${drive}p${par}s${sub}
214 64,0)
215 des="keyboard input multiplexer"
216 dev=kbdmux
218 64,[1-4])
219 n=`expr $minor - 1`
220 des="keyboard input $n"
221 dev=kbd$n
223 64,64)
224 des="mouse input multiplexer"
225 dev=mousemux
227 64,6[5-8])
228 n=`expr $minor - 65`
229 des="mouse input $n"
230 dev=mouse$n
232 BAD,BAD)
233 des= dev=
235 *) dev=BAD
236 esac
238 case $name:$dev in
240 echo "$path: not a device" >&2
241 ex=1
243 *:*BAD*)
244 echo "$path: cannot describe: major=$major, minor=$minor" >&2
245 ex=1
247 $dev:*)
248 echo "$path: $des"
250 *:*) echo "$path: nonstandard name for $dev: $des"
251 esac
252 done
254 exit $ex