]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/IdeDev.pm
7a4cf919d3166db69c140714a41830b6bfce855a
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / IdeDev.pm
1 #!perl -w
2 #
3 # IdeDev -- probed values for an IDE device as found in /proc/ide
4 #   Copyright (C) 2005  Erik van Konijnenburg
5 #
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.
10 #
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.
15 #
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
19 #
20 #
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.
23 #
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
28 #
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
38 # that handle this.
39 #
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
48 #
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
52 # protocol modules.
53 #
54 use strict;
55 use warnings;
56 use Base;
57 use Conf;
58 package IdeDev;
59 use base 'Obj';
60
61 sub fill {
62         my $self = shift;
63         $self->SUPER::fill();
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");
69         }
70         if ($link !~ m!.*/([^/]+)!) {
71                 Base::fatal ("malformed link to block device in $path");
72         }
73         my $name = $1;
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");
78 }
79
80 sub path        { return $_[0]->{path}; }
81 sub name        { return $_[0]->{name}; }
82 sub media       { return $_[0]->{media}; }
83 sub model       { return $_[0]->{model}; }
84
85 sub string {
86         my $self = shift;
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";
92 }
93
94
95 #
96 # findModuleByIdeDev -- list of suitable IDE drivers;
97 # you need all of them.
98 #
99 sub findModuleByIdeDev ($) {
100         my ($ideDev) = @_;
101         my $media = $ideDev->media();
102         my $driver;
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");
107         my $result;
108         if (defined ($driver)) {
109                 $result = [ "ide-generic", $driver ];
110         }
111         else {
112                 $result = [ "ide-generic" ];
113         }
114         return $result;
115 }
116
117
118 1;
119