Package: yaird
Version: 0.0.12-3
Severity: wishlist

I'm currently playing around to port the Linux sbus
support to the new device model to gain sysfs support.

The attached patch extends yaird to support my patches,
which I plan to test a bit more and submit the next days
(or weeks).

Nevertheless I decided to already decided to already submit
this patch against yaird, so it can already be reviewed
(I tried my best to forget all perl I once new the last years)
and I do not lose it somewhere.

Hochachtungsvoll,
        Bernhard R. Link
diff -u -N yaird/usr/lib/yaird/perl/Conf.pm /usr/lib/yaird/perl/Conf.pm
--- yaird/usr/lib/yaird/perl/Conf.pm    2005-12-30 11:17:11.000000000 +0100
+++ /usr/lib/yaird/perl/Conf.pm 2006-02-16 18:18:32.000000000 +0100
@@ -45,6 +45,9 @@
        modDep          => sub { get('libModules')
                                . '/' . get('version')
                                . '/modules.dep'; },
+       modAlias        => sub { get('libModules')
+                               . '/' . get('version')
+                               . '/modules.alias'; },
        usbMap          => sub { get('libModules')
                                . '/' . get('version')
                                . '/modules.usbmap'; },
diff -u -N yaird/usr/lib/yaird/perl/Hardware.pm /usr/lib/yaird/perl/Hardware.pm
--- yaird/usr/lib/yaird/perl/Hardware.pm        2005-12-30 11:17:10.000000000 
+0100
+++ /usr/lib/yaird/perl/Hardware.pm     2006-02-16 18:30:11.000000000 +0100
@@ -34,6 +34,8 @@
 use UsbTab;
 use CcwDev;
 use CcwTab;
+use SBusDev;
+use ModAliasTab;
 package Hardware;
 
 
@@ -73,7 +75,13 @@
                        my $dev = UsbDev->new (path => $abspath);
                        $modules = UsbTab::find ($dev);
                }
-
+               elsif ($abspath =~ m!sbus\d+$!) {
+                       # sbus; harmless
+               }
+               elsif ($abspath =~ m!sbus\d+(/\d+:\d+)+$!) {
+                       my $dev = SBusDev->new (path => $abspath);
+                       $modules = ModAliasTab::find ($dev->modalias);
+               }
                elsif ($abspath =~ m!/css0$!) {
                        # S390 Channel SubSystem; harmless
                }
diff -u -N yaird/usr/lib/yaird/perl/ModAliasEntry.pm 
/usr/lib/yaird/perl/ModAliasEntry.pm
--- yaird/usr/lib/yaird/perl/ModAliasEntry.pm   1970-01-01 01:00:00.000000000 
+0100
+++ /usr/lib/yaird/perl/ModAliasEntry.pm        2006-02-16 18:23:01.000000000 
+0100
@@ -0,0 +1,54 @@
+#!perl -w
+#
+# ModAliasEntry - iencapsulate a line form modules.alias
+#   Copyright (C) 2006  Bernhard R. Link
+# heavily based upon
+# PciMapEntry - iencapsulate a line form modules.pcimap.
+#   Copyright (C) 2005  Erik van Konijnenburg
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+#
+# Knows how to match, can return module name.
+#
+
+use strict;
+use warnings;
+use Base;
+package ModAliasEntry;
+use base 'Obj';
+
+sub fill {
+       my $self = shift;
+       $self->SUPER::fill();
+       $self->takeArgs ('module', 'mask');
+}
+
+sub module     { return $_[0]->{module}; }
+
+sub matches {
+# this is the easy variant for sbus: match the whole string.
+       my ($self, $modalias) = @_;
+       if ($self->{mask} eq $modalias ) {
+               return 1;
+       }
+       if ($self->{mask} eq ( $modalias . "*") ) {
+               return 1;
+       }
+       return 0;
+}
+
+1;
+
diff -u -N yaird/usr/lib/yaird/perl/ModAliasTab.pm 
/usr/lib/yaird/perl/ModAliasTab.pm
--- yaird/usr/lib/yaird/perl/ModAliasTab.pm     1970-01-01 01:00:00.000000000 
+0100
+++ /usr/lib/yaird/perl/ModAliasTab.pm  2006-02-16 18:39:37.000000000 +0100
@@ -0,0 +1,87 @@
+#!perl -w
+#
+# ModAliasTab -- encapsulate modules.alias
+#   Copyright (C) 2006  Bernhard R. Link
+#   based on PciTab.pm, which is:
+#   Copyright (C) 2005  Erik van Konijnenburg
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+
+use strict;
+use warnings;
+use Base;
+use Conf;
+use ModAliasEntry;
+package ModAliasTab;
+
+my $modAliasList = undef;
+
+# Parse this:
+# # Aliases extracted from modules themselves.
+# alias sbus:audio* snd_sun_amd7930
+
+sub init () {
+       if (defined ($modAliasList)) {
+               return;
+       }
+       $modAliasList = [];
+       my $name = Conf::get('modAlias');
+       if (! open (IN, "<", "$name")) {
+               Base::fatal ("can't open modAlias module list $name");
+       }
+       while (defined (my $line = <IN>)) {
+               chomp $line;
+               $line =~ s/#.*//;
+               $line =~ s/^\s+//;
+               $line =~ s/\s+$//;
+               next if ($line eq "");
+               my @fields = split (/\s+/, $line, 999);
+               if ($#fields != 2) {
+                       Base::fatal "malformed line ($#fields != 2) in modAlias 
module list $name";
+               }
+               if ($fields[0] ne "alias") {
+                       Base::fatal "malformed line (not starting with alias) 
in modAlias module list $name";
+               }
+               push @{$modAliasList}, ModAliasEntry->new (
+                       module => $fields[2],
+                       mask => $fields[1],
+               );
+       }
+       if (! close (IN)) {
+               Base::fatal "could not read modAlias module list $name";
+       }
+}
+
+sub all        () {
+       init;
+       return $modAliasList;
+}
+
+# given pathname in devices tree, find module name in ModAlias as a list.
+sub find ($) {
+       my ($modalias) = @_;
+       my @result = ();
+       for my $gme (@{ModAliasTab::all()}) {
+               if ($gme->matches ($modalias)) {
+                       push @result, $gme->module;
+               }
+       }
+       return [EMAIL PROTECTED];
+}
+
+
+1;
+
diff -u -N yaird/usr/lib/yaird/perl/SBusDev.pm /usr/lib/yaird/perl/SBusDev.pm
--- yaird/usr/lib/yaird/perl/SBusDev.pm 1970-01-01 01:00:00.000000000 +0100
+++ /usr/lib/yaird/perl/SBusDev.pm      2006-02-16 18:31:12.000000000 +0100
@@ -0,0 +1,40 @@
+#!perl -w
+#
+# SBusDev -- get the modalias field for a SBus device from /sys.
+#   Copyright (C) 2006  Bernhard R. Link
+# based heavily on
+#   Copyright (C) 2005  Erik van Konijnenburg
+#
+#   This program is free software; you can redistribute it and/or modify
+#   it under the terms of the GNU General Public License as published by
+#   the Free Software Foundation; either version 2 of the License, or
+#   (at your option) any later version.
+#
+#   This program is distributed in the hope that it will be useful,
+#   but WITHOUT ANY WARRANTY; without even the implied warranty of
+#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#   GNU General Public License for more details.
+#
+#   You should have received a copy of the GNU General Public License
+#   along with this program; if not, write to the Free Software
+#   Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301 USA
+#
+use strict;
+use warnings;
+use Base;
+package SBusDev;
+use base 'Obj';
+
+sub fill {
+       my $self = shift;
+       $self->SUPER::fill();
+       $self->takeArgs ('path');
+       my $path = $self->path;
+       $self->{modalias} = Base::getStringFile ("$path/modalias");
+}
+
+sub modalias   { return $_[0]->{modalias}; }
+sub path       { return $_[0]->{path}; }
+
+
+1;

Reply via email to