Index: detect_devices.pm =================================================================== --- detect_devices.pm (revision 215410) +++ detect_devices.pm (revision 215411) @@ -276,37 +193,39 @@ "Communications", ); - my @l = map { + my @l; + foreach (all($dev_dir)) { my ($host, $channel, $id, $lun) = split ':' or log::l("bad entry in $dev_dir: $_"), next; + my $dir = "$dev_dir/$_"; - my $dir = "$dev_dir/$_"; + # handle both old and new kernels: + my $node = -e "$dir/block" ? "$dir/block" : top(glob_("$dir/block*")); + my ($device) = readlink($node) =~ m!/block/(.*)!; + warn("cannot get info for device ($_)"), next if !$device; + + my $usb_dir = readlink("$node/device") =~ m!/usb! && "$node/device/../../../.."; + my $get_usb = sub { chomp_(cat_("$usb_dir/$_[0]")) }; + my $get = sub { my $s = cat_("$dir/$_[0]"); $s =~ s/\s+$//; $s; }; - my $usb_dir = readlink("$dir/block/device") =~ m!/usb! && "$dir/block/device/../../../.."; - my $get_usb = sub { chomp_(cat_("$usb_dir/$_[0]")) }; - - # handle both old and new kernels: - my $node = -e "$dir/block" ? "$dir/block" : top(glob_("$dir/block*")); - my ($device) = readlink($node) =~ m!/block/(.*)!; - warn "cannot get info for device ($host, $channel, $id, $lun)" if !$device; - - my $media_type = ${{ st => 'tape', sr => 'cdrom', sd => 'hd' }}{substr($device, 0, 2)}; # Old hp scanners report themselves as "Processor"s # (see linux/include/scsi/scsi.h and sans-find-scanner.1) my $raw_type = $scsi_types[$get->('type')]; - $media_type ||= 'scanner' if $raw_type =~ /Scanner|Processor/; - { info => $get->('vendor') . ' ' . $get->('model'), host => $host, channel => $channel, id => $id, lun => $lun, + my $media_type = ${{ st => 'tape', sr => 'cdrom', sd => 'hd' }}{substr($device, 0, 2)} || + $raw_type =~ /Scanner|Processor/ && 'scanner'; + + push @l, { info => $get->('vendor') . ' ' . $get->('model'), host => $host, channel => $channel, id => $id, lun => $lun, bus => 'SCSI', media_type => $media_type, device => $device, $usb_dir ? ( usb_vendor => hex($get_usb->('idVendor')), usb_id => hex($get_usb->('idProduct')), ) : (), }; - } all($dev_dir); + } @l = sort { $a->{host} <=> $b->{host} || $a->{channel} <=> $b->{channel} || $a->{id} <=> $b->{id} || $a->{lun} <=> $b->{lun} } @l;