1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107
|
#!perl -w
#
# IdeDev -- probed values for an IDE device as found in /proc/ide
# 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
#
#
# The probed values for an IDE device as found in /proc/ide,
# based on the name in /sys/devices/.../ideX/X.X/block.
#
# path - location in sysfs
# name - descriptive string, retrieved from device
# media - type of device: disk, tape, ...
# model - descriptive string, retrieved from device
#
# Background: hotplug is triggered when an IDE controller is
# found on for instance the PCI bus. The loaded module should
# be good enough to talk to the hardware, but that does not
# mean you can actually use it: you will also need something
# to use the hardware driver to send IDE commands over the
# IDE cable to the controller on the other end of the cable.
# Those commands also have to make sense: a disk controller
# uses a different set of IDE commands than an IDE tape controller.
# The ide-disk, ide-cdrom etc modules are the protocol drivers
# that handle this.
#
use strict;
use warnings;
use Base;
use Conf;
package IdeDev;
use base 'Obj';
sub fill {
my $self = shift;
$self->SUPER::fill();
$self->takeArgs ('path');
my $path = $self->path;
my $link = readlink ("$path/block");
if (! defined ($link)) {
Base::fatal ("no link to block device in $path");
}
if ($link !~ m!.*/([^/]+)!) {
Base::fatal ("malformed link to block device in $path");
}
my $name = $1;
my $ideDir = Conf::get('procFs') . "/ide";
$self->{name} = $name;
$self->{media} = Base::getStringFile ("$ideDir/$name/media");
$self->{model} = Base::getStringFile ("$ideDir/$name/model");
}
sub path { return $_[0]->{path}; }
sub name { return $_[0]->{name}; }
sub media { return $_[0]->{media}; }
sub model { return $_[0]->{model}; }
sub string {
my $self = shift;
my $path = $self->path();
my $name = $self->name();
my $media = $self->media();
my $model = $self->model();
return "$name ($media) = $model at $path";
}
#
# findModuleByIdeDev -- list of suitable IDE drivers;
# you need all of them.
#
sub findModuleByIdeDev ($) {
my ($ideDev) = @_;
my $media = $ideDev->media();
my $result = [];
my $driver;
$driver = "ide-disk" if ($media eq "disk");
$driver = "ide-tape" if ($media eq "tape");
# The CD may also need ide-generic.
$driver = "ide-cd" if ($media eq "cdrom");
$driver = "ide-floppy" if ($media eq "floppy");
if (defined ($driver)) {
push @{$result}, $driver;
}
return $result;
}
1;
|