Modified usb-devices.sh script

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Greg, Randy,

Attached a modified version of the usb-devices.sh script. The change is 
that I removed almost all the directory changes, which gives some speedup 
(~5%) and IMHO also simplifies the code.

Attached both my version and a patch relative to the script as attached in 
http://article.gmane.org/gmane.linux.usb.general/16828.

I plan to use a modified version of the script in Debian Installer.
We currently cat /proc/bus/usb/devices into a hardware-summary file we 
create for troubleshooting purposes. I prefer using the script over 
mounting debugfs in the installer.
I'll mention you both as authors of the script.

Cheers,
FJP

Attachment: usb-devices.sh
Description: application/shellscript

--- usb-devices.sh.sv	2009-06-18 00:40:19.000000000 +0200
+++ usb-devices.sh	2009-06-18 00:58:02.000000000 +0200
@@ -48,42 +48,37 @@
 }
 
 print_endpoint() {
-	endpoint=$1
+	local eppath=$1
 	if [ "$debug" = "1" ]; then
-		echo "endpoint=$endpoint"
+		echo "procesing endpoint=$eppath"
 	fi
 
-	addr=`cat $endpoint/bEndpointAddress`
-	attr=`cat $endpoint/bmAttributes`
-	dir=`cat $endpoint/direction`
-	eptype=`cat $endpoint/type`
-	maxps=`cat $endpoint/wMaxPacketSize`
-	interval=`cat $endpoint/interval`
+	addr=`cat $eppath/bEndpointAddress`
+	attr=`cat $eppath/bmAttributes`
+	dir=`cat $eppath/direction`
+	eptype=`cat $eppath/type`
+	maxps=`cat $eppath/wMaxPacketSize`
+	interval=`cat $eppath/interval`
 
 	printf "E:  Ad=%s(%s) Atr=%s(%s) MxPS=%s Ivl=%s\n" \
 		$addr $dir $attr $eptype $maxps $interval
 }
 
 print_interface() {
-	interface=$1
-	local cwd
+	local ifpath=$1
 
-	cwd=`/bin/pwd`
-	cd $interface
 	if [ "$debug" = "1" ]; then
-		echo "cd to interface=$interface"
-		echo -n "pwd="
-		/bin/pwd
+		echo "processing interface=$ifpath"
 	fi
 
-	ifnum=`cat bInterfaceNumber`
-	altset=`cat bAlternateSetting`
-	numeps=`cat bNumEndpoints`
-	class=`cat bInterfaceClass`
-	subclass=`cat bInterfaceSubClass`
-	protocol=`cat bInterfaceProtocol`
-	if [ -L driver ]; then		# v4: allow for no driver
-		driver=`readlink driver`
+	ifnum=`cat $ifpath/bInterfaceNumber`
+	altset=`cat $ifpath/bAlternateSetting`
+	numeps=`cat $ifpath/bNumEndpoints`
+	class=`cat $ifpath/bInterfaceClass`
+	subclass=`cat $ifpath/bInterfaceSubClass`
+	protocol=`cat $ifpath/bInterfaceProtocol`
+	if [ -L $ifpath/driver ]; then		# v4: allow for no driver
+		driver=`readlink $ifpath/driver`
 		driver=`basename $driver`
 	else
 		driver="(none)"
@@ -92,33 +87,24 @@
 	printf "I:  If#=%s Alt=%s #EPs=%s Cls=%s(%s) Sub=%s Prot=%s Driver=%s\n" \
 		$ifnum $altset $numeps $class $classname $subclass $protocol $driver
 
-	##for endpoint in $interface/ep_??
-	for endpoint in ep_??
+	for endpoint in $ifpath/ep_??
 	do
 		if [ -L $endpoint ]; then	# v4: verify endpoint exists
 			print_endpoint $endpoint
 		fi
 	done
-
-	if [ "$debug" = "1" ]; then
-		echo "cd back to cwd=$cwd"
-	fi
-	cd $cwd
 }
 
 print_device() {
-	device=$1
-	local cwd
+	local devpath=$1
 
-	cwd=`/bin/pwd`
-	cd $device
+	cd $devpath
 	if [ "$debug" = "1" ]; then
-		echo "cd to device=$device"
-		echo -n "pwd="
-		/bin/pwd
+		echo "cd to device=$devpath"
 	fi
 
-	busnum=`cat busnum`
+	local busnum=`cat busnum`
+
 	devnum=`cat devnum`
 	speed=`cat speed`
 	maxchild=`cat maxchild`
@@ -163,29 +149,23 @@
 
 	for endpoint in ep_??
 	do
-		print_endpoint $endpoint
+		print_endpoint $devpath/$endpoint
 	done
 
 	for interface in *:?.*
 	do
-		print_interface $interface
+		print_interface $devpath/$interface
 	done
 
-	busnum=`cat busnum`
 	for subdev in $busnum-? $busnum-?? $busnum-???
 	do
-		if [ -d $subdev ]; then
+		if [ -d $devpath/$subdev ]; then
 			if [ "$debug" = "1" ]; then
 				echo "try subdev=$subdev"
 			fi
-			print_device $subdev
+			print_device $devpath/$subdev
 		fi
 	done
-
-	if [ "$debug" = "1" ]; then
-		echo "cd back to cwd=$cwd"
-	fi
-	cd $cwd
 }
 
 debug=
@@ -195,7 +175,7 @@
 fi
 
 ##print_device /sys/bus/usb/devices/usb1
-for dev in /sys/bus/usb/devices/usb*
+for device in /sys/bus/usb/devices/usb*
 do
-	print_device $dev
+	print_device $device
 done

[Index of Archives]     [Linux Media]     [Linux Input]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [Old Linux USB Devel Archive]

  Powered by Linux