source: trunk/minix/commands/scripts/MAKEDEV.sh@ 21

Last change on this file since 21 was 9, checked in by Mattia Monga, 13 years ago

Minix 3.1.2a

File size: 6.8 KB
Line 
1#!/bin/sh
2#
3# MAKEDEV 3.3 - Make special devices. Author: Kees J. Bot
4
5case $1 in
6-n) e=echo; shift ;; # Just echo when -n is given.
7*) e=
8esac
9
10case $#:$1 in
111: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 tty ttyc1 ttyc2 ttyc3 tty00 tty01 tty02 tty03 \
18 ttyp0 ttyp1 ttyp2 ttyp3 ttyp4 ttyp5 ttyp6 ttyp7 ttyp8 ttyp9 \
19 ttypa ttypb ttypc ttypd ttype ttypf \
20 ttyq0 ttyq1 ttyq2 ttyq3 ttyq4 ttyq5 ttyq6 ttyq7 ttyq8 ttyq9 \
21 ttyqa ttyqb ttyqc ttyqd ttyqe ttyqf \
22 eth klog random cmos rescue
23 ;;
240:|1:-\?)
25 cat >&2 <<EOF
26Usage: $0 [-n] key ...
27Where key is one of the following:
28 ram mem kmem null boot zero # One of these makes all these memory devices
29 fd0 fd1 ... # Floppy devices for drive 0, 1, ...
30 fd0p0 fd1p0 ... # Make floppy partitions fd0p[0-3], fd1p[0-3], ...
31 c0d0 c0d1 ... # Make disks c0d0, c0d1, ...
32 c0d0p0 c0d1p0 ... # Make partitions c0d0p[0-3], c0d1p[0-3], ...
33 c0d0p0s0 c0d1p0s0 ... # Subparts c0d0p[0-3]s[0-3], c0d1p[0-3]s[0-3], ...
34 c1d0(p0)(s0) # Likewise for controller 1
35 c0t0 c0t1 c1t0 ... # Make tape devices c0t0, c0t0n, c0t1, ...
36 console lp tty log # One of these makes all four
37 ttyc1 ... ttyc7 # Virtual consoles
38 tty00 ... tty03 # Make serial lines
39 ttyp0 ... ttyq0 ... # Make tty, pty pairs
40 eth ip tcp udp # One of these makes some TCP/IP devices
41 audio mixer # Make audio devices
42 klog # Make /dev/klog
43 random # Make /dev/random, /dev/urandom
44 cmos # Make /dev/cmos
45 kbd # Make /dev/kbd
46 kbdaux # Make /dev/kbdaux
47 rescue # Make /dev/rescue
48 video # Make /dev/video
49 std # All standard devices
50EOF
51 exit 1
52esac
53
54umask 077
55ex=0
56
57for dev
58do
59 case $dev in # One of the controllers? Precompute major device nr.
60 c0*) maj=3 ;;
61 c1*) maj=8 ;;
62 c2*) maj=10 ;;
63 c3*) maj=12 ;;
64 esac
65
66 case $dev in
67 ram|mem|kmem|null|boot|zero)
68 # Memory devices.
69 #
70 $e mknod ram b 1 0; $e chmod 600 ram
71 $e mknod mem c 1 1; $e chmod 640 mem
72 $e mknod kmem c 1 2; $e chmod 640 kmem
73 $e mknod null c 1 3; $e chmod 666 null
74 $e mknod boot b 1 4; $e chmod 600 ram
75 $e mknod zero c 1 5; $e chmod 644 zero
76 $e chgrp kmem ram mem kmem null boot zero
77 ;;
78 fd[0-3])
79 # Floppy disk drive n.
80 #
81 d=`expr $dev : '.*\\(.\\)'` # Drive number.
82 $e mknod $dev b 2 $d
83 $e chmod 666 $dev
84 ;;
85 pc[0-3]|at[0-3]|qd[0-3]|ps[0-3]|pat[0-3]|qh[0-3]|PS[0-3])
86 # Obsolete density locked floppy disk drive n.
87 #
88 d=`expr $dev : '.*\\(.\\)'` # Drive number.
89 m=$d # Minor device number.
90
91 $e mknod pc$d b 2 $m; m=`expr $m + 4`
92 $e mknod at$d b 2 $m; m=`expr $m + 4`
93 $e mknod qd$d b 2 $m; m=`expr $m + 4`
94 $e mknod ps$d b 2 $m; m=`expr $m + 4`
95 $e mknod pat$d b 2 $m; m=`expr $m + 4`
96 $e mknod qh$d b 2 $m; m=`expr $m + 4`
97 $e mknod PS$d b 2 $m; m=`expr $m + 4`
98
99 $e chmod 666 pc$d at$d qd$d ps$d pat$d qh$d PS$d
100 ;;
101 fd[0-3]p[0-3])
102 # Floppy disk partitions.
103 #
104 n=`expr $dev : '\\(.*\\)..'` # Name prefix.
105 d=`expr $dev : '..\\(.\\)'` # Drive number.
106 m=`expr 112 + $d` # Minor of partition 0.
107 alldev=
108
109 for p in 0 1 2 3
110 do
111 m=`expr 112 + $d + $p '*' 4` # Minor of partition $p.
112 $e mknod ${n}p${p} b 2 $m # Make e.g. fd0p0 - fd0p3
113 alldev="$alldev ${n}p${p}"
114 done
115 $e chmod 666 $alldev
116 ;;
117 c[0-3]d[0-7])
118 # Whole disk devices.
119 d=`expr $dev : '...\\(.\\)'` # Disk number.
120 m=`expr $d '*' 5` # Minor device number.
121 $e mknod $dev b $maj $m
122 $e chmod 600 $dev
123 ;;
124 c[0-3]d[0-7]p[0-3])
125 # Disk primary partitions.
126 n=`expr $dev : '\\(.*\\).'` # Name prefix.
127 d=`expr $dev : '...\\(.\\)'` # Disk number.
128 alldev=
129
130 for p in 0 1 2 3
131 do
132 m=`expr $d '*' 5 + 1 + $p` # Minor device number.
133 $e mknod $n$p b $maj $m
134 alldev="$alldev $n$p"
135 done
136 $e chmod 600 $alldev
137 ;;
138 c[0-3]d[0-7]p[0-3]s[0-3])
139 # Disk subpartition.
140 n=`expr $dev : '\\(.*\\)...'` # Name prefix.
141 d=`expr $dev : '...\\(.\\)'` # Disk number.
142 alldev=
143
144 for p in 0 1 2 3
145 do
146 for s in 0 1 2 3
147 do
148 m=`expr 128 + $d '*' 16 + $p '*' 4 + $s` # Minor device nr.
149 $e mknod ${n}${p}s${s} b $maj $m
150 alldev="$alldev ${n}${p}s${s}"
151 done
152 done
153 $e chmod 600 $alldev
154 ;;
155 c[0-3]t[0-7]|c[0-3]t[0-7]n)
156 # Tape devices.
157 n=`expr $dev : '\\(....\\)'` # Name prefix.
158 t=`expr $dev : '...\\(.\\)'` # Tape number.
159 m=`expr 64 + $t '*' 2` # Minor device number.
160 $e mknod ${n}n c $maj $m
161 $e mknod ${n} c $maj `expr $m + 1`
162 $e chmod 660 ${n}n ${n}
163 ;;
164 console|lp|tty|log|kbd|kbdaux|video)
165 # Console, line printer, anonymous tty, diagnostics device,
166 # raw keyboard, ps/2 mouse, video.
167 $e mknod console c 4 0
168 $e chmod 600 console
169 $e chgrp tty console
170 $e mknod tty c 5 0
171 $e chmod 666 tty
172 $e mknod lp c 6 0
173 $e chown daemon lp
174 $e chgrp daemon lp
175 $e chmod 200 lp
176 $e mknod log c 4 15
177 $e chmod 222 log
178 $e mknod kbd c 4 127
179 $e mknod kbdaux c 4 126
180 $e chmod 660 kbd kbdaux
181 $e chgrp operator kbd kbdaux
182 $e mknod video c 4 125
183 $e chmod 600 video
184 $e chgrp operator video
185 ;;
186 ttyc[1-7])
187 # Virtual consoles.
188 #
189 m=`expr $dev : '....\\(.*\\)'` # Minor device number.
190 $e mknod $dev c 4 $m
191 $e chgrp tty $dev
192 $e chmod 600 $dev
193 ;;
194 tty0[0-3])
195 # Serial lines.
196 #
197 n=`expr $dev : '.*\\(.\\)'`
198 $e mknod $dev c 4 `expr $n + 16`
199 $e chmod 666 $dev
200 $e chgrp tty $dev
201 ;;
202 tty[p-s][0-9a-f]|pty[p-s][0-9a-f])
203 # Pseudo ttys.
204 #
205 dev=`expr $dev : '...\\(..\\)'`
206 g=`expr $dev : '\\(.\\)'` # Which group.
207 g=`echo $g | tr 'pqrs' '0123'`
208 n=`expr $dev : '.\\(.\\)'` # Which pty in the group.
209 case $n in
210 [a-f]) n=1`echo $n | tr 'abcdef' '012345'`
211 esac
212
213 $e mknod tty$dev c 4 `expr $g '*' 16 + $n + 128`
214 $e mknod pty$dev c 4 `expr $g '*' 16 + $n + 192`
215 $e chgrp tty tty$dev pty$dev
216 $e chmod 666 tty$dev pty$dev
217 ;;
218 eth|ip|tcp|udp|eth0|ip0|tcp0|udp0)
219 # TCP/IP devices.
220 #
221 $e mknod eth0 c 7 0 # Network 0 (Ethernet)
222 $e mknod ip0 c 7 1
223 $e mknod tcp0 c 7 2
224 $e mknod udp0 c 7 3
225 $e chmod 600 eth0 ip0
226 $e chmod 666 tcp0 udp0
227 $e ln -f eth0 eth # Default interface
228 $e ln -f ip0 ip
229 $e ln -f tcp0 tcp
230 $e ln -f udp0 udp
231 ;;
232 audio|mixer)
233 # Audio devices.
234 #
235 $e mknod audio c 13 0
236 $e mknod rec c 13 1
237 $e mknod mixer c 13 2
238 $e chmod 666 audio rec mixer
239 ;;
240 random|urandom)
241 # random data generator.
242 $e mknod random c 16 0; $e chmod 644 random
243 $e mknod urandom c 16 0; $e chmod 644 urandom
244 $e chgrp operator random urandom
245 ;;
246 cmos)
247 # cmos device (set/get system time).
248 $e mknod cmos c 17 0
249 $e chmod 600 cmos
250 ;;
251 rescue)
252 # rescue device
253 $e mknod rescue b 9 0
254 $e chmod 644 rescue
255 ;;
256 klog)
257 # logging device.
258 $e mknod klog c 15 0
259 $e chmod 600 klog
260 ;;
261 *)
262 echo "$0: don't know about $dev" >&2
263 ex=1
264 esac
265done
266
267exit $ex
Note: See TracBrowser for help on using the repository browser.