plan9fox/rc/bin/nusbrc
cinap_lenrek 4275c49e72 nusb: implement aijus stable uniqueue device names
instead of naming devices by ther dynamically assigned device address,
we hash device uniqueue fields from the device descriptor and produce
a 5 digit hex string that will identify the device across machines.

when there is a collision (less than 1% chance with 100 devices),
usbd will append the device address to the name to make it uniqueue
for this machine.

the hname is passed to drivers in the devid argument, which now has
the form addr:hname, where the colon and hname can be omited (for backwards
compatibility).

when the new behaviour isnt desired, nousbhname= environment variable
can be defined giving the old behaviour.
2014-06-28 18:09:43 +02:00

39 lines
622 B
Bash
Executable file
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(! test -e '#σ/usb/usbevent')
exit
if(! bind -a '#u' /dev)
exit
@{
rfork ne
fn attach {
id=$1
if(~ $#* 5 && ! test -e /env/nousbhname)
id=$1:$5
switch($4){
case *01
nusb/audio $id
case *02
# serial and ethernet
nusb/serial $id
# handled /sys/src/9/boot/nusbrc
# nusb/ether $id
case *03
# handled /sys/src/9/boot/nusbrc
# nusb/kb $id
case *08
# handled /sys/src/9/boot/nusbrc
# nusb/disk $id
case 010106
nusb/ptp $id
}
}
fn detach {
# handled /sys/src/9/boot/nusbrc
}
rc < '#σ/usb/usbevent' &
}
bind -qa '#σ/usb' /dev
bind -qa '#σ/usbnet' /net