line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package BSD::Getfsent; |
2
|
|
|
|
|
|
|
|
3
|
2
|
|
|
2
|
|
84565
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
77
|
|
4
|
2
|
|
|
2
|
|
15
|
use warnings; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
79
|
|
5
|
2
|
|
|
2
|
|
14
|
use base qw(Exporter); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
370
|
|
6
|
2
|
|
|
2
|
|
1105
|
use boolean qw(true false); |
|
2
|
|
|
|
|
8756
|
|
|
2
|
|
|
|
|
13
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
217
|
use Carp qw(croak); |
|
2
|
|
|
|
|
6
|
|
|
2
|
|
|
|
|
142
|
|
9
|
2
|
|
|
2
|
|
1302
|
use IO::File (); |
|
2
|
|
|
|
|
22282
|
|
|
2
|
|
|
|
|
276
|
|
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
our ($VERSION, @EXPORT_OK, $ENTRIES, $FSTAB); |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
$VERSION = '0.18'; |
14
|
|
|
|
|
|
|
@EXPORT_OK = qw(getfsent); |
15
|
|
|
|
|
|
|
$ENTRIES = __PACKAGE__ . '::_fsents'; |
16
|
|
|
|
|
|
|
$FSTAB = '/etc/fstab'; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub getfsent |
19
|
|
|
|
|
|
|
{ |
20
|
7
|
100
|
|
7
|
1
|
224
|
if (wantarray) { |
21
|
2
|
|
|
2
|
|
22
|
no strict 'refs'; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
1221
|
|
22
|
|
|
|
|
|
|
|
23
|
6
|
100
|
|
|
|
11
|
unless (${$ENTRIES}) { |
|
6
|
|
|
|
|
71
|
|
24
|
1
|
|
|
|
|
3
|
@{$ENTRIES} = @{_parse_entries()}; |
|
1
|
|
|
|
|
7
|
|
|
1
|
|
|
|
|
3
|
|
25
|
1
|
|
|
|
|
8
|
${$ENTRIES} = true; |
|
1
|
|
|
|
|
6
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
6
|
100
|
|
|
|
56
|
if (@{$ENTRIES}) { |
|
6
|
|
|
|
|
24
|
|
29
|
5
|
|
|
|
|
21
|
return @{shift @{$ENTRIES}}; |
|
5
|
|
|
|
|
8
|
|
|
5
|
|
|
|
|
37
|
|
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
else { |
32
|
1
|
|
|
|
|
5
|
${$ENTRIES} = false; |
|
1
|
|
|
|
|
5
|
|
33
|
1
|
|
|
|
|
4
|
return (); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
} |
36
|
1
|
|
|
|
|
5
|
else { return _count_entries() } |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub _parse_entries |
40
|
|
|
|
|
|
|
{ |
41
|
1
|
|
|
1
|
|
3
|
my @entries; |
42
|
1
|
|
|
|
|
3
|
my $fh = _open_fh(); |
43
|
|
|
|
|
|
|
|
44
|
1
|
|
|
|
|
16
|
while (local $_ = <$fh>) { |
45
|
5
|
50
|
|
|
|
17
|
next if /^\#/; |
46
|
|
|
|
|
|
|
|
47
|
5
|
|
|
|
|
11
|
chomp; |
48
|
5
|
|
|
|
|
21
|
my @entry = split; |
49
|
|
|
|
|
|
|
|
50
|
5
|
100
|
|
|
|
19
|
if ($entry[3] !~ /,/) { # In case element 4, fs_type, doesn't |
51
|
1
|
|
|
|
|
6
|
splice(@entry, 3, 1, '', $entry[3]); # contain fs_mntops, insert blank fs_mntops |
52
|
|
|
|
|
|
|
} # at index 3 and move fs_type to index 4. |
53
|
|
|
|
|
|
|
else { # In case element 4 contains fs_type and |
54
|
4
|
|
|
|
|
17
|
splice(@entry, 3, 1, # fs_mntops, switch fs_mntops to index 3 and |
55
|
|
|
|
|
|
|
(reverse split ',', $entry[3], 2)); # fs_type to index 4. |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
5
|
|
|
|
|
44
|
push @entries, [ @entry ]; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
1
|
|
|
|
|
7
|
_close_fh($fh); |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
|
|
23
|
return \@entries; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub _count_entries |
67
|
|
|
|
|
|
|
{ |
68
|
1
|
|
|
1
|
|
2
|
my $counted_entries; |
69
|
|
|
|
|
|
|
|
70
|
1
|
|
|
|
|
6
|
my $fh = _open_fh(); |
71
|
1
|
|
|
|
|
40
|
$counted_entries++ while <$fh>; |
72
|
1
|
|
|
|
|
8
|
_close_fh($fh); |
73
|
|
|
|
|
|
|
|
74
|
1
|
|
|
|
|
41
|
return $counted_entries; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub _open_fh |
78
|
|
|
|
|
|
|
{ |
79
|
2
|
50
|
|
2
|
|
18
|
my $fh = IO::File->new("<$FSTAB") |
80
|
|
|
|
|
|
|
or croak "Cannot open $FSTAB: $!"; |
81
|
|
|
|
|
|
|
|
82
|
2
|
|
|
|
|
225
|
return $fh; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _close_fh |
86
|
|
|
|
|
|
|
{ |
87
|
2
|
|
|
2
|
|
7
|
my ($fh) = @_; |
88
|
2
|
|
|
|
|
15
|
$fh->close; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
1; |
92
|
|
|
|
|
|
|
__END__ |