]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/ScsiDev.pm
f771bc00e4995773ac167e96ecc495dd982e07a4
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / ScsiDev.pm
1 #!perl -w
2 #
3 # ScsiDev -- the probed values for a SCSI device, as found in /sys.
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 # Like IDE devices, SCSI devices need a protocol driver, based
21 # on device type, without hardware probing and matching against
22 # a kernel generated table.
23 #
24 # The type and module knowledge is based in /etc/hotplug/scsi.agent,
25 # that attributes scsi/scsi.h.
26 #
27 use strict;
28 use warnings;
29 use Base;
30 package ScsiDev;
31 use base 'Obj';
32
33 sub fill {
34         my $self = shift;
35         $self->SUPER::fill();
36         $self->takeArgs ('path');
37         my $path = $self->path;
38         my $name = readlink ("$path/block");
39         if (defined ($name)) {
40                 $name = Base::basename ($name);
41                 $self->{name} = $name;
42         }
43         else {
44                 $self->{name} = undef;
45         }
46         $self->{vendor} = Base::getStringFile ("$path/vendor");
47         $self->{model} = Base::getStringFile ("$path/model");
48
49         my $type = Base::getStringFile ("$path/type");
50         $self->{type} = "disk" if $type eq '0';
51         $self->{type} = "tape" if $type eq '1';
52         $self->{type} = "printer" if $type eq '2';
53         $self->{type} = "processor" if $type eq '3';
54         $self->{type} = "worm" if $type eq '4';
55         $self->{type} = "cdrom" if $type eq '5';
56         $self->{type} = "scanner" if $type eq '6';
57         $self->{type} = "mod" if $type eq '7';
58         $self->{type} = "changer" if $type eq '8';
59         $self->{type} = "comm" if $type eq '9';
60         $self->{type} = "enclosure" if $type eq '14';
61         $self->{type} = "type$type" if (!defined ($self->{type}));
62 }
63
64 sub path        { return $_[0]->{path}; }
65 sub name        { return $_[0]->{name}; }
66 sub vendor      { return $_[0]->{vendor}; }
67 sub model       { return $_[0]->{model}; }
68 sub type        { return $_[0]->{type}; }
69
70 sub string {
71         my $self = shift;
72         my $path = $self->path();
73         my $name = $self->name();
74         my $vendor = $self->vendor();
75         my $model = $self->model();
76         my $type = $self->type();
77         $name = "---" if (! defined ($name));
78         return "$name ($type) = $vendor, $model at $path";
79 }
80
81
82 #
83 # findModuleByScsiDev -- list of required SCSI drivers
84 #
85 sub findModuleByScsiDev ($) {
86         my ($scsiDev) = @_;
87         my $type = $scsiDev->type();
88         my $driver;
89         $driver = "sd-mod" if $type eq "disk";
90         # "FIXME some tapes use 'osst'"
91         $driver = "st" if $type eq "tape";
92         # if $type eq "printer";
93         # if $type eq "processor";
94         $driver = "sr-mod" if $type eq "worm";
95         $driver = "sr-mod" if $type eq "cdrom";
96         # if $type eq "scanner";
97         $driver = "sd-mod" if $type eq "mod";
98         # if $type eq "changer";
99         # if $type eq "comm";
100         # if $type eq "enclosure";
101         $driver = "sg" if (! defined ($driver));
102         return [ $driver ];
103 }
104
105 1;
106
107