From: Robert 'phaylon' Sedlacek Date: Thu, 3 May 2012 16:43:06 +0000 (+0000) Subject: MountPoints probe for fstab and mtab files X-Git-Tag: v0.001_001~130 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b99ec451f38899687ad3959334c5558dbe8c1b95;p=scpubgit%2FSystem-Introspector.git MountPoints probe for fstab and mtab files --- diff --git a/lib/System/Introspector/MountPoints.pm b/lib/System/Introspector/MountPoints.pm new file mode 100644 index 0000000..761cabe --- /dev/null +++ b/lib/System/Introspector/MountPoints.pm @@ -0,0 +1,47 @@ +package System::Introspector::MountPoints; +use Moo; + +sub gather { + my ($self) = @_; + return { + mtab => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')), + fstab => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')), + }; +} + +sub _open_fh { + my ($self, $file) = @_; + open my $fh, '<', $file + or die "Unable to open $file: $!\n"; + return $fh; +} + +sub _parse_tab_fh { + my ($self, $fh) = @_; + my @mounts; + while (defined( my $line = <$fh> )) { + chomp $line; + next if $line =~ m{^\s*$} + or $line =~ m{^\s*#}; + my ($device, $point, $type, $opt, $dump, $pass) + = split m{\s+}, $line; + push @mounts, { + device_name => $device, + moint_point => $point, + fs_type => $type, + dump_freq => $dump, + pass_num => $pass, + options => { + map { + my ($name, $value) = split m{=}, $_, 2; + $value = 1 + unless defined $value; + ($name => $value); + } split m{,}, $opt, + }, + }; + } + return \@mounts; +} + +1;