unstack - fix ipcvecs
[minix.git] / commands / MAKEDEV / MAKEDEV.sh
blob43f547b3fd0083218a45b0a7cd0f9ca792dd5e24
1 #!/bin/sh
3 # MAKEDEV 3.3 - Make special devices. Author: Kees J. Bot
5 case $1 in
6 -n) e=echo; shift ;; # Just echo when -n is given.
7 *) e=
8 esac
10 case $#:$1 in
11 1:std) # Standard devices.
12 set -$- mem fd0 fd1 fd0p0 fd1p0 \
13 c0d0 c0d0p0 c0d0p0s0 c0d1 c0d1p0 c0d1p0s0 \
14 c0d2 c0d2p0 c0d2p0s0 c0d3 c0d3p0 c0d3p0s0 \
15 c0d4 c0d4p0 c0d4p0s0 c0d5 c0d5p0 c0d5p0s0 \
16 c0d6 c0d6p0 c0d6p0s0 c0d7 c0d7p0 c0d7p0s0 \
17 c1d0 c1d0p0 c1d0p0s0 c1d1 c1d1p0 c1d1p0s0 \
18 c1d2 c1d2p0 c1d2p0s0 c1d3 c1d3p0 c1d3p0s0 \
19 c1d4 c1d4p0 c1d4p0s0 c1d5 c1d5p0 c1d5p0s0 \
20 c1d6 c1d6p0 c1d6p0s0 c1d7 c1d7p0 c1d7p0s0 \
21 tty ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03 \
22 ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9 \
23 ttypa ttypb ttypc ttypd ttype ttypf \
24 ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9 \
25 ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf \
26 eth klog random uds filter fbd hello
28 0:|1:-\?)
29 cat >&2 <<EOF
30 Usage: $0 [-n] key ...
31 Where key is one of the following:
32 ram mem kmem null boot zero # One of these makes all these memory devices
33 fd0 fd1 ... # Floppy devices for drive 0, 1, ...
34 fd0p0 fd1p0 ... # Make floppy partitions fd0p[0-3], fd1p[0-3], ...
35 c0d0 c0d1 ... # Make disks c0d0, c0d1, ...
36 c0d0p0 c0d1p0 ... # Make partitions c0d0p[0-3], c0d1p[0-3], ...
37 c0d0p0s0 c0d1p0s0 ... # Subparts c0d0p[0-3]s[0-3], c0d1p[0-3]s[0-3], ...
38 c1d0(p0)(s0) # Likewise for controller 1
39 c0t0 c0t1 c1t0 ... # Make tape devices c0t0, c0t0n, c0t1, ...
40 console lp tty log # One of these makes all four
41 ttyc1 ... ttyc7 # Virtual consoles
42 tty00 ... tty03 # Make serial lines
43 ttyp0 ... ttyq0 ... # Make tty, pty pairs
44 eth ip tcp udp # One of these makes some TCP/IP devices
45 audio mixer # Make audio devices
46 klog # Make /dev/klog
47 random # Make /dev/random, /dev/urandom
48 uds # Make /dev/uds
49 kbd # Make /dev/kbd
50 kbdaux # Make /dev/kbdaux
51 filter # Make /dev/filter
52 fbd # Make /dev/fbd
53 hello # Make /dev/hello
54 video # Make /dev/video
55 std # All standard devices
56 EOF
57 exit 1
58 esac
60 umask 077
61 ex=0
63 for dev
65 case $dev in # One of the controllers? Precompute major device nr.
66 c0*) maj=3 ;;
67 c1*) maj=8 ;;
68 c2*) maj=10 ;;
69 c3*) maj=12 ;;
70 esac
72 case $dev in
73 ram|mem|kmem|null|boot|zero|imgrd)
74 # Memory devices.
76 $e mknod ram b 1 0; $e chmod 600 ram
77 $e mknod mem c 1 1; $e chmod 640 mem
78 $e mknod kmem c 1 2; $e chmod 640 kmem
79 $e mknod null c 1 3; $e chmod 666 null
80 $e mknod boot b 1 4; $e chmod 600 ram
81 $e mknod zero c 1 5; $e chmod 644 zero
82 $e mknod imgrd b 1 6; $e chmod 644 zero
83 for n in 0 1 2 3 4 5
84 do $e mknod ram$n b 1 $((7+$n)); $e chmod 600 ram$n
85 done
86 $e chgrp kmem ram* mem kmem null boot zero imgrd
88 fd[0-3])
89 # Floppy disk drive n.
91 d=`expr $dev : '.*\\(.\\)'` # Drive number.
92 $e mknod $dev b 2 $d
93 $e chmod 666 $dev
95 pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3])
96 # Obsolete density locked floppy disk drive n.
98 d=`expr $dev : '.*\\(.\\)'` # Drive number.
99 m=$d # Minor device number.
101 $e mknod pc$d b 2 $m; m=`expr $m + 4`
102 $e mknod at$d b 2 $m; m=`expr $m + 4`
103 $e mknod qd$d b 2 $m; m=`expr $m + 4`
104 $e mknod ps$d b 2 $m; m=`expr $m + 4`
105 $e mknod pat$d b 2 $m; m=`expr $m + 4`
106 $e mknod qh$d b 2 $m; m=`expr $m + 4`
107 $e mknod PS$d b 2 $m; m=`expr $m + 4`
109 $e chmod 666 pc$d at$d qd$d ps$d pat$d qh$d PS$d
111 fd[0-3]p[0-3])
112 # Floppy disk partitions.
114 n=`expr $dev : '\\(.*\\)..'` # Name prefix.
115 d=`expr $dev : '..\\(.\\)'` # Drive number.
116 m=`expr 112 + $d` # Minor of partition 0.
117 alldev=
119 for p in 0 1 2 3
121 m=`expr 112 + $d + $p '*' 4` # Minor of partition $p.
122 $e mknod ${n}p${p} b 2 $m # Make e.g. fd0p0 - fd0p3
123 alldev="$alldev ${n}p${p}"
124 done
125 $e chmod 666 $alldev
127 c[0-3]d[0-7])
128 # Whole disk devices.
129 d=`expr $dev : '...\\(.\\)'` # Disk number.
130 m=`expr $d '*' 5` # Minor device number.
131 $e mknod $dev b $maj $m
132 $e chmod 600 $dev
134 c[0-3]d[0-7]p[0-3])
135 # Disk primary partitions.
136 n=`expr $dev : '\\(.*\\).'` # Name prefix.
137 d=`expr $dev : '...\\(.\\)'` # Disk number.
138 alldev=
140 for p in 0 1 2 3
142 m=`expr $d '*' 5 + 1 + $p` # Minor device number.
143 $e mknod $n$p b $maj $m
144 alldev="$alldev $n$p"
145 done
146 echo $alldev | xargs $e chmod 600
148 c[0-3]d[0-7]p[0-3]s[0-3])
149 # Disk subpartition.
150 n=`expr $dev : '\\(.*\\)...'` # Name prefix.
151 d=`expr $dev : '...\\(.\\)'` # Disk number.
152 alldev=
154 for p in 0 1 2 3
156 for s in 0 1 2 3
158 m=`expr 128 + $d '*' 16 + $p '*' 4 + $s` # Minor device nr.
159 $e mknod ${n}${p}s${s} b $maj $m
160 alldev="$alldev ${n}${p}s${s}"
161 done
162 done
163 echo $alldev | xargs $e chmod 600
165 c[0-3]t[0-7]|c[0-3]t[0-7]n)
166 # Tape devices.
167 n=`expr $dev : '\\(....\\)'` # Name prefix.
168 t=`expr $dev : '...\\(.\\)'` # Tape number.
169 m=`expr 64 + $t '*' 2` # Minor device number.
170 $e mknod ${n}n c $maj $m
171 $e mknod ${n} c $maj `expr $m + 1`
172 $e chmod 660 ${n}n ${n}
174 console|lp|tty|log|kbd|kbdaux|video)
175 # Console, line printer, anonymous tty, diagnostics device,
176 # raw keyboard, ps/2 mouse, video.
177 $e mknod console c 4 0
178 $e chmod 600 console
179 $e chgrp tty console
180 $e mknod tty c 5 0
181 $e chmod 666 tty
182 $e mknod lp c 6 0
183 $e chown daemon lp
184 $e chgrp daemon lp
185 $e chmod 200 lp
186 $e mknod log c 4 15
187 $e chmod 222 log
188 $e mknod kbd c 4 127
189 $e mknod kbdaux c 4 126
190 $e chmod 660 kbd kbdaux
191 $e chgrp operator kbd kbdaux
192 $e mknod video c 4 125
193 $e chmod 600 video
194 $e chgrp operator video
196 ttyc[1-7])
197 # Virtual consoles.
199 m=`expr $dev : '....\\(.*\\)'` # Minor device number.
200 $e mknod $dev c 4 $m
201 $e chgrp tty $dev
202 $e chmod 600 $dev
204 tty0[0-3])
205 # Serial lines.
207 n=`expr $dev : '.*\\(.\\)'`
208 $e mknod $dev c 4 `expr $n + 16`
209 $e chmod 666 $dev
210 $e chgrp tty $dev
212 tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
213 # Pseudo ttys.
215 dev=`expr $dev : '...\\(..\\)'`
216 g=`expr $dev : '\\(.\\)'` # Which group.
217 g=`echo $g | tr 'pqrs' '0123'`
218 n=`expr $dev : '.\\(.\\)'` # Which pty in the group.
219 case $n in
220 [a-f]) n=1`/bin/echo $n | tr 'abcdef' '012345'`
221 esac
223 $e mknod tty$dev c 4 `expr $g '*' 16 + $n + 128`
224 $e mknod pty$dev c 4 `expr $g '*' 16 + $n + 192`
225 $e chgrp tty tty$dev pty$dev
226 $e chmod 666 tty$dev pty$dev
228 eth|ip|tcp|udp|eth0|ip0|tcp0|udp0)
229 # TCP/IP devices.
231 $e mknod eth0 c 7 0 # Network 0 (Ethernet)
232 $e mknod ip0 c 7 1
233 $e mknod tcp0 c 7 2
234 $e mknod udp0 c 7 3
235 $e chmod 600 eth0 ip0
236 $e chmod 666 tcp0 udp0
237 $e ln -f eth0 eth # Default interface
238 $e ln -f ip0 ip
239 $e ln -f tcp0 tcp
240 $e ln -f udp0 udp
242 audio|mixer)
243 # Audio devices.
245 $e mknod audio c 13 0
246 $e mknod mixer c 13 1
247 $e chmod 666 audio mixer
249 random|urandom)
250 # random data generator.
251 $e mknod random c 16 0; $e chmod 644 random
252 $e mknod urandom c 16 0; $e chmod 644 urandom
253 $e chgrp operator random urandom
255 uds)
256 # unix domain sockets device
257 $e mknod uds c 18 0; $e chmod 644 random
258 $e chgrp operator uds
259 $e chmod 666 uds
261 klog)
262 # logging device.
263 $e mknod klog c 15 0
264 $e chmod 600 klog
266 filter)
267 # filter driver
268 $e mknod filter b 11 0
269 $e chmod 600 filter
271 fbd)
272 # faulty block device driver
273 $e mknod fbd b 14 0
274 $e chmod 600 fbd
276 hello)
277 # hello driver
278 $e mknod hello c 17 0
279 $e chmod 644 hello
282 echo "$0: don't know about $dev" >&2
283 ex=1
284 esac
285 done
287 exit $ex