]> git.sur5r.net Git - bacula/rescue/blob - rescue/linux/cdrom/yaird-0.0.5/perl/FsOpts.pm
Initial revision
[bacula/rescue] / rescue / linux / cdrom / yaird-0.0.5 / perl / FsOpts.pm
1 #!perl -w
2 #
3 # FsOpts -- encapsulate the options in an FsEntry
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 package FsOpts;
23 use base 'Obj';
24
25
26 sub fill {
27         my $self = shift;
28         $self->SUPER::fill();
29
30         $self->takeArgs ('string');
31         my @optlist = split (/,/, $self->{string});
32         my $opthash = {};
33         for my $opt (@optlist) {
34                 if ($opt =~ /^(.*)=(.*)$/) {
35                         $opthash->{$1} = $2;
36                 }
37                 else {
38                         $opthash->{$opt} = undef;
39                 }
40         }
41         $self->{optsHash} = $opthash;
42 }
43
44 #
45 # exists -- the option occurs, possibly with undef value.
46 #
47 sub exists {
48         my ($self, $optnam) = @_;
49         return exists ($self->{optsHash}{$optnam});
50 }
51
52 sub get {
53         my ($self, $optnam) = @_;
54         return $self->{optsHash}{$optnam};
55 }
56
57 sub string {
58         my $self = shift;
59         my $opts = $self->{optsHash};
60         my @optlist = ();
61         for my $key (sort keys %{$opts}) {
62                 push @optlist, ("$key=" . ($opts->{$key} or "-"));
63         }
64         return join (',', @optlist);
65 }
66
67
68 #
69 # cmdLineVersion -- return a version of all options suitable for
70 # a mount command line.
71 # Note that some options in fstab can only be used in fstab,
72 # not in scripts.
73 #
74 sub cmdLineVersion {
75         my $self = shift;
76         my $opts = $self->{optsHash};
77
78         my @cmdLine = ();
79         for my $key (sort keys %{$opts}) {
80                 next if $key eq 'auto';
81                 next if $key eq 'noauto';
82                 next if $key eq 'nouser';
83                 next if $key eq 'owner';
84                 next if $key eq 'user';
85                 next if $key eq 'users';
86                 next if $key eq 'defaults';
87                 my $val = $opts->{$key};
88                 if (defined ($val)) {
89                         push @cmdLine, "$key=$val";
90                 }
91                 else {
92                         push @cmdLine, "$key";
93                 }
94         }
95         if ($#cmdLine == -1) {
96                 return "";
97         }
98         else {
99                 # protect against logdev=John's disk.
100                 my $cmdLine = join (',', @cmdLine);
101                 $cmdLine =~ s/(['\\])/\\$1/g; 
102                 return "-o '$cmdLine'";
103         }
104 }
105
106 1;
107