On Fri, 1 Mar 2002, Greg KH wrote:
| On Thu, Feb 28, 2002 at 10:21:21PM -0800, David Brownell wrote:
| > - Shows high bandwidth endpoints with something like
| > "1024*3" for maxpacket size; other endpoints just
| > have two extra spaces there.
|
| Why have the "*n" here? Why not just spit out the whole number? That
| would break less parsers :)
|
| And remember to also modify Documentation/usb/proc_usb_info.txt if you
| modify the layout.
|
| > That means this patch could break some programs; I don't
| > know why any would bother parsing such lines. The change
| > should be easily handled by detecting parsing errors.
|
| Did you try running usbview or Randy's perl scripts? I also think the
| KDE control panel parses that file.
|
| And I don't mind breaking backward compatiblilty to fix things, so don't
| be afraid of it :)
and I don't mind modifying them either.
Here they are in case anyone is interested in them (procusb & usbtree).
[attached]
--
~Randy
#!/usr/bin/perl
# Reads /proc/bus/usb/devices and selectively lists and/or
# interprets it.
$DEVFILENAME = "/proc/bus/usb/devices";
$PROGNAME = $0;
$TAGS = $ARGV[0]; # save user TAGS
if (length ($TAGS) == 0)
{
print "usage: $PROGNAME tags\n";
print " where 'tags' can be any number of 'TBDPSCIE' or 'A(LL)'\n";
exit 1;
}
$ALL = ($TAGS =~ /all/i) || ($TAGS =~ /a/i);
# TBD: Check that $TAGS is valid.
if (! $ALL)
{
}
if (! open (DEVNUM, "<$DEVFILENAME"))
{
print "$PROGNAME: cannot open '$DEVFILENAME'\n";
exit 1;
}
while ($line = <DEVNUM>) # read a text line from DEVNUM
{
if ($line =~ /^T:/) # put device break line
{
print "---\n";
}
if (($ALL) || ($line =~ /^[$TAGS]:/i)) # any of TAGS at beg. of line?
{
print "$line"; # still has newline char on it
# TBD: add more/paging functionality.
}
} # end while DEVNUM
close (DEVNUM);
print "\n";
# END.
#!/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: $bus, $level, $parent, $port, $count, $devnum, $speed,
$maxchild.
$bus = @fields [2];
$level = @fields [4];
$parent = @fields [6]; # parent devnum
$port = @fields [8] + 1; # make $port 1-based
$count = @fields [10];
$devnum = @fields [12];
$speed = @fields [14];
$maxchild = @fields [16];
$devclass = "?";
$intclass = "?";
$driver = "?";
$ifnum = "?";
$showclass = "?"; # derived from $devclass or $intclass
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--;
}
}
if (($devclass eq ">ifc") || ($devclass eq "unk."))
{ # then use InterfaceClass, not DeviceClass
$showclass = $intclass;
}
else
{ # use DeviceClass
$showclass = $devclass;
}
if ($level == 0)
{
print sprintf ("/: Bus $bus.Port $port: Dev $devnum, Class=root_hub,
Driver=hub/%sp, %sM\n",
$maxchild, $speed);
}
else
{
print sprintf ("|__ Port $port: Dev $devnum, If $ifnum,
Class=$showclass, Driver=$driver%s, %sM\n",
($maxchild == 0) ? "" : ("/" . $maxchild . "p"),
$speed);
}
} # end while DEVNUM
close (DEVNUM);
print "\n";
# END.