patch-2.3.27 linux/scripts/usb/usbtree

Next file: linux/CREDITS
Previous file: linux/scripts/usb/procusb
Back to the patch index
Back to the overall index

diff -u --recursive --new-file v2.3.26/linux/scripts/usb/usbtree linux/scripts/usb/usbtree
@@ -0,0 +1,90 @@
+#!/usr/bin/perl
+
+# Reads /proc/bus/usb/devices and selectively lists and/or
+# interprets it.
+
+$DEVFILENAME = "/proc/bus/usb/devices";
+$PROGNAME = $0;
+
+print "\n";
+
+$TAGS = $ARGV[0];		# save user TAGS
+if (length ($TAGS) == 0)
+{
+}
+
+if (! open (DEVNUM, "<$DEVFILENAME"))
+{
+	print "$PROGNAME: cannot open '$DEVFILENAME'\n";
+	exit 1;
+}
+
+while ($line = <DEVNUM>)	# read a text line from DEVNUM
+{
+	# skip all lines except those that begin with "T:" or "D:" or "I:".
+	if (($line !~ "^T:") && ($line !~ "^I:") && ($line !~ "^D:"))
+	{
+		next;	# to the next line
+	}
+
+	chomp $line;		# remove line endings
+
+	# First convert '=' signs to spaces.
+	$line =~ tr/=/ /;
+
+	# and convert all ( and ) to spaces.
+	$line =~ tr/(/ /;
+	$line =~ tr/)/ /;
+
+	# split the line at spaces.
+	@fields = split / +/, $line;
+
+	if ($line =~ "^T:")
+	{
+		# split yields: $level, $port, $devnum, $speed, $maxchild.
+
+		$level  = @fields [2];
+		$port   = @fields [6];
+		$devnum = @fields [10];
+		$speed  = @fields [12];
+		$maxchild = @fields [14];
+		$devclass = "?";
+		$intclass = "?";
+		$driver   = "?";
+
+		if (($devnum == -1) && ($level == 0))
+		{
+			print "/:  Dev# -1, root hub/$maxchild ports, $speed Mbps\n";
+		}
+		next;
+	} # end T: line
+	elsif ($line =~ "^D:")
+	{ # for D: line
+		$devclass = @fields [5];
+		next;
+	}
+	else
+	{ # for I: line
+		$intclass = @fields [9];
+		$ifnum    = @fields [2];
+		$driver   = @fields [15];
+	} # end I: line
+
+	if ($level > 1)
+	{
+		$temp = $level;
+		while ($temp > 1)
+		{
+			print "    ";
+			$temp--;
+		}
+	}
+	
+	print sprintf ("|__ Port# $port: Dev# $devnum, If# $ifnum, Class=$devclass, Ifc=$intclass, Driver=$driver%s, $speed Mbps\n",
+		($maxchild == 0) ? "" : ("/" . $maxchild . " ports"));
+} # end while DEVNUM
+
+close (DEVNUM);
+print "\n";
+
+# END.


FUNET's LINUX-ADM group, linux-adm@nic.funet.fi
TCL-scripts by Sam Shen (who was at: slshen@lbl.gov)