plan9fox/sys/src/9/boot/nusbrc

43 lines
646 B
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/bin/rc
if(! bind -a '#u' /dev)
exit
mkdir -m 0700 '#σc/usb'
if(! nusb/usbd)
exit
@{
rfork ne
fn attach {
switch($4){
case *03
nusb/kb $1
case *08
nusb/disk $1
@{
rfork ne
cd '#σ/usb'
for(dev in sdU^$1.*) if(test -d $dev) {
diskparts $dev
for(part in $dev/dos* $dev/9fat) if(test -r $part) {
mkdir -m 0700 '#σc/'^$dev || exit
{dossrv -s -f $part &} <[0=1] |
echo 0 >'#σc/'^$dev/dos
exit
}
}
} &
}
}
fn detach {
rm -rf '#σc/usb/'^$1.* '#σc/sdU'^$1.*
}
rc < '#σ/usb/usbevent' &
}
bind -a '#σ/usb' /dev
# wait for devices getting activated
sleep 3