]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/FsEntry.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / FsEntry.pm
1 #!perl -w
2 #
3 # FsEntry -- encapsulate a single entry in /etc/fstab
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 use strict;
21 use warnings;
22 use LabeledPartitionTab;
23 package FsEntry;
24 use base 'Obj';
25
26 sub fill {
27         my $self = shift;
28         $self->SUPER::fill();
29         $self->takeArgs ('dev', 'mnt', 'type', 'opts');
30 }
31
32 sub dev         { return $_[0]->{dev}; }
33 sub mnt         { return $_[0]->{mnt}; }
34 sub type        { return $_[0]->{type}; }
35 sub opts        { return $_[0]->{opts}; }
36
37 sub string {
38         my $self = shift;
39         my $dev = $self->dev();
40         my $mnt = $self->mnt();
41         my $type = $self->type();
42         my $opts = $self->opts()->string();
43         return "$mnt at $dev ($type) with $opts";
44 }
45
46
47 #
48 # isRequiredAtBoot -- To be mounted at boot time with mount -a.
49 # This does not imply the initrd should already mount it.
50 #
51 sub isRequiredAtBoot {
52         my $self = shift;
53         return 0 if ($self->type eq "ignore");
54         return 0 if ($self->opts->exists("noauto"));
55         return 1;
56 }
57
58
59 #
60 # blockDevPath -- return blockdev pathname for an fstab entry.
61 # must resolve LABEL= and UUID=.  Note that LVM and raid devices
62 # may be implemented on top of multiple other devices; this returns
63 # only the top device.
64 #
65 # Returns undef if first field of fstab entry does not point to
66 # an existing block device.  Possible reasons:
67 # - filesystem does not have underlying device, such as /proc.
68 # - filesystem has a non-file underlying resource, such as NFS
69 # - garbage line with missing blockdev
70 # - filesystem has a plain file as underlying resource;
71 #   this can be a loopback file system, or swap to plain file.
72 #
73 # NOTE: We should support the last case, but for now that's too difficult:
74 # imagine /a/b/c, where /a is reiserfs, b is a symlink to /d (an NFS
75 # filesystem), and /d/c is a symlink to /e/f, where /e is a ramdisk.)
76 #
77 sub blockDevPath {
78         my $self = shift;
79         my $dev = $self->dev();
80         if ($dev =~  /^\//) {
81                 if (-f $dev && $self->opts->exists('loop')) {
82                         return undef;
83                 }
84                 if (-f $dev && $self->type eq "swap") {
85                         return undef;
86                 }
87                 if (-b $dev) {
88                         return $dev;
89                 }
90         }
91         elsif ($dev =~ /^LABEL=(.*)/) {
92                 return LabeledPartitionTab::findPathByLabel ($1);
93         }
94         elsif ($dev =~ /^UUID=(.*)/) {
95                 return LabeledPartitionTab::findPathByUuid ($1);
96         }
97         return undef;
98 }
99
100
101 1;