3 # ActiveBlockDev -- a single blockdev, as found in /sys
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
20 # The blockdev can be a whole device or a partition.
21 # descriptors contain:
22 # - name, path as found in /sys (sda, sda/sda1)
23 # - devno, as found in /sys (8:1)
24 # - parent, undef for whole device, maj:minor of parent otherwise
25 # - hw, path to underlying hardware device,
26 # eg an ide controller somewhere on a PCI bus.
27 # this is a path relative to /sys/devices,
28 # and can be undef (eg for ram disk)
29 # - special, a block special file giving access to the device
30 # in the currently running kernel, or undef.
31 # - yspecial, a block special file giving access to the device
32 # in the generated initrd image. This often needs
33 # a mknod on the generated image. It's not convenient
34 # to use the previous special, since that may be in
35 # a subdirectory unavailable on the initrd image.
36 # It's also not exactly /dev/$name, since LVM logical
37 # volumes follow another convention.
38 # - partitions, list of partitions contained in the device.
39 # these partitions are also ActiveBlockDevs.
41 # NOTE: the partition list relies on ActiveBlockDevTab making
42 # a complete scan of all block devices, each partition registering
43 # itself as partition with the parent device.
47 use BlockSpecialFileTab;
49 package ActiveBlockDev;
56 $self->takeArgs ('name', 'devno', 'parent', 'hw');
57 $self->{partitions} = [];
58 if (defined ($self->parent)) {
59 push @{$self->parent->partitions}, $self;
62 my $bfs = BlockSpecialFileTab::findByDevno($self->devno);
64 $self->{special} = $bfs->path;
67 $self->{special} = undef;
71 sub name { return $_[0]->{name}; }
72 sub devno { return $_[0]->{devno}; }
73 sub parent { return $_[0]->{parent}; }
74 sub hw { return $_[0]->{hw}; }
75 sub special { return $_[0]->{special}; }
76 sub partitions { return $_[0]->{partitions}; }
80 my $name = $self->name;
81 my $devno = $self->devno;
82 my $parent = (defined($self->parent) ? $self->parent->name : "--");
83 my $hw = ($self->hw or "--");
84 my $special = ($self->special or "--");
85 my $yspecial = ($self->yspecial or "--");
86 return "$name($devno) in $parent at $hw via $special becomes $yspecial";
91 my $name = $self->name;
92 my $devno = $self->devno;
93 my $yspecial = "/dev/$name";
94 my $lv = LvmTab::findLVByDevno ($devno);
96 $yspecial = $lv->lvnam;
103 return ($#{$self->partitions} >= 0);