filesystem: added script to create unique ttyUSB devices.
This commit is contained in:
parent
f1265e4e7a
commit
eee2296f59
43
rules/filesystem/fs/sbin/mdev-ttyusb
Executable file
43
rules/filesystem/fs/sbin/mdev-ttyusb
Executable file
@ -0,0 +1,43 @@
|
||||
#! /bin/sh
|
||||
|
||||
[ "$SUBSYSTEM" -ne "tty" ] && exit 0
|
||||
if [ -z "$MAJOR" ] || [ -z "$MINOR" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
MAJOR_HEX=$(echo $(printf %2x "$MAJOR"))
|
||||
MINOR_HEX=$(echo $(printf %2x "$MINOR"))
|
||||
|
||||
# env | while read line; do
|
||||
# logger -t "$0" "$line"
|
||||
# done
|
||||
|
||||
case "$ACTION" in
|
||||
add)
|
||||
dev_root="/sys/$DEVPATH/../../../../"
|
||||
itf_root="/sys/$DEVPATH/../../../"
|
||||
vid="$(cat $dev_root/idVendor 2> /dev/null)"
|
||||
pid="$(cat $dev_root/idProduct 2> /dev/null)"
|
||||
serial="$(cat $dev_root/serial 2> /dev/null)"
|
||||
[ -z "$serial" ] && serial='0'
|
||||
itf="$(cat $itf_root/bInterfaceNumber 2> /dev/null)"
|
||||
dev_name="${vid}_${pid}_${serial}_${itf}"
|
||||
dev_file="/dev/uart/$dev_name"
|
||||
logger -t "$0" "creating device: $dev_file"
|
||||
mknod "$dev_file" c "$MAJOR" "$MINOR"
|
||||
;;
|
||||
|
||||
remove)
|
||||
removed_major_minor="$MAJOR_HEX:$MINOR_HEX"
|
||||
|
||||
for f in /dev/uart/*; do
|
||||
file_major_minor="$(stat -c %t:%T "$f")"
|
||||
#logger -t "$0" "$f | $removed_major_minor | $file_major_minor"
|
||||
|
||||
if [ "$file_major_minor" = "$removed_major_minor" ]; then
|
||||
logger -t "$0" "removing device: $f"
|
||||
rm -f "$f"
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
Reference in New Issue
Block a user