]> git.lizzy.rs Git - plan9front.git/blob - sys/src/9/boot/nusbrc
merge
[plan9front.git] / sys / src / 9 / boot / nusbrc
1 #!/bin/rc
2 if(! bind -a '#u' /dev)
3         exit
4
5 mkdir -p -m 700 '#σc/usb'
6 mkdir -p -m 700 '#σc/usbnet'
7
8 if(! nusb/usbd)
9         exit
10
11 @{
12         rfork ne
13         fn attach {
14                 id=$1
15                 if(~ $#* 5 && ! test -e /env/nousbhname)
16                         id=$1:$5
17                 switch($2$3){
18                 case 0b957720 0b95772a 0db0a877 13b10018 15577720 20013c05 07d13c05 05ac1402
19                         nusb/ether -t a88772 $etherargs $id
20                 case 0b951780 14eaab11 17370039 0411006e 050d5055
21                         nusb/ether -t a88178 $etherargs $id
22                 case 2001abc1
23                         nusb/ether -t aue $etherargs $id
24                 case 0bda8150
25                         nusb/ether -t url $etherargs $id
26                 case 18d14ee3 0bb40003
27                         nusb/ether -t rndis $etherargs $id
28                 case *
29                         switch($4){
30                         case *03
31                                 nusb/kb $id
32                         case *02
33                                 # CDC ethernet
34                                 nusb/ether $etherargs $id
35                         case *08
36                                 if(nusb/disk $id) {@{
37                                         rfork ne
38                                         cd '#σ/usb'
39                                         devs=sdU^($1 $5)
40                                         for(dev in $devs $devs.*) if(test -d $dev) {
41                                                 diskparts $dev
42                                                 for(part in $dev/dos* $dev/9fat) if(test -r $part) {
43                                                         mkdir -m 0700 '#σc/'^$dev || exit
44                                                         {dossrv -s -f $part &} <[0=1] |
45                                                                 echo 0 >'#σc/'^$dev/dos
46                                                         exit
47                                                 }
48                                         }
49                                 }&}
50                         case *
51                                 # Raspberry Pi ethernet will always appear as /net/etherU0
52                                 if(~ $2 0424)
53                                         nusb/ether -t smsc $etherargs $1:0
54                         }
55                 }
56         }
57         fn detach {
58                 devs='#σc/sdU'^($1 $5)
59                 rm -rf '#σc/usb/'^$1.* '#σc/usbnet/'^$1.* $devs $devs.* 
60         }
61         rc < '#σ/usb/usbevent' &
62 }
63
64 bind -a '#σ/usb' /dev
65 bind -a '#σ/usbnet' /net