3 # IdeDev -- probed values for an IDE device as found in /proc/ide
4 # Copyright (C) 2005 Erik van Konijnenburg
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 # The probed values for an IDE device as found in /proc/ide,
22 # based on the name in /sys/devices/.../ideX/X.X/block.
24 # path - location in sysfs
25 # name - descriptive string, retrieved from device
26 # media - type of device: disk, tape, ...
27 # model - descriptive string, retrieved from device
29 # Background: hotplug is triggered when an IDE controller is
30 # found on for instance the PCI bus. The loaded module should
31 # be good enough to talk to the hardware, but that does not
32 # mean you can actually use it: you will also need something
33 # to use the hardware driver to send IDE commands over the
34 # IDE cable to the controller on the other end of the cable.
35 # Those commands also have to make sense: a disk controller
36 # uses a different set of IDE commands than an IDE tape controller.
37 # The ide-disk, ide-cdrom etc modules are the protocol drivers
40 # The following detection is based on an ide.rc script by Marco d'Itri
41 # that was not included in hotplug. Note that some CDROMs may need
42 # ide-generic in addition to ide-cdrom to work; that can be considered
43 # a driver bug rather than a valid dependency. Note that there is discussion
44 # over whether ide-generic should grab otherwise unhandled IDE devices.
45 # - http://thread.gmane.org/gmane.linux.hotplug.devel/6003
46 # - http://lists.debian.org/debian-kernel/2004/11/msg00218.html
47 # - http://www.ussg.iu.edu/hypermail/linux/kernel/0410.1/1452.html
49 # Hmm, via82cxxx (2.6.8) also needs ide-generic to load it seems. That could
50 # be because ide-generic contains a call to ide_probe_init() which is in
51 # the ide-core module. We'll add ide-generic as an extra with all IDE
64 $self->takeArgs ('path');
65 my $path = $self->path;
66 my $link = readlink ("$path/block");
67 if (! defined ($link)) {
68 Base::fatal ("no link to block device in $path");
70 if ($link !~ m!.*/([^/]+)!) {
71 Base::fatal ("malformed link to block device in $path");
74 my $ideDir = Conf::get('procFs') . "/ide";
75 $self->{name} = $name;
76 $self->{media} = Base::getStringFile ("$ideDir/$name/media");
77 $self->{model} = Base::getStringFile ("$ideDir/$name/model");
80 sub path { return $_[0]->{path}; }
81 sub name { return $_[0]->{name}; }
82 sub media { return $_[0]->{media}; }
83 sub model { return $_[0]->{model}; }
87 my $path = $self->path();
88 my $name = $self->name();
89 my $media = $self->media();
90 my $model = $self->model();
91 return "$name ($media) = $model at $path";
96 # findModuleByIdeDev -- list of suitable IDE drivers;
97 # you need all of them.
99 sub findModuleByIdeDev ($) {
101 my $media = $ideDev->media();
103 $driver = "ide-disk" if ($media eq "disk");
104 $driver = "ide-tape" if ($media eq "tape");
105 $driver = "ide-cd" if ($media eq "cdrom");
106 $driver = "ide-floppy" if ($media eq "floppy");
108 if (defined ($driver)) {
109 $result = [ "ide-generic", $driver ];
112 $result = [ "ide-generic" ];