DiskUsage probe tests
[scpubgit/System-Introspector.git] / lib / System / Introspector / MountPoints.pm
CommitLineData
b99ec451 1package System::Introspector::MountPoints;
2use Moo;
3
4sub gather {
5 my ($self) = @_;
6 return {
7 mtab => $self->_parse_tab_fh($self->_open_fh('/etc/mtab')),
8 fstab => $self->_parse_tab_fh($self->_open_fh('/etc/fstab')),
9 };
10}
11
12sub _open_fh {
13 my ($self, $file) = @_;
14 open my $fh, '<', $file
15 or die "Unable to open $file: $!\n";
16 return $fh;
17}
18
19sub _parse_tab_fh {
20 my ($self, $fh) = @_;
21 my @mounts;
22 while (defined( my $line = <$fh> )) {
23 chomp $line;
24 next if $line =~ m{^\s*$}
25 or $line =~ m{^\s*#};
26 my ($device, $point, $type, $opt, $dump, $pass)
27 = split m{\s+}, $line;
28 push @mounts, {
29 device_name => $device,
46a24787 30 mount_point => $point,
b99ec451 31 fs_type => $type,
32 dump_freq => $dump,
33 pass_num => $pass,
34 options => {
35 map {
36 my ($name, $value) = split m{=}, $_, 2;
37 $value = 1
38 unless defined $value;
39 ($name => $value);
40 } split m{,}, $opt,
41 },
42 };
43 }
44 return \@mounts;
45}
46
471;