blib/lib/Langertha/Holmgang/Sim/Linux/Storage.pm

filter: Statementstmt 78.4% 704 / 898 Branchbran 52.6% 297 / 564 Conditioncond 38.4% 235 / 612 MC/DCmcdc 9.2% 31 / 334 Subroutinesub 94.3% 50 / 53 Podpod 100% 17 / 17 totaltotal 53.8% 1334 / 2478 CC 586 SCAR 56.9
CC
586
Cov
60%
lvm
1130.0
swap
652.8
findmnt
274.7
CRAP 297.1
« blib/lib/Langertha/Holmgang/Sim/Linux/Http.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Git.pm »
1 package Langertha::Holmgang::Sim::Linux::Storage;
2 # ABSTRACT: Disks and file systems on a simulated Linux server — LVM, mount, fstab, swap, mdadm
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 ▶use JSON::MaybeXS ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 2 our $VERSION = '0.001';
11  
12  
13 2 my $T = JSON::MaybeXS::true();
14 2 my $F = JSON::MaybeXS::false();
15 129 ▶sub _lx { 'Langertha::Holmgang::Sim::Linux' }
Subroutine _lx: called CC=1 SCAR=0.0
16 129 ▶sub _L { my $n = shift; return _lx()->can($n)->(@_) }
Subroutine _L: called CC=1 SCAR=0.0
17 73 ▶sub _b { _L( '_bytes', @_ ) }
Subroutine _b: called CC=1 SCAR=0.0
18 13 ▶sub _h { _L( '_human', @_ ) }
Subroutine _h: called CC=1 SCAR=0.0
19 489 ▶sub _st { $_[0]{storage} //= {} }
Subroutine _st: called CC=2 SCAR=7.6
Condition50%1/2
$_[0]{"storage"} //= {}
l!l
4890
MC/DC0%0/1
$_[0]{"storage"} //= {}
$_[0]{"storage"}
Truth table50%1/2
A
A= $_[0]{"storage"}
Aresult
11
00
20  
21 # --- Geräte -----------------------------------------------------------------------
22  
23 # alle Geräte mit Dateisystem-Merkmalen: kanonischer Pfad => Eintrag
24 438 ▶sub _all {
Subroutine _all: called CC=9 SCAR=22.7
25 438 my ($dev) = @_;
26 438 my $s = _st($dev);
27 438 my %d;
28 438 ▶ $d{$_} = $s->{disks}{$_} for keys %{ $s->{disks} || {} };
Condition50%1/2
$$s{'disks'} || {}
l!l
4380
MC/DC0%0/1
$$s{'disks'} || {}
$$s{'disks'}
Truth table50%1/2
A
A= $$s{'disks'}
Aresult
11
00
29 438 ▶ $d{$_} = $s->{md}{$_} for keys %{ $s->{md} || {} };
Condition50%1/2
$$s{'md'} || {}
l!l
4380
MC/DC0%0/1
$$s{'md'} || {}
$$s{'md'}
Truth table50%1/2
A
A= $$s{'md'}
Aresult
11
00
30 438 ▶ for my $vg ( keys %{ $s->{vgs} || {} } ) {
Condition50%1/2
$$s{'vgs'} || {}
l!l
4380
MC/DC0%0/1
$$s{'vgs'} || {}
$$s{'vgs'}
Truth table50%1/2
A
A= $$s{'vgs'}
Aresult
11
00
31 438 ▶ my $lvs = $s->{vgs}{$vg}{lvs} || {};
Condition50%1/2
$$s{'vgs'}{$vg}{'lvs'} || {}
l!l
4380
MC/DC0%0/1
$$s{'vgs'}{$vg}{'lvs'} || {}
$$s{'vgs'}{$vg}{'lvs'}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'lvs'}
Aresult
11
00
32 438 $d{"/dev/mapper/$vg-$_"} = $lvs->{$_} for keys %$lvs;
33 }
34 438 return \%d;
35 }
36  
37  
38 389 ▶sub canon {
Subroutine canon: called CC=12 SCAR=25.2
Pod documented
39 389 my ( $dev, $p ) = @_;
40 389 ▶ return undef unless defined $p;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 389 389
41 389 $p =~ s{/+\z}{};
42 389 my $all = _all($dev);
43 389 ▶ return $p if $all->{$p};
Branch: 1 branch
BranchTrueFalseTotal
if $$all{$p} 359 30 389
44 30 ▶ if ( $p =~ m{\A/dev/([\w.-]+)/([\w.+-]+)\z} && $1 ne 'mapper' && $1 ne 'disk' ) { my $c = "/dev/mapper/$1-$2"; return $c if $all->{$c} }
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z] and $1 ne "mapper" and $1 ne "disk") 2 28 30
if $$all{$c} 2 0 2
Condition66%4/6
$p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z] and $1 ne "mapper" and $1 ne "disk"
!ll&&!rl&&r
2802
$p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z] and $1 ne "mapper"
!ll&&!rl&&r
2802
MC/DC33%1/3
$p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z] and $1 ne "mapper" and $1 ne "disk"
$p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z] $1 ne "mapper" $1 ne "disk"
Truth table50%2/4
A and B and C
A= $p =~ m[\A/dev/([\w.-]+)/([\w.+-]+)\z]B= $1 ne "mapper"C= $1 ne "disk"
ABCresult
0XX0
10X0
1100
1111
45 28 ▶ if ( $p =~ m{\A([\w.-]+)/([\w.+-]+)\z} ) { my $c = "/dev/mapper/$1-$2"; return $c if $all->{$c} } # vg/lv
Branch: 2 branches
BranchTrueFalseTotal
if ($p =~ m[\A([\w.-]+)/([\w.+-]+)\z]) 1 27 28
if $$all{$c} 1 0 1
46 27 ▶ if ( $p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/i || $p =~ m{\A/dev/disk/by-(uuid|label)/(.+)\z} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/i or $p =~ m[\A/dev/disk/by-(uuid|label)/(.+)\z]) 5 22 27
Condition66%2/3
$p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/i or $p =~ m[\A/dev/disk/by-(uuid|label)/(.+)\z]
l!l&&r!l&&!r
5022
MC/DC50%1/2
$p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/i or $p =~ m[\A/dev/disk/by-(uuid|label)/(.+)\z]
$p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/i $p =~ m[\A/dev/disk/by-(uuid|label)/(.+)\z]
Truth table66%2/3
A or B
A= $p =~ /\A(UUID|LABEL)=["']?([^"']+)["']?\z/iB= $p =~ m[\A/dev/disk/by-(uuid|label)/(.+)\z]
ABresult
1X1
011
000
47 5 my ( $k, $v ) = ( lc $1, $2 );
48 5 ▶ my ($hit) = grep { ( $all->{$_}{$k} // '' ) eq $v } sort keys %$all;
Condition100%2/2
$$all{$_}{$k} // ""
l!l
2545
MC/DC100%1/1
$$all{$_}{$k} // ""
$$all{$_}{$k}
Truth table100%2/2
A
A= $$all{$_}{$k}
Aresult
11
00
49 5 return $hit;
50 }
51 22 return undef;
52 }
53  
54 47 ▶sub _bd { my ( $dev, $p ) = @_; my $c = canon( $dev, $p ) // return; return ( $c, _all($dev)->{$c} ) }
Subroutine _bd: called CC=2 SCAR=6.9
Condition100%2/2
canon($dev, $p) // (return)
l!l
416
MC/DC100%1/1
canon($dev, $p) // (return)
canon($dev, $p)
Truth table100%2/2
A
A= canon($dev, $p)
Aresult
11
00
55  
56 2 ▶sub _fssize { my ($e) = @_; return _b( $e->{fssize} // $e->{size} ) }
Subroutine _fssize: called CC=2 SCAR=8.1
Condition33%1/3
$$e{"fssize"} // $$e{"size"}
l!l&&r!l&&!r
020
MC/DC0%0/2
$$e{"fssize"} // $$e{"size"}
$$e{"fssize"} $$e{"size"}
Truth table33%1/3
A // B
A= $$e{"fssize"}B= $$e{"size"}
ABresult
1X1
011
000
57  
58 36 ▶sub _mounted_at {
Subroutine _mounted_at: called CC=3 SCAR=11.3
59 36 my ( $dev, $c ) = @_;
60 36 ▶ my $m = $dev->{mounts} || {};
Condition50%1/2
$$dev{'mounts'} || {}
l!l
360
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
61 36 ▶ return grep { defined canon( $dev, $m->{$_}{dev} ) && canon( $dev, $m->{$_}{dev} ) eq $c } sort keys %$m;
Condition66%2/3
defined canon($dev, $$m{$_}{'dev'}) && canon($dev, $$m{$_}{'dev'}) eq $c
!ll&&!rl&&r
012318
MC/DC50%1/2
defined canon($dev, $$m{$_}{'dev'}) && canon($dev, $$m{$_}{'dev'}) eq $c
defined canon($dev, $$m{$_}{'dev'}) canon($dev, $$m{$_}{'dev'}) eq $c
Truth table66%2/3
A && B
A= defined canon($dev, $$m{$_}{'dev'})B= canon($dev, $$m{$_}{'dev'}) eq $c
ABresult
0X0
100
111
62 }
63  
64 5 ▶sub _vg_of_pv {
Subroutine _vg_of_pv: called CC=5 SCAR=16.6
65 5 my ( $dev, $pv ) = @_;
66 5 my $s = _st($dev);
67 5 ▶ for my $vg ( sort keys %{ $s->{vgs} || {} } ) { return $vg if grep { $_ eq $pv } @{ $s->{vgs}{$vg}{pvs} || [] } }
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $pv;} @{$$s{"vgs"}{$vg}{"pvs"} or [];} 0 5 5
Condition50%2/4
$$s{'vgs'} || {}
l!l
50
$$s{'vgs'}{$vg}{'pvs'} || []
l!l
50
MC/DC0%0/1
$$s{'vgs'} || {}
$$s{'vgs'}
MC/DC0%0/1
$$s{'vgs'}{$vg}{'pvs'} || []
$$s{'vgs'}{$vg}{'pvs'}
Truth table50%1/2
A
A= $$s{'vgs'}
Aresult
11
00
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'pvs'}
Aresult
11
00
68 5 return;
69 }
70  
71 4 ▶sub _vg_size {
Subroutine _vg_size: called CC=6 SCAR=18.4
72 4 my ( $dev, $vg ) = @_;
73 4 my $s = _st($dev);
74 4 my $size = 0;
75 4 ▶ $size += _b( $s->{disks}{$_}{size} // 0 ) for @{ $s->{vgs}{$vg}{pvs} || [] };
Condition50%2/4
$$s{'vgs'}{$vg}{'pvs'} || []
l!l
40
$$s{"disks"}{$_}{"size"} // 0
l!l
60
MC/DC0%0/1
$$s{'vgs'}{$vg}{'pvs'} || []
$$s{'vgs'}{$vg}{'pvs'}
MC/DC0%0/1
$$s{"disks"}{$_}{"size"} // 0
$$s{"disks"}{$_}{"size"}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'pvs'}
Aresult
11
00
Truth table50%1/2
A
A= $$s{"disks"}{$_}{"size"}
Aresult
11
00
76 4 my $used = 0;
77 4 ▶ $used += _b( $_->{size} ) for values %{ $s->{vgs}{$vg}{lvs} || {} };
Condition50%1/2
$$s{'vgs'}{$vg}{'lvs'} || {}
l!l
40
MC/DC0%0/1
$$s{'vgs'}{$vg}{'lvs'} || {}
$$s{'vgs'}{$vg}{'lvs'}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'lvs'}
Aresult
11
00
78 4 return ( $size, $size - $used );
79 }
80  
81 10 ▶sub _parts { my ( $dev, $disk ) = @_; my $d = _st($dev)->{disks} || {}; return sort grep { ( $d->{$_}{parent} // '' ) eq $disk } keys %$d }
Subroutine _parts: called CC=3 SCAR=11.0
Condition75%3/4
_st($dev)->{'disks'} || {}
l!l
100
$$d{$_}{"parent"} // ""
l!l
4370
MC/DC0%0/1
_st($dev)->{'disks'} || {}
_st($dev)->{'disks'}
MC/DC100%1/1
$$d{$_}{"parent"} // ""
$$d{$_}{"parent"}
Truth table50%1/2
A
A= _st($dev)->{'disks'}
Aresult
11
00
Truth table100%2/2
A
A= $$d{$_}{"parent"}
Aresult
11
00
82  
83 5 ▶sub _gib { my ($b) = @_; return sprintf '%.2f GiB', $b / 1024**3 }
Subroutine _gib: called CC=1 SCAR=0.0
84 2 ▶sub _g { my ($b) = @_; my $x = $b / 1024**3; return $x == int $x ? "${x}g" : sprintf( '%.2fg', $x ) }
Subroutine _g: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$x == int $x ? : 2 0 2
85  
86  
87 6 ▶sub prepare {
Subroutine prepare: called CC=15 SCAR=30.1
Pod documented
88 6 my ( $dev, $ctx ) = @_;
89 6 ▶ my $s = $dev->{storage} or return;
Branch: 1 branch
BranchTrueFalseTotal
my $s = $$dev{"storage"} or return 6 0 6
90 6 ▶ for my $mp ( keys %{ $dev->{mounts} || {} } ) {
Condition50%1/2
$$dev{'mounts'} || {}
l!l
60
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
91 24 my $m = $dev->{mounts}{$mp};
92 24 my ( $c, $e ) = _bd( $dev, $m->{dev} );
93 24 ▶ next unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 24 24
94 24 ▶ $m->{fstype} //= $e->{fstype} if defined $e->{fstype};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$e{"fstype"} 24 0 24
Condition33%1/3
$$m{"fstype"} //= $$e{"fstype"}
l!l&&r!l&&!r
0240
MC/DC0%0/2
$$m{"fstype"} //= $$e{"fstype"}
$$m{"fstype"} $$e{"fstype"}
Truth table33%1/3
A //= B
A= $$m{"fstype"}B= $$e{"fstype"}
ABresult
1X1
011
000
95 24 ▶ $m->{opts} //= 'rw,relatime';
Condition50%1/2
$$m{"opts"} //= "rw,relatime"
l!l
024
MC/DC0%0/1
$$m{"opts"} //= "rw,relatime"
$$m{"opts"}
Truth table50%1/2
A
A= $$m{"opts"}
Aresult
11
00
96 24 ▶ $e->{reserved_pct} //= $m->{reserved_pct} if defined $m->{reserved_pct};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$m{"reserved_pct"} 6 18 24
Condition33%1/3
$$e{"reserved_pct"} //= $$m{"reserved_pct"}
l!l&&r!l&&!r
060
MC/DC0%0/2
$$e{"reserved_pct"} //= $$m{"reserved_pct"}
$$e{"reserved_pct"} $$m{"reserved_pct"}
Truth table33%1/3
A //= B
A= $$e{"reserved_pct"}B= $$m{"reserved_pct"}
ABresult
1X1
011
000
97 }
98 6 ▶ $s->{fstab_loaded} //= _L( '_file_text', $dev, '/etc/fstab' ) // '';
Condition50%2/4
$$s{"fstab_loaded"} //= _L("_file_text", $dev, "/etc/fstab") // ""
l!l
06
_L("_file_text", $dev, "/etc/fstab") // ""
l!l
60
MC/DC0%0/1
$$s{"fstab_loaded"} //= _L("_file_text", $dev, "/etc/fstab") // ""
$$s{"fstab_loaded"}
Truth table50%1/2
A
A= $$s{"fstab_loaded"}
Aresult
11
00
99 # Einhaengepunkte sind Verzeichnisse, auch wenn gerade nichts eingehaengt ist
100 6 ▶ $dev->{dirs}{$_} //= {} for grep { m{\A/.} } ( keys %{ $dev->{mounts} || {} } ), map { $_->{mp} =~ s{(?<=.)/+\z}{}r } _fstab($dev);
Condition75%3/4
$$dev{'mounts'} || {}
l!l
60
$$dev{"dirs"}{$_} //= {}
l!l
618
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
MC/DC100%1/1
$$dev{"dirs"}{$_} //= {}
$$dev{"dirs"}{$_}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
Truth table100%2/2
A
A= $$dev{"dirs"}{$_}
Aresult
11
00
101 6 return;
102 }
103  
104 # --- fstab, mount ------------------------------------------------------------------
105  
106 11 ▶sub _fstab {
Subroutine _fstab: called CC=6 SCAR=18.7
107 11 my ($dev) = @_;
108 11 my @e;
109 11 my $n = 0;
110 11 ▶ for my $l ( split /\n/, _L( '_file_text', $dev, '/etc/fstab' ) // '' ) {
Condition50%1/2
_L("_file_text", $dev, "/etc/fstab") // ""
l!l
110
MC/DC0%0/1
_L("_file_text", $dev, "/etc/fstab") // ""
_L("_file_text", $dev, "/etc/fstab")
Truth table50%1/2
A
A= _L("_file_text", $dev, "/etc/fstab")
Aresult
11
00
111 25 $n++;
112 25 ▶ next if $l =~ /\A\s*(?:#|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $l =~ /\A\s*(?:#|\z)/ 0 25 25
113 25 my @f = split ' ', $l;
114 25 ▶ push @e, { src => $f[0], mp => $f[1], type => $f[2] // 'auto', opts => $f[3] // 'defaults', line => $n };
Condition50%2/4
$f[2] // "auto"
l!l
250
$f[3] // "defaults"
l!l
250
MC/DC0%0/1
$f[2] // "auto"
$f[2]
MC/DC0%0/1
$f[3] // "defaults"
$f[3]
Truth table50%1/2
A
A= $f[2]
Aresult
11
00
Truth table50%1/2
A
A= $f[3]
Aresult
11
00
115 }
116 11 return @e;
117 }
118  
119 4 ▶sub _merge_opts {
Subroutine _merge_opts: called CC=12 SCAR=26.9
120 4 my ( $old, $new ) = @_;
121 4 ▶ my @o = grep { length && $_ ne 'defaults' } split /,/, $old // '';
Condition40%2/5
length $_ && $_ ne 'defaults'
!ll&&!rl&&r
008
$old // ""
l!l
40
MC/DC0%0/2
length $_ && $_ ne 'defaults'
length $_ $_ ne 'defaults'
MC/DC0%0/1
$old // ""
$old
Truth table33%1/3
A && B
A= length $_B= $_ ne 'defaults'
ABresult
0X0
100
111
Truth table50%1/2
A
A= $old
Aresult
11
00
122 4 my %pair = ( ro => 'rw', rw => 'ro', exec => 'noexec', noexec => 'exec', suid => 'nosuid', nosuid => 'suid', dev => 'nodev', nodev => 'dev',
123 atime => 'noatime', noatime => 'atime' );
124 4 ▶ for my $x ( grep { length && !/\A(?:remount|defaults|nofail|noauto|auto|_netdev|user|nouser|x-.*|comment=.*)\z/ } split /,/, $new // '' ) {
Condition80%4/5
length $_ && !/\A(?:remount|defaults|nofail|noauto|auto|_netdev|user|nouser|x-.*|comment=.*)\z/
!ll&&!rl&&r
032
$new // ""
l!l
31
MC/DC50%1/2
length $_ && !/\A(?:remount|defaults|nofail|noauto|auto|_netdev|user|nouser|x-.*|comment=.*)\z/
length $_ !/\A(?:remount|defaults|nofail|noauto|auto|_netdev|user|nouser|x-.*|comment=.*)\z/
MC/DC100%1/1
$new // ""
$new
Truth table66%2/3
A && not(B)
A= length $_B= !/\A(?:remount|defaults|nofail|noauto|auto|_netdev|user|nouser|x-.*|comment=.*)\z/
ABresult
0X0
100
111
Truth table100%2/2
A
A= $new
Aresult
11
00
125 2 ▶ @o = grep { $_ ne $x && $_ ne ( $pair{$x} // '' ) } @o;
Condition40%2/5
$_ ne $x && $_ ne ($pair{$x} // '')
!ll&&!rl&&r
005
$pair{$x} // ""
l!l
50
MC/DC0%0/2
$_ ne $x && $_ ne ($pair{$x} // '')
$_ ne $x $_ ne ($pair{$x} // '')
MC/DC0%0/1
$pair{$x} // ""
$pair{$x}
Truth table33%1/3
A && B
A= $_ ne $xB= $_ ne ($pair{$x} // '')
ABresult
0X0
100
111
Truth table50%1/2
A
A= $pair{$x}
Aresult
11
00
126 2 push @o, $x;
127 }
128 4 ▶ unshift @o, 'rw' unless grep { $_ eq 'ro' || $_ eq 'rw' } @o;
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq "ro" or $_ eq "rw";} @o 0 4 4
Condition66%2/3
$_ eq 'ro' || $_ eq 'rw'
l!l&&r!l&&!r
046
MC/DC50%1/2
$_ eq 'ro' || $_ eq 'rw'
$_ eq 'ro' $_ eq 'rw'
Truth table66%2/3
A || B
A= $_ eq 'ro'B= $_ eq 'rw'
ABresult
1X1
011
000
129 4 ▶ @o = ( ( grep { $_ eq 'ro' || $_ eq 'rw' } @o ), grep { $_ ne 'ro' && $_ ne 'rw' } @o );
Condition66%4/6
$_ eq 'ro' || $_ eq 'rw'
l!l&&r!l&&!r
046
$_ ne 'ro' && $_ ne 'rw'
!ll&&!rl&&r
046
MC/DC50%1/2
$_ eq 'ro' || $_ eq 'rw'
$_ eq 'ro' $_ eq 'rw'
MC/DC50%1/2
$_ ne 'ro' && $_ ne 'rw'
$_ ne 'ro' $_ ne 'rw'
Truth table66%2/3
A || B
A= $_ eq 'ro'B= $_ eq 'rw'
ABresult
1X1
011
000
Truth table66%2/3
A && B
A= $_ ne 'ro'B= $_ ne 'rw'
ABresult
0X0
100
111
130 4 return join ',', @o;
131 }
132  
133 4 ▶sub _do_mount {
Subroutine _do_mount: called CC=23 SCAR=39.0
134 4 my ( $dev, $src, $mp, $type, $opts ) = @_;
135 4 my ( $c, $e ) = _bd( $dev, $src );
136 4 ▶ return "mount: $mp: special device $src does not exist." unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 2 2 4
137 2 $mp =~ s{(?<=.)/+\z}{};
138 2 ▶ return "mount: $mp: mount point does not exist." unless _L( '_is_dir', $dev, $mp ) || ( $dev->{dirs} || {} )->{$mp};
Branch: 1 branch
BranchTrueFalseTotal
unless _L("_is_dir", $dev, $mp) or ($$dev{"dirs"} || {})->{$mp} 0 2 2
Condition20%1/5
_L("_is_dir", $dev, $mp) or ($$dev{"dirs"} || {})->{$mp}
l!l&&r!l&&!r
200
$$dev{'dirs'} || {}
l!l
00
MC/DC0%0/2
_L("_is_dir", $dev, $mp) or ($$dev{"dirs"} || {})->{$mp}
_L("_is_dir", $dev, $mp) $$dev{'dirs'}
Truth table33%1/3
A or B
A= _L("_is_dir", $dev, $mp)B= $$dev{'dirs'}
ABresult
1X1
011
000
139 2 my ($already) = _mounted_at( $dev, $c );
140 2 ▶ return "mount: $mp: $src already mounted on $already." if defined $already;
Branch: 1 branch
BranchTrueFalseTotal
if defined $already 0 2 2
141 2 ▶ return "mount: $mp: $mp already mounted or mount point busy." if ( $dev->{mounts} || {} )->{$mp};
Branch: 1 branch
BranchTrueFalseTotal
if ($$dev{"mounts"} || {})->{$mp} 0 2 2
Condition50%1/2
$$dev{'mounts'} || {}
l!l
20
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
142 2 my $fs = $e->{fstype};
143 2 ▶ return "mount: $mp: wrong fs type, bad option, bad superblock on $c, missing codepage or helper program, or other error." unless $fs && $fs !~ /\A(?:swap|LVM2_member|linux_raid_member)\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless $fs and not $fs =~ /\A(?:swap|LVM2_member|linux_raid_member)\z/ 0 2 2
Condition33%1/3
$fs and not $fs =~ /\A(?:swap|LVM2_member|linux_raid_member)\z/
!ll&&!rl&&r
002
MC/DC0%0/2
$fs and not $fs =~ /\A(?:swap|LVM2_member|linux_raid_member)\z/
$fs not $fs =~ /\A(?:swap|LVM2_member|linux_raid_member)\z/
Truth table33%1/3
A and not(B)
A= $fsB= not $fs =~ /\A(?:swap|LVM2_member|linux_raid_member)\z/
ABresult
0X0
100
111
144 2 ▶ return "mount: $mp: unknown filesystem type '$type'." if defined $type && $type ne 'auto' && $type ne $fs;
Branch: 1 branch
BranchTrueFalseTotal
if defined $type and $type ne "auto" and $type ne $fs 0 2 2
Condition66%4/6
defined $type and $type ne "auto" and $type ne $fs
!ll&&!rl&&r
110
defined $type and $type ne "auto"
!ll&&!rl&&r
101
MC/DC0%0/3
defined $type and $type ne "auto" and $type ne $fs
defined $type $type ne "auto" $type ne $fs
Truth table50%2/4
A and B and C
A= defined $typeB= $type ne "auto"C= $type ne $fs
ABCresult
0XX0
10X0
1100
1111
145 # was unter dem Einhängepunkt lag, wird verdeckt; das Dateisystem bringt seine Dateien mit
146 2 ▶ my $off = delete $e->{offline} || {};
Condition50%1/2
delete $$e{'offline'} || {}
l!l
20
MC/DC0%0/1
delete $$e{'offline'} || {}
delete $$e{'offline'}
Truth table50%1/2
A
A= delete $$e{'offline'}
Aresult
11
00
147 0 for my $p ( _L( '_under', $dev, $mp ) ) { $e->{hidden}{$p} = delete $dev->{files}{$p} }
148 0 ▶ my $hid = $e->{hidden} ? { %{ $e->{hidden} } } : undef;
Branch: 1 branch
BranchTrueFalseTotal
$$e{'hidden'} ? : 0 2 2
149 2 delete $e->{hidden};
150 2 ▶ for my $rel ( keys %{ $off->{files} || {} } ) { $dev->{files}{ ( $mp eq '/' ? '' : $mp ) . $rel } = $off->{files}{$rel} }
Branch: 1 branch
BranchTrueFalseTotal
$mp eq '/' ? : 0 2 2
Condition50%1/2
$$off{'files'} || {}
l!l
20
MC/DC0%0/1
$$off{'files'} || {}
$$off{'files'}
Truth table50%1/2
A
A= $$off{'files'}
Aresult
11
00
151 $dev->{mounts}{$mp} = { dev => $c, size => _h( _fssize($e) ), used => $off->{used} // '100M', fstype => $fs, opts => _merge_opts( 'rw,relatime', $opts ),
152 2 ▶ ( defined $e->{reserved_pct} ? ( reserved_pct => $e->{reserved_pct} ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $$e{'reserved_pct'} ? : 2 0 2
Condition50%1/2
$$off{"used"} // "100M"
l!l
20
MC/DC0%0/1
$$off{"used"} // "100M"
$$off{"used"}
Truth table50%1/2
A
A= $$off{"used"}
Aresult
11
00
153 2 ▶ _st($dev)->{covered}{$mp} = $hid if $hid && %$hid;
Branch: 1 branch
BranchTrueFalseTotal
if $hid and %$hid 0 2 2
Condition33%1/3
$hid and %$hid
!ll&&!rl&&r
200
MC/DC0%0/2
$hid and %$hid
$hid %$hid
Truth table33%1/3
A and B
A= $hidB= %$hid
ABresult
0X0
100
111
154 2 return undef;
155 }
156  
157 4 ▶sub _do_umount {
Subroutine _do_umount: called CC=17 SCAR=31.1
158 4 my ( $dev, $mp, $lazy ) = @_;
159 4 my $m = $dev->{mounts}{$mp};
160 4 ▶ for my $n ( sort keys %{ $dev->{services} || {} } ) {
Condition50%1/2
$$dev{'services'} || {}
l!l
40
MC/DC0%0/1
$$dev{'services'} || {}
$$dev{'services'}
Truth table50%1/2
A
A= $$dev{'services'}
Aresult
11
00
161 4 my $svc = $dev->{services}{$n};
162 4 ▶ next unless $svc->{active};
Branch: 1 branch
BranchTrueFalseTotal
unless $$svc{"active"} 3 1 4
163 1 ▶ return "umount: $mp: target is busy." if grep { $_ eq $mp || index( $_, "$mp/" ) == 0 } @{ $svc->{uses} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $mp or index($_, "$mp/") == 0;} @{$$svc{"uses"} or [];} 1 0 1
Condition40%2/5
$_ eq $mp || index($_, "$mp/") == 0
l!l&&r!l&&!r
100
$$svc{'uses'} || []
l!l
10
MC/DC0%0/2
$_ eq $mp || index($_, "$mp/") == 0
$_ eq $mp index($_, "$mp/") == 0
MC/DC0%0/1
$$svc{'uses'} || []
$$svc{'uses'}
Truth table33%1/3
A || B
A= $_ eq $mpB= index($_, "$mp/") == 0
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$svc{'uses'}
Aresult
11
00
164 }
165 3 my ( $c, $e ) = _bd( $dev, $m->{dev} );
166 3 my %files;
167 3 ▶ for my $p ( _L( '_under', $dev, $mp ) ) { $files{ substr( $p, length( $mp eq '/' ? '' : $mp ) ) } = delete $dev->{files}{$p} }
Branch: 1 branch
BranchTrueFalseTotal
$mp eq '/' ? : 0 3 3
168 3 ▶ if ($e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 3 0 3
169 3 ▶ $e->{offline} = { used => $m->{used}, ( %files ? ( files => \%files ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
%files ? : 3 0 3
170 3 ▶ $e->{fssize} = $m->{size} if _b( $m->{size} ) != _b( $e->{size} );
Branch: 1 branch
BranchTrueFalseTotal
if _b($$m{"size"}) != _b($$e{"size"}) 0 3 3
171 3 ▶ $e->{reserved_pct} = $m->{reserved_pct} if defined $m->{reserved_pct};
Branch: 1 branch
BranchTrueFalseTotal
if defined $$m{"reserved_pct"} 3 0 3
172 }
173 3 delete $dev->{mounts}{$mp};
174 3 ▶ $dev->{dirs}{$mp} //= {};
Condition50%1/2
$$dev{"dirs"}{$mp} //= {}
l!l
30
MC/DC0%0/1
$$dev{"dirs"}{$mp} //= {}
$$dev{"dirs"}{$mp}
Truth table50%1/2
A
A= $$dev{"dirs"}{$mp}
Aresult
11
00
175 3 ▶ my $cov = delete( ( _st($dev)->{covered} || {} )->{$mp} ) || {};
Condition50%2/4
delete((_st($dev)->{'covered'} || {})->{$mp}) || {}
l!l
03
_st($dev)->{'covered'} || {}
l!l
03
MC/DC0%0/1
delete((_st($dev)->{'covered'} || {})->{$mp}) || {}
_st($dev)->{'covered'}
Truth table50%1/2
A
A= _st($dev)->{'covered'}
Aresult
11
00
176 3 $dev->{files}{$_} = $cov->{$_} for keys %$cov;
177 3 return undef;
178 }
179  
180 5 ▶sub _fstab_hint {
Subroutine _fstab_hint: called CC=4 SCAR=14.3
181 5 my ($dev) = @_;
182 5 ▶ my $now = _L( '_file_text', $dev, '/etc/fstab' ) // '';
Condition50%1/2
_L("_file_text", $dev, "/etc/fstab") // ""
l!l
50
MC/DC0%0/1
_L("_file_text", $dev, "/etc/fstab") // ""
_L("_file_text", $dev, "/etc/fstab")
Truth table50%1/2
A
A= _L("_file_text", $dev, "/etc/fstab")
Aresult
11
00
183 5 ▶ return $now ne ( _st($dev)->{fstab_loaded} // '' ) ? "mount: (hint) your fstab has been modified, but systemd still uses\n the old version; use 'systemctl daemon-reload' to reload." : ();
Branch: 1 branch
BranchTrueFalseTotal
$now ne (_st($dev)->{'fstab_loaded'} // '') ? : 1 4 5
Condition50%1/2
_st($dev)->{"fstab_loaded"} // ""
l!l
50
MC/DC0%0/1
_st($dev)->{"fstab_loaded"} // ""
_st($dev)->{"fstab_loaded"}
Truth table50%1/2
A
A= _st($dev)->{"fstab_loaded"}
Aresult
11
00
184 }
185  
186  
187 5 ▶sub mount {
Subroutine mount: called CC=44 SCAR=51.5
Pod documented
188 5 my ( $dev, $av ) = @_;
189 5 my ( @a, $type, $opts, $all );
190 5 my @w = @$av;
191 5 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 7 5 12
192 7 my $x = shift @w;
193 0 ▶ if ( $x eq '-t' ) { $type = shift @w }
Branch: 5 branches
BranchTrueFalseTotal
if ($x eq '-t') { } 0 7 7
elsif ($x eq '-o') { } 1 6 7
elsif ($x =~ /\A-o(.+)\z/) { } 0 6 6
elsif ($x eq '-a' or $x eq '--all') { } 3 3 6
elsif ($x =~ /\A-[vfnr]+\z/ or $x eq '--verbose') { } 0 3 3
194 1 elsif ( $x eq '-o' ) { $opts = shift @w }
195 0 elsif ( $x =~ /\A-o(.+)\z/ ) { $opts = $1 }
196 3 ▶ elsif ( $x eq '-a' || $x eq '--all' ) { $all = 1 }
Condition66%2/3
$x eq "-a" or $x eq "--all"
l!l&&r!l&&!r
303
MC/DC50%1/2
$x eq "-a" or $x eq "--all"
$x eq "-a" $x eq "--all"
Truth table66%2/3
A or B
A= $x eq "-a"B= $x eq "--all"
ABresult
1X1
011
000
197 ▶ elsif ( $x =~ /\A-[vfnr]+\z/ || $x eq '--verbose' ) { }
Condition33%1/3
$x =~ /\A-[vfnr]+\z/ or $x eq "--verbose"
l!l&&r!l&&!r
003
MC/DC0%0/2
$x =~ /\A-[vfnr]+\z/ or $x eq "--verbose"
$x =~ /\A-[vfnr]+\z/ $x eq "--verbose"
Truth table33%1/3
A or B
A= $x =~ /\A-[vfnr]+\z/B= $x eq "--verbose"
ABresult
1X1
011
000
198 3 else { push @a, $x }
199 }
200 5 ▶ my $m = $dev->{mounts} || {};
Condition50%1/2
$$dev{'mounts'} || {}
l!l
50
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
201 5 ▶ if ( !@a && !$all ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@a or $all) 0 5 5
Condition66%2/3
@a or $all
l!l&&r!l&&!r
230
MC/DC0%0/2
@a or $all
@a $all
Truth table66%2/3
A or B
A= @aB= $all
ABresult
1X1
011
000
202 0 ▶ return ( join( "\n", map { "$m->{$_}{dev} on $_ type " . ( $m->{$_}{fstype} // 'ext4' ) . ' (' . ( $m->{$_}{opts} // 'rw,relatime' ) . ')' } sort keys %$m ), 1 );
Condition0%0/4
$$m{$_}{"fstype"} // "ext4"
l!l
00
$$m{$_}{"opts"} // "rw,relatime"
l!l
00
MC/DC0%0/1
$$m{$_}{"fstype"} // "ext4"
$$m{$_}{"fstype"}
MC/DC0%0/1
$$m{$_}{"opts"} // "rw,relatime"
$$m{$_}{"opts"}
Truth table0%0/2
A
A= $$m{$_}{"fstype"}
Aresult
11
00
Truth table0%0/2
A
A= $$m{$_}{"opts"}
Aresult
11
00
203 }
204 5 my @hint = _fstab_hint($dev);
205 5 ▶ if ($all) {
Branch: 1 branch
BranchTrueFalseTotal
if ($all) 3 2 5
206 3 my @err;
207 3 for my $f ( _fstab($dev) ) {
208 8 ▶ next if $f->{type} eq 'swap' || $f->{mp} eq 'none' || $f->{opts} =~ /(?:\A|,)noauto(?:,|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
if $$f{"type"} eq "swap" or $$f{"mp"} eq "none" or $$f{"opts"} =~ /(?:\A|,)noauto(?:,|\z)/ 0 8 8
Condition33%2/6
$$f{"type"} eq "swap" or $$f{"mp"} eq "none" or $$f{"opts"} =~ /(?:\A|,)noauto(?:,|\z)/
l!l&&r!l&&!r
008
$$f{"type"} eq "swap" or $$f{"mp"} eq "none"
l!l&&r!l&&!r
008
MC/DC0%0/3
$$f{"type"} eq "swap" or $$f{"mp"} eq "none" or $$f{"opts"} =~ /(?:\A|,)noauto(?:,|\z)/
$$f{"type"} eq "swap" $$f{"mp"} eq "none" $$f{"opts"} =~ /(?:\A|,)noauto(?:,|\z)/
Truth table25%1/4
A or B or C
A= $$f{"type"} eq "swap"B= $$f{"mp"} eq "none"C= $$f{"opts"} =~ /(?:\A|,)noauto(?:,|\z)/
ABCresult
1XX1
01X1
0011
0000
209 8 ( my $mp = $f->{mp} ) =~ s{(?<=.)/+\z}{};
210 8 ▶ next if $m->{$mp};
Branch: 1 branch
BranchTrueFalseTotal
if $$m{$mp} 5 3 8
211 3 my $e = _do_mount( $dev, $f->{src}, $mp, $f->{type}, $f->{opts} );
212 3 ▶ next unless defined $e;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $e 1 2 3
213 2 ▶ $e = "mount: $mp: can't find $f->{src}." if $f->{src} =~ /\A(?:UUID|LABEL)=/i && $e =~ /special device/;
Branch: 1 branch
BranchTrueFalseTotal
if $$f{"src"} =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/ 2 0 2
Condition33%1/3
$$f{"src"} =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/
!ll&&!rl&&r
002
MC/DC0%0/2
$$f{"src"} =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/
$$f{"src"} =~ /\A(?:UUID|LABEL)=/i $e =~ /special device/
Truth table33%1/3
A and B
A= $$f{"src"} =~ /\A(?:UUID|LABEL)=/iB= $e =~ /special device/
ABresult
0X0
100
111
214 2 ▶ push @err, $e unless $f->{opts} =~ /(?:\A|,)nofail(?:,|\z)/;
Branch: 1 branch
BranchTrueFalseTotal
unless $$f{"opts"} =~ /(?:\A|,)nofail(?:,|\z)/ 2 0 2
215 }
216 3 ▶ return ( join( "\n", @hint, @err ), @err ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
@err ? : 2 1 3
217 }
218 2 ▶ if ( defined $opts && $opts =~ /(?:\A|,)remount(?:,|\z)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $opts and $opts =~ /(?:\A|,)remount(?:,|\z)/) 1 1 2
Condition66%2/3
defined $opts and $opts =~ /(?:\A|,)remount(?:,|\z)/
!ll&&!rl&&r
101
MC/DC50%1/2
defined $opts and $opts =~ /(?:\A|,)remount(?:,|\z)/
defined $opts $opts =~ /(?:\A|,)remount(?:,|\z)/
Truth table66%2/3
A and B
A= defined $optsB= $opts =~ /(?:\A|,)remount(?:,|\z)/
ABresult
0X0
100
111
219 1 my $t = $a[-1];
220 1 $t =~ s{(?<=.)/+\z}{};
221 1 ▶ my ($mp) = grep { $_ eq $t || canon( $dev, $m->{$_}{dev} ) eq ( canon( $dev, $t ) // '' ) } sort keys %$m;
Condition60%3/5
$_ eq $t || canon($dev, $$m{$_}{'dev'}) eq (canon($dev, $t) // '')
l!l&&r!l&&!r
103
canon($dev, $t) // ""
l!l
03
MC/DC50%1/2
$_ eq $t || canon($dev, $$m{$_}{'dev'}) eq (canon($dev, $t) // '')
$_ eq $t canon($dev, $$m{$_}{'dev'}) eq (canon($dev, $t) // '')
MC/DC0%0/1
canon($dev, $t) // ""
canon($dev, $t)
Truth table66%2/3
A || B
A= $_ eq $tB= canon($dev, $$m{$_}{'dev'}) eq (canon($dev, $t) // '')
ABresult
1X1
011
000
Truth table50%1/2
A
A= canon($dev, $t)
Aresult
11
00
222 1 ▶ return ( "mount: $t: mount point not mounted or bad option.", 0 ) unless defined $mp;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $mp 0 1 1
223 1 my ( $c, $e ) = _bd( $dev, $m->{$mp}{dev} );
224 # wie util-linux: Optionen aus fstab, dann die auf der Befehlszeile
225 1 my ($f) = grep { ( $_->{mp} =~ s{(?<=.)/+\z}{}r ) eq $mp } _fstab($dev);
226 1 ▶ my $new = _merge_opts( _merge_opts( $m->{$mp}{opts}, $f ? $f->{opts} : '' ), $opts );
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 1 0 1
227 1 ▶ $m->{$mp}{opts} = $new if $new ne ( $m->{$mp}{opts} // '' );
Branch: 1 branch
BranchTrueFalseTotal
if $new ne ($$m{$mp}{"opts"} // "") 1 0 1
Condition50%1/2
$$m{$mp}{"opts"} // ""
l!l
10
MC/DC0%0/1
$$m{$mp}{"opts"} // ""
$$m{$mp}{"opts"}
Truth table50%1/2
A
A= $$m{$mp}{"opts"}
Aresult
11
00
228 1 return ( '', 1 );
229 }
230 1 my ( $src, $mp );
231 1 ▶ if ( @a == 1 ) { # aus fstab
Branch: 1 branch
BranchTrueFalseTotal
if (@a == 1) { } 0 1 1
232 0 my $t = $a[0] =~ s{(?<=.)/+\z}{}r;
233 0 ▶ my ($f) = grep { ( $_->{mp} =~ s{(?<=.)/+\z}{}r ) eq $t || $_->{src} eq $t || ( canon( $dev, $_->{src} ) // '' ) eq ( canon( $dev, $t ) // '-' ) } _fstab($dev);
Condition0%0/10
$$_{'mp'} =~ s[(?<=.)/+\z][]r eq $t || $$_{'src'} eq $t || (canon($dev, $$_{'src'}) // '') eq (canon($dev, $t) // '-')
l!l&&r!l&&!r
000
$$_{"mp"} =~ s[(?<=.)/+\z][]r eq $t or $$_{"src"} eq $t
l!l&&r!l&&!r
000
canon($dev, $$_{"src"}) // ""
l!l
00
canon($dev, $t) // "-"
l!l
00
MC/DC0%0/3
$$_{'mp'} =~ s[(?<=.)/+\z][]r eq $t || $$_{'src'} eq $t || (canon($dev, $$_{'src'}) // '') eq (canon($dev, $t) // '-')
$$_{"mp"} =~ s[(?<=.)/+\z][]r eq $t $$_{"src"} eq $t canon($dev, $$_{"src"})
MC/DC0%0/1
canon($dev, $t) // "-"
canon($dev, $t)
Truth table0%0/4
A or B || C
A= $$_{"mp"} =~ s[(?<=.)/+\z][]r eq $tB= $$_{"src"} eq $tC= canon($dev, $$_{"src"})
ABCresult
1XX1
01X1
0011
0000
Truth table0%0/2
A
A= canon($dev, $t)
Aresult
11
00
234 0 ▶ return ( "mount: $t: can't find in /etc/fstab.", 0 ) unless $f;
Branch: 1 branch
BranchTrueFalseTotal
unless $f 0 0 0
235 0 ( $src, $mp, $type ) = ( $f->{src}, $f->{mp}, $f->{type} );
236 0 $opts = join ',', grep {defined} $f->{opts}, $opts;
237 }
238 1 else { ( $src, $mp ) = @a[ 0, 1 ] }
239 1 my $e = _do_mount( $dev, $src, $mp, $type, $opts );
240 1 ▶ $e = "mount: $mp: can't find $src." if defined $e && $src =~ /\A(?:UUID|LABEL)=/i && $e =~ /special device/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e and $src =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/ 0 1 1
Condition33%2/6
defined $e and $src =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/
!ll&&!rl&&r
100
defined $e and $src =~ /\A(?:UUID|LABEL)=/i
!ll&&!rl&&r
100
MC/DC0%0/3
defined $e and $src =~ /\A(?:UUID|LABEL)=/i and $e =~ /special device/
defined $e $src =~ /\A(?:UUID|LABEL)=/i $e =~ /special device/
Truth table25%1/4
A and B and C
A= defined $eB= $src =~ /\A(?:UUID|LABEL)=/iC= $e =~ /special device/
ABCresult
0XX0
10X0
1100
1111
241 1 ▶ return ( join( "\n", @hint, defined $e ? $e : () ), defined $e ? 0 : 1 );
Branch: 2 branches
BranchTrueFalseTotal
defined $e ? : 0 1 1
defined $e ? : 0 1 1
242 }
243  
244  
245 4 ▶sub umount {
Subroutine umount: called CC=11 SCAR=26.1
Pod documented
246 4 my ( $dev, $av ) = @_;
247 4 my @a = grep { !/\A-/ } @$av;
248 4 ▶ return ( 'umount: bad usage', 0 ) unless @a;
Branch: 1 branch
BranchTrueFalseTotal
unless @a 0 4 4
249 4 my @out;
250 4 for my $t (@a) {
251 4 ( my $x = $t ) =~ s{(?<=.)/+\z}{};
252 4 ▶ my $m = $dev->{mounts} || {};
Condition50%1/2
$$dev{'mounts'} || {}
l!l
40
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
253 4 ▶ my ($mp) = grep { $_ eq $x || ( canon( $dev, $m->{$_}{dev} ) // '' ) eq ( canon( $dev, $x ) // '-' ) } sort keys %$m;
Condition57%4/7
$_ eq $x || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $x) // '-')
l!l&&r!l&&!r
4012
canon($dev, $$m{$_}{"dev"}) // ""
l!l
120
canon($dev, $x) // "-"
l!l
012
MC/DC0%0/2
$_ eq $x || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $x) // '-')
$_ eq $x canon($dev, $$m{$_}{"dev"})
MC/DC0%0/1
canon($dev, $x) // "-"
canon($dev, $x)
Truth table66%2/3
A || B
A= $_ eq $xB= canon($dev, $$m{$_}{"dev"})
ABresult
1X1
011
000
Truth table50%1/2
A
A= canon($dev, $x)
Aresult
11
00
254 0 ▶ if ( !defined $mp ) { push @out, "umount: $t: not mounted."; next }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $mp) 0 4 4
255 4 ▶ return ( "umount: /: target is busy.", 0 ) if $mp eq '/';
Branch: 1 branch
BranchTrueFalseTotal
if $mp eq "/" 0 4 4
256 4 my $e = _do_umount( $dev, $mp );
257 4 ▶ return ( $e, 0 ) if defined $e;
Branch: 1 branch
BranchTrueFalseTotal
if defined $e 1 3 4
258 }
259 3 ▶ return ( join( "\n", @out ), @out ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
@out ? : 0 3 3
260 }
261  
262  
263 1 ▶sub findmnt {
Subroutine findmnt: called CC=36 SCAR=56.2
Pod documented
264 1 my ( $dev, $av ) = @_;
265 1 my @a = grep { !/\A-/ } @$av;
266 1 my %o = map { $_ => 1 } grep {/\A-/} @$av;
267 1 ▶ if ( $o{'--verify'} || $o{'-x'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"--verify"} or $o{"-x"}) 1 0 1
Condition33%1/3
$o{"--verify"} or $o{"-x"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$o{"--verify"} or $o{"-x"}
$o{"--verify"} $o{"-x"}
Truth table33%1/3
A or B
A= $o{"--verify"}B= $o{"-x"}
ABresult
1X1
011
000
268 1 my ( @l, $err, $warn );
269 1 my @f = _fstab($dev);
270 1 for my $f (@f) {
271 3 my @m;
272 3 ▶ if ( $f->{type} eq 'swap' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$f{'type'} eq 'swap') { } 0 3 3
273 0 ▶ push( @m, " [E] unreachable source: $f->{src}" ), $err++ unless canon( $dev, $f->{src} ) || _L( '_file_entry', $dev, $f->{src} );
Branch: 1 branch
BranchTrueFalseTotal
unless canon($dev, $$f{"src"}) or _L("_file_entry", $dev, $$f{"src"}) 0 0 0
Condition0%0/3
canon($dev, $$f{"src"}) or _L("_file_entry", $dev, $$f{"src"})
l!l&&r!l&&!r
000
MC/DC0%0/2
canon($dev, $$f{"src"}) or _L("_file_entry", $dev, $$f{"src"})
canon($dev, $$f{"src"}) _L("_file_entry", $dev, $$f{"src"})
Truth table0%0/3
A or B
A= canon($dev, $$f{"src"})B= _L("_file_entry", $dev, $$f{"src"})
ABresult
1X1
011
000
274 }
275 else {
276 3 my $c = canon( $dev, $f->{src} );
277 3 ▶ if ( !$c ) { push @m, " [E] unreachable source: $f->{src}: No such file or directory"; $err++ }
Branch: 2 branches
BranchTrueFalseTotal
if (not $c) { } 1 2 3
elsif ($$f{'type'} ne 'auto' and (_all($dev)->{$c}{'fstype'} // '') ne $$f{'type'}) { } 0 2 2
278 ▶ elsif ( $f->{type} ne 'auto' && ( _all($dev)->{$c}{fstype} // '' ) ne $f->{type} ) {
Condition40%2/5
$$f{"type"} ne "auto" and (_all($dev)->{$c}{"fstype"} // "") ne $$f{"type"}
!ll&&!rl&&r
020
_all($dev)->{$c}{"fstype"} // ""
l!l
20
MC/DC0%0/2
$$f{"type"} ne "auto" and (_all($dev)->{$c}{"fstype"} // "") ne $$f{"type"}
$$f{"type"} ne "auto" _all($dev)->{$c}{"fstype"}
Truth table33%1/3
A and B
A= $$f{"type"} ne "auto"B= _all($dev)->{$c}{"fstype"}
ABresult
0X0
100
111
279 0 ▶ push @m, " [E] $f->{type} does not match with on-disk " . ( _all($dev)->{$c}{fstype} // 'unknown' ); $err++;
Condition0%0/2
_all($dev)->{$c}{"fstype"} // "unknown"
l!l
00
MC/DC0%0/1
_all($dev)->{$c}{"fstype"} // "unknown"
_all($dev)->{$c}{"fstype"}
Truth table0%0/2
A
A= _all($dev)->{$c}{"fstype"}
Aresult
11
00
280 }
281 3 ▶ if ( $f->{mp} =~ m{\A/} && !_L( '_is_dir', $dev, $f->{mp} ) ) { push @m, " [E] target does not exist"; $err++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($$f{"mp"} =~ m[\A/] and not _L("_is_dir", $dev, $$f{"mp"})) 1 2 3
Condition66%2/3
$$f{"mp"} =~ m[\A/] and not _L("_is_dir", $dev, $$f{"mp"})
!ll&&!rl&&r
021
MC/DC50%1/2
$$f{"mp"} =~ m[\A/] and not _L("_is_dir", $dev, $$f{"mp"})
$$f{"mp"} =~ m[\A/] not _L("_is_dir", $dev, $$f{"mp"})
Truth table66%2/3
A and not(B)
A= $$f{"mp"} =~ m[\A/]B= not _L("_is_dir", $dev, $$f{"mp"})
ABresult
0X0
100
111
282 0 ▶ if ( $f->{src} =~ m{\A/dev/(?:sd|vd|nvme|hd)} ) { push @m, " [W] recommended to use UUID= instead of $f->{src}"; $warn++ }
Branch: 1 branch
BranchTrueFalseTotal
if ($$f{"src"} =~ m[\A/dev/(?:sd|vd|nvme|hd)]) 0 3 3
283 }
284 3 ▶ push @l, $f->{mp}, @m if @m || $o{'--verbose'} || $o{'-v'};
Branch: 1 branch
BranchTrueFalseTotal
if @m or $o{"--verbose"} or $o{"-v"} 1 2 3
Condition66%4/6
@m or $o{"--verbose"} or $o{"-v"}
l!l&&r!l&&!r
102
@m or $o{"--verbose"}
l!l&&r!l&&!r
102
MC/DC33%1/3
@m or $o{"--verbose"} or $o{"-v"}
@m $o{"--verbose"} $o{"-v"}
Truth table50%2/4
A or B or C
A= @mB= $o{"--verbose"}C= $o{"-v"}
ABCresult
1XX1
01X1
0011
0000
285 }
286 1 ▶ push @l, '', sprintf( '0 parse errors, %d error%s, %d warning%s', $err // 0, ( $err // 0 ) == 1 ? '' : 's', $warn // 0, ( $warn // 0 ) == 1 ? '' : 's' );
Branch: 2 branches
BranchTrueFalseTotal
($err // 0) == 1 ? : 0 1 1
($warn // 0) == 1 ? : 0 1 1
Condition50%4/8
$err // 0
l!l
10
$err // 0
l!l
10
$warn // 0
l!l
01
$warn // 0
l!l
01
MC/DC0%0/1
$err // 0
$err
MC/DC0%0/1
$err // 0
$err
MC/DC0%0/1
$warn // 0
$warn
MC/DC0%0/1
$warn // 0
$warn
Truth table50%1/2
A
A= $err
Aresult
11
00
Truth table50%1/2
A
A= $err
Aresult
11
00
Truth table50%1/2
A
A= $warn
Aresult
11
00
Truth table50%1/2
A
A= $warn
Aresult
11
00
287 1 ▶ return ( join( "\n", grep {defined} @l ), $err ? 0 : 1 );
Branch: 1 branch
BranchTrueFalseTotal
$err ? : 1 0 1
288 }
289 0 ▶ if ( $o{'-s'} || $o{'--fstab'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($o{"-s"} or $o{"--fstab"}) 0 0 0
Condition0%0/3
$o{"-s"} or $o{"--fstab"}
l!l&&r!l&&!r
000
MC/DC0%0/2
$o{"-s"} or $o{"--fstab"}
$o{"-s"} $o{"--fstab"}
Truth table0%0/3
A or B
A= $o{"-s"}B= $o{"--fstab"}
ABresult
1X1
011
000
290 0 my @l = sprintf( '%-20s %-40s %-6s %s', qw( TARGET SOURCE FSTYPE OPTIONS ) );
291 0 push @l, sprintf( '%-20s %-40s %-6s %s', $_->{mp}, $_->{src}, $_->{type}, $_->{opts} ) for _fstab($dev);
292 0 return ( join( "\n", @l ), 1 );
293 }
294 0 ▶ my $m = $dev->{mounts} || {};
Condition0%0/2
$$dev{'mounts'} || {}
l!l
00
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table0%0/2
A
A= $$dev{'mounts'}
Aresult
11
00
295 0 my @mps = sort keys %$m;
296 0 ▶ if (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 0 0 0
297 0 my $t = $a[0] =~ s{(?<=.)/+\z}{}r;
298 0 ▶ @mps = grep { $_ eq $t || ( canon( $dev, $m->{$_}{dev} ) // '' ) eq ( canon( $dev, $t ) // '-' ) } @mps;
Condition0%0/7
$_ eq $t || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $t) // '-')
l!l&&r!l&&!r
000
canon($dev, $$m{$_}{"dev"}) // ""
l!l
00
canon($dev, $t) // "-"
l!l
00
MC/DC0%0/2
$_ eq $t || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $t) // '-')
$_ eq $t canon($dev, $$m{$_}{"dev"})
MC/DC0%0/1
canon($dev, $t) // "-"
canon($dev, $t)
Truth table0%0/3
A || B
A= $_ eq $tB= canon($dev, $$m{$_}{"dev"})
ABresult
1X1
011
000
Truth table0%0/2
A
A= canon($dev, $t)
Aresult
11
00
299 0 ▶ return ( '', 0 ) unless @mps;
Branch: 1 branch
BranchTrueFalseTotal
unless @mps 0 0 0
300 }
301 return ( join( "\n", sprintf( '%-20s %-28s %-6s %s', qw( TARGET SOURCE FSTYPE OPTIONS ) ),
302 0 ▶ map { sprintf '%-20s %-28s %-6s %s', $_, $m->{$_}{dev}, $m->{$_}{fstype} // 'ext4', $m->{$_}{opts} // 'rw,relatime' } @mps ), 1 );
Condition0%0/4
$$m{$_}{"fstype"} // "ext4"
l!l
00
$$m{$_}{"opts"} // "rw,relatime"
l!l
00
MC/DC0%0/1
$$m{$_}{"fstype"} // "ext4"
$$m{$_}{"fstype"}
MC/DC0%0/1
$$m{$_}{"opts"} // "rw,relatime"
$$m{$_}{"opts"}
Truth table0%0/2
A
A= $$m{$_}{"fstype"}
Aresult
11
00
Truth table0%0/2
A
A= $$m{$_}{"opts"}
Aresult
11
00
303 }
304  
305 # --- lsblk, blkid ------------------------------------------------------------------
306  
307  
308 2 ▶sub lsblk {
Subroutine lsblk: called CC=32 SCAR=36.4
Pod documented
309 2 my ( $dev, $av ) = @_;
310 2 my ( $o, $err ) = _L( '_lsblk_opts', $av );
311 2 ▶ return ( $err, 0 ) if defined $err;
Branch: 1 branch
BranchTrueFalseTotal
if defined $err 0 2 2
312 0 ▶ if ( !$o ) { push @Langertha::Holmgang::Sim::Linux::GAPS, join( ' ', 'lsblk', @$av ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless ($o) 0 2 2
313 2 my $f = $o->{f};
314 2 my $s = _st($dev);
315 2 my $all = _all($dev);
316 2 my %kids;
317 2 ▶ my $d = $s->{disks} || {};
Condition50%1/2
$$s{'disks'} || {}
l!l
20
MC/DC0%0/1
$$s{'disks'} || {}
$$s{'disks'}
Truth table50%1/2
A
A= $$s{'disks'}
Aresult
11
00
318 2 ▶ for my $p ( keys %$d ) { push @{ $kids{ $d->{$p}{parent} } }, $p if $d->{$p}{parent} }
Branch: 1 branch
BranchTrueFalseTotal
if $$d{$p}{"parent"} 8 14 22
319 2 ▶ for my $vg ( keys %{ $s->{vgs} || {} } ) {
Condition50%1/2
$$s{'vgs'} || {}
l!l
20
MC/DC0%0/1
$$s{'vgs'} || {}
$$s{'vgs'}
Truth table50%1/2
A
A= $$s{'vgs'}
Aresult
11
00
320 2 ▶ for my $pvx ( @{ $s->{vgs}{$vg}{pvs} || [] } ) { push @{ $kids{$pvx} }, map {"/dev/mapper/$vg-$_"} sort keys %{ $s->{vgs}{$vg}{lvs} || {} } }
Condition50%2/4
$$s{'vgs'}{$vg}{'pvs'} || []
l!l
20
$$s{'vgs'}{$vg}{'lvs'} || {}
l!l
20
MC/DC0%0/1
$$s{'vgs'}{$vg}{'pvs'} || []
$$s{'vgs'}{$vg}{'pvs'}
MC/DC0%0/1
$$s{'vgs'}{$vg}{'lvs'} || {}
$$s{'vgs'}{$vg}{'lvs'}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'pvs'}
Aresult
11
00
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'lvs'}
Aresult
11
00
321 }
322 2 ▶ for my $md ( keys %{ $s->{md} || {} } ) {
Condition50%1/2
$$s{'md'} || {}
l!l
20
MC/DC0%0/1
$$s{'md'} || {}
$$s{'md'}
Truth table50%1/2
A
A= $$s{'md'}
Aresult
11
00
323 2 ▶ for my $mem ( keys %{ $s->{md}{$md}{members} || {} } ) { push @{ $kids{$mem} }, $md if ( $s->{md}{$md}{members}{$mem} // '' ) ne 'removed' }
Branch: 1 branch
BranchTrueFalseTotal
if ($$s{"md"}{$md}{"members"}{$mem} // "") ne "removed" 4 0 4
Condition50%2/4
$$s{'md'}{$md}{'members'} || {}
l!l
20
$$s{"md"}{$md}{"members"}{$mem} // ""
l!l
40
MC/DC0%0/1
$$s{'md'}{$md}{'members'} || {}
$$s{'md'}{$md}{'members'}
MC/DC0%0/1
$$s{"md"}{$md}{"members"}{$mem} // ""
$$s{"md"}{$md}{"members"}{$mem}
Truth table50%1/2
A
A= $$s{'md'}{$md}{'members'}
Aresult
11
00
Truth table50%1/2
A
A= $$s{"md"}{$md}{"members"}{$mem}
Aresult
11
00
324 }
325 0 ▶ my %swap = map { $_->{name} => 1 } @{ $s->{swaps} || [] };
Condition50%1/2
$$s{'swaps'} || []
l!l
02
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table50%1/2
A
A= $$s{'swaps'}
Aresult
11
00
326 2 my %row = map { $_->{mount} => $_ } _L( '_df_rows', $dev );
327 2 my @rows;
328 my $line;
329 16 ▶ $line = sub {
Subroutine __ANON__: called CC=16 SCAR=28.1
330 16 my ( $p, $pre, $last, $depth ) = @_;
331 16 ▶ my $e = $all->{$p} || {};
Condition50%1/2
$$all{$p} || {}
l!l
160
MC/DC0%0/1
$$all{$p} || {}
$$all{$p}
Truth table50%1/2
A
A= $$all{$p}
Aresult
11
00
332 16 ( my $name = $p ) =~ s{\A/dev/(?:mapper/)?}{};
333 16 ▶ my @mp = ( _mounted_at( $dev, $p ), $swap{$p} ? '[SWAP]' : () );
Branch: 1 branch
BranchTrueFalseTotal
$swap{$p} ? : 0 16 16
334 16 ▶ my $r = @mp && $row{ $mp[0] };
Condition66%2/3
@mp && $row{$mp[0]}
!ll&&!rl&&r
1105
MC/DC50%1/2
@mp && $row{$mp[0]}
@mp $row{$mp[0]}
Truth table66%2/3
A && B
A= @mpB= $row{$mp[0]}
ABresult
0X0
100
111
335 push @rows, { name => $name, path => $p, tree => $depth ? $pre . ( $last ? '└─' : '├─' ) : '', majmin => '254:0', size => _b( $e->{size} ),
336 type => $p =~ m{/mapper/} ? 'lvm' : $p =~ m{/md\d} ? ( $e->{level} // 'raid1' ) : $e->{parent} ? 'part' : 'disk', mps => \@mp,
337 16 ▶ fstype => $e->{fstype}, label => $e->{label}, uuid => $e->{uuid}, fsavail => $r ? $r->{avail} : undef, fsuse => $r ? $r->{pct} : undef };
Branch: 7 branches
BranchTrueFalseTotal
$depth ? : 8 8 16
$last ? : 6 2 8
$p =~ m[/mapper/] ? : 2 14 16
$p =~ m[/md\d] ? : 2 12 14
$$e{'parent'} ? : 4 8 12
$r ? : 5 11 16
$r ? : 5 11 16
Condition50%1/2
$$e{"level"} // "raid1"
l!l
20
MC/DC0%0/1
$$e{"level"} // "raid1"
$$e{"level"}
Truth table50%1/2
A
A= $$e{"level"}
Aresult
11
00
338 16 ▶ my @k = sort @{ $kids{$p} || [] };
Condition100%2/2
$kids{$p} || []
l!l
610
MC/DC100%1/1
$kids{$p} || []
$kids{$p}
Truth table100%2/2
A
A= $kids{$p}
Aresult
11
00
339 16 ▶ for my $i ( 0 .. $#k ) { $line->( $k[$i], $depth ? $pre . ( $last ? ' ' : '│ ' ) : '', $i == $#k, $depth + 1 ) }
Branch: 2 branches
BranchTrueFalseTotal
$depth ? : 4 4 8
$last ? : 4 0 4
340 2 };
341 2 my @top = grep { !$d->{$_}{parent} } sort keys %$d;
342 2 my ($want) = @{ $o->{dev} };
343 2 ▶ @top = grep { $_ eq ( canon( $dev, $want ) // '' ) } keys %$all if defined $want;
Branch: 1 branch
BranchTrueFalseTotal
if defined $want 1 1 2
Condition50%1/2
canon($dev, $want) // ""
l!l
140
MC/DC0%0/1
canon($dev, $want) // ""
canon($dev, $want)
Truth table50%1/2
A
A= canon($dev, $want)
Aresult
11
00
344 2 ▶ return ( "lsblk: $want: not a block device", 0 ) if defined $want && !@top;
Branch: 1 branch
BranchTrueFalseTotal
if defined $want and not @top 0 2 2
Condition66%2/3
defined $want and not @top
!ll&&!rl&&r
110
MC/DC0%0/2
defined $want and not @top
defined $want not @top
Truth table66%2/3
A and not(B)
A= defined $wantB= not @top
ABresult
0X0
100
111
345 2 $line->( $_, '', 1, 0 ) for @top;
346 2 ▶ return ( _L( '_lsblk_table', \@rows, $o ), 1 ) if $o->{table};
Branch: 1 branch
BranchTrueFalseTotal
if $$o{"table"} 1 1 2
347 1 ▶ my @l = $f ? sprintf( '%-20s %-11s %-6s %-37s %6s %4s %s', 'NAME', 'FSTYPE', 'LABEL', 'UUID', 'FSAVAIL', 'FSUSE%', 'MOUNTPOINTS' )
Branch: 1 branch
BranchTrueFalseTotal
$f ? : 1 0 1
348 : sprintf( '%-20s %7s %2s %6s %2s %-5s %s', 'NAME', 'MAJ:MIN', 'RM', 'SIZE', 'RO', 'TYPE', 'MOUNTPOINTS' );
349 1 for my $r (@rows) {
350 push @l, $f
351 ? sprintf( '%-20s %-11s %-6s %-37s %6s %4s %s', $r->{tree} . $r->{name}, $r->{fstype} // '', $r->{label} // '', $r->{uuid} // '',
352 15 defined $r->{fsavail} ? _h( $r->{fsavail} ) : '', defined $r->{fsuse} ? "$r->{fsuse}%" : '', join( ' ', @{ $r->{mps} } ) )
353 0 ▶ : sprintf( '%-20s %7s %2d %6s %2d %-5s %s', $r->{tree} . $r->{name}, $r->{majmin}, 0, _h( $r->{size} ), 0, $r->{type}, join( ' ', @{ $r->{mps} } ) );
Branch: 3 branches
BranchTrueFalseTotal
$f ? : 15 0 15
defined $$r{'fsavail'} ? : 4 11 15
defined $$r{'fsuse'} ? : 4 11 15
Condition100%6/6
$$r{"fstype"} // ""
l!l
87
$$r{"label"} // ""
l!l
114
$$r{"uuid"} // ""
l!l
510
MC/DC100%1/1
$$r{"fstype"} // ""
$$r{"fstype"}
MC/DC100%1/1
$$r{"label"} // ""
$$r{"label"}
MC/DC100%1/1
$$r{"uuid"} // ""
$$r{"uuid"}
Truth table100%2/2
A
A= $$r{"fstype"}
Aresult
11
00
Truth table100%2/2
A
A= $$r{"label"}
Aresult
11
00
Truth table100%2/2
A
A= $$r{"uuid"}
Aresult
11
00
354 }
355 1 return ( join( "\n", @l ), 1 );
356 }
357  
358  
359 1 ▶sub blkid {
Subroutine blkid: called CC=10 SCAR=25.9
Pod documented
360 1 my ( $dev, $av ) = @_;
361 1 my $all = _all($dev);
362 1 my @want = grep { !/\A-/ } @$av;
363 0 ▶ my @p = @want ? map { canon( $dev, $_ ) // () } @want : grep { $all->{$_}{fstype} } sort keys %$all;
Branch: 1 branch
BranchTrueFalseTotal
@want ? : 1 0 1
Condition33%1/3
canon($dev, $_) // ()
l!l&&r!l&&!r
100
MC/DC0%0/2
canon($dev, $_) // ()
canon($dev, $_) ()
Truth table33%1/3
A // B
A= canon($dev, $_)B= ()
ABresult
1X1
011
000
364 1 ▶ return ( '', 0 ) unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 1 1
365 1 my @l;
366 1 for my $p (@p) {
367 1 my $e = $all->{$p};
368 1 ▶ next unless $e->{fstype};
Branch: 1 branch
BranchTrueFalseTotal
unless $$e{"fstype"} 0 1 1
369 push @l, "$p: " . join( ' ', ( defined $e->{label} ? qq{LABEL="$e->{label}"} : () ), ( defined $e->{uuid} ? qq{UUID="$e->{uuid}"} : () ),
370 1 ▶ ( $e->{fstype} =~ /ext|xfs/ ? 'BLOCK_SIZE="4096"' : () ), qq{TYPE="$e->{fstype}"} );
Branch: 3 branches
BranchTrueFalseTotal
defined $$e{'label'} ? : 1 0 1
defined $$e{'uuid'} ? : 1 0 1
$$e{'fstype'} =~ /ext|xfs/ ? : 1 0 1
371 }
372 1 ▶ return ( join( "\n", @l ), @l ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
@l ? : 1 0 1
373 }
374  
375 # --- LVM ---------------------------------------------------------------------------
376  
377  
378 7 ▶sub lvm {
Subroutine lvm: called CC=92 SCAR=70.3
Pod documented
379 7 my ( $dev, $av, $ctx, $prog ) = @_;
380 7 my $s = _st($dev);
381 7 my @a = @$av;
382 7 ▶ if ( $prog eq 'pvs' || $prog eq 'pvdisplay' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "pvs" or $prog eq "pvdisplay") 0 7 7
Condition33%1/3
$prog eq "pvs" or $prog eq "pvdisplay"
l!l&&r!l&&!r
007
MC/DC0%0/2
$prog eq "pvs" or $prog eq "pvdisplay"
$prog eq "pvs" $prog eq "pvdisplay"
Truth table33%1/3
A or B
A= $prog eq "pvs"B= $prog eq "pvdisplay"
ABresult
1X1
011
000
383 0 my @l = sprintf( ' %-10s %-5s %-4s %-5s %8s %8s', qw( PV VG Fmt Attr PSize PFree ) );
384 0 ▶ for my $p ( sort grep { ( $s->{disks}{$_}{fstype} // '' ) eq 'LVM2_member' } keys %{ $s->{disks} || {} } ) {
Condition0%0/4
$$s{"disks"}{$_}{"fstype"} // ""
l!l
00
$$s{'disks'} || {}
l!l
00
MC/DC0%0/1
$$s{"disks"}{$_}{"fstype"} // ""
$$s{"disks"}{$_}{"fstype"}
MC/DC0%0/1
$$s{'disks'} || {}
$$s{'disks'}
Truth table0%0/2
A
A= $$s{"disks"}{$_}{"fstype"}
Aresult
11
00
Truth table0%0/2
A
A= $$s{'disks'}
Aresult
11
00
385 0 ▶ my $vg = _vg_of_pv( $dev, $p ) // '';
Condition0%0/2
_vg_of_pv($dev, $p) // ""
l!l
00
MC/DC0%0/1
_vg_of_pv($dev, $p) // ""
_vg_of_pv($dev, $p)
Truth table0%0/2
A
A= _vg_of_pv($dev, $p)
Aresult
11
00
386 0 ▶ my $free = $vg ? ( _vg_size( $dev, $vg ) )[1] : _b( $s->{disks}{$p}{size} );
Branch: 1 branch
BranchTrueFalseTotal
$vg ? : 0 0 0
387 0 ▶ $free = _b( $s->{disks}{$p}{size} ) if $free > _b( $s->{disks}{$p}{size} );
Branch: 1 branch
BranchTrueFalseTotal
if $free > _b($$s{"disks"}{$p}{"size"}) 0 0 0
388 0 ▶ push @l, sprintf( ' %-10s %-5s %-4s %-5s %8s %8s', $p, $vg, 'lvm2', $vg ? 'a--' : '---', _g( _b( $s->{disks}{$p}{size} ) ), _g($free) );
Branch: 1 branch
BranchTrueFalseTotal
$vg ? : 0 0 0
389 }
390 0 return ( join( "\n", @l ), 1 );
391 }
392 7 ▶ if ( $prog eq 'vgs' || $prog eq 'vgdisplay' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "vgs" or $prog eq "vgdisplay") 1 6 7
Condition66%2/3
$prog eq "vgs" or $prog eq "vgdisplay"
l!l&&r!l&&!r
106
MC/DC50%1/2
$prog eq "vgs" or $prog eq "vgdisplay"
$prog eq "vgs" $prog eq "vgdisplay"
Truth table66%2/3
A or B
A= $prog eq "vgs"B= $prog eq "vgdisplay"
ABresult
1X1
011
000
393 1 my @l = sprintf( ' %-5s %3s %3s %3s %-6s %8s %8s', 'VG', '#PV', '#LV', '#SN', 'Attr', 'VSize', 'VFree' );
394 1 ▶ for my $vg ( sort keys %{ $s->{vgs} || {} } ) {
Condition50%1/2
$$s{'vgs'} || {}
l!l
10
MC/DC0%0/1
$$s{'vgs'} || {}
$$s{'vgs'}
Truth table50%1/2
A
A= $$s{'vgs'}
Aresult
11
00
395 1 my ( $size, $free ) = _vg_size( $dev, $vg );
396 1 ▶ my $lvs = $s->{vgs}{$vg}{lvs} || {};
Condition50%1/2
$$s{'vgs'}{$vg}{'lvs'} || {}
l!l
10
MC/DC0%0/1
$$s{'vgs'}{$vg}{'lvs'} || {}
$$s{'vgs'}{$vg}{'lvs'}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'lvs'}
Aresult
11
00
397 1 ▶ push @l, sprintf( ' %-5s %3d %3d %3d %-6s %8s %8s', $vg, scalar @{ $s->{vgs}{$vg}{pvs} || [] }, scalar( grep { !$lvs->{$_}{origin} } keys %$lvs ),
Condition50%1/2
$$s{'vgs'}{$vg}{'pvs'} || []
l!l
10
MC/DC0%0/1
$$s{'vgs'}{$vg}{'pvs'} || []
$$s{'vgs'}{$vg}{'pvs'}
Truth table50%1/2
A
A= $$s{'vgs'}{$vg}{'pvs'}
Aresult
11
00
398 1 scalar( grep { $lvs->{$_}{origin} } keys %$lvs ), 'wz--n-', _g($size), _g($free) );
399 }
400 1 return ( join( "\n", @l ), 1 );
401 }
402 6 ▶ if ( $prog eq 'lvs' || $prog eq 'lvdisplay' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "lvs" or $prog eq "lvdisplay") 0 6 6
Condition33%1/3
$prog eq "lvs" or $prog eq "lvdisplay"
l!l&&r!l&&!r
006
MC/DC0%0/2
$prog eq "lvs" or $prog eq "lvdisplay"
$prog eq "lvs" $prog eq "lvdisplay"
Truth table33%1/3
A or B
A= $prog eq "lvs"B= $prog eq "lvdisplay"
ABresult
1X1
011
000
403 0 my @l = sprintf( ' %-16s %-5s %-10s %8s %-8s', qw( LV VG Attr LSize Origin ) );
404 0 ▶ for my $vg ( sort keys %{ $s->{vgs} || {} } ) {
Condition0%0/2
$$s{'vgs'} || {}
l!l
00
MC/DC0%0/1
$$s{'vgs'} || {}
$$s{'vgs'}
Truth table0%0/2
A
A= $$s{'vgs'}
Aresult
11
00
405 0 ▶ my $lvs = $s->{vgs}{$vg}{lvs} || {};
Condition0%0/2
$$s{'vgs'}{$vg}{'lvs'} || {}
l!l
00
MC/DC0%0/1
$$s{'vgs'}{$vg}{'lvs'} || {}
$$s{'vgs'}{$vg}{'lvs'}
Truth table0%0/2
A
A= $$s{'vgs'}{$vg}{'lvs'}
Aresult
11
00
406 push @l, sprintf( ' %-16s %-5s %-10s %8s %-8s', $_, $vg, $lvs->{$_}{origin} ? 'swi-a-s---' : '-wi-ao----', _g( _b( $lvs->{$_}{size} ) ), $lvs->{$_}{origin} // '' )
407 0 ▶ for sort keys %$lvs;
Branch: 1 branch
BranchTrueFalseTotal
$$lvs{$_}{'origin'} ? : 0 0 0
Condition0%0/2
$$lvs{$_}{"origin"} // ""
l!l
00
MC/DC0%0/1
$$lvs{$_}{"origin"} // ""
$$lvs{$_}{"origin"}
Truth table0%0/2
A
A= $$lvs{$_}{"origin"}
Aresult
11
00
408 }
409 0 return ( join( "\n", @l ), 1 );
410 }
411 6 my @args = grep { !/\A-/ } @a;
412 6 ▶ if ( $prog eq 'pvcreate' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "pvcreate") 2 4 6
413 2 my @o;
414 2 for my $p (@args) {
415 2 my $c = canon( $dev, $p );
416 2 ▶ my $e = $c && $s->{disks}{$c};
Condition33%1/3
$c && $$s{'disks'}{$c}
!ll&&!rl&&r
002
MC/DC0%0/2
$c && $$s{'disks'}{$c}
$c $$s{'disks'}{$c}
Truth table33%1/3
A && B
A= $cB= $$s{'disks'}{$c}
ABresult
0X0
100
111
417 2 ▶ return ( " No device found for $p.", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 2 2
418 0 ▶ return ( " Can't open $p exclusively. Mounted filesystem?", 0 ) if _mounted_at( $dev, $c ) || grep { _mounted_at( $dev, $_ ) } _parts( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c) 1 1 2
Condition66%2/3
_mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c)
l!l&&r!l&&!r
101
MC/DC50%1/2
_mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c)
_mounted_at($dev, $c) grep {_mounted_at($dev, $_);} _parts($dev, $c)
Truth table66%2/3
A or B
A= _mounted_at($dev, $c)B= grep {_mounted_at($dev, $_);} _parts($dev, $c)
ABresult
1X1
011
000
419 1 ▶ return ( " Cannot use $p: device is partitioned", 0 ) if _parts( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _parts($dev, $c) 0 1 1
420 0 ▶ if ( defined $e->{fstype} && $e->{fstype} ne 'LVM2_member' && !grep { /\A-(?:f|ff|y|\w*f)\z/ } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $$e{"fstype"} and $$e{"fstype"} ne "LVM2_member" and not grep({/\A-(?:f|ff|y|\w*f)\z/;} @a)) 0 1 1
Condition33%2/6
defined $$e{"fstype"} and $$e{"fstype"} ne "LVM2_member" and not grep({/\A-(?:f|ff|y|\w*f)\z/;} @a)
!ll&&!rl&&r
100
defined $$e{"fstype"} and $$e{"fstype"} ne "LVM2_member"
!ll&&!rl&&r
100
MC/DC0%0/3
defined $$e{"fstype"} and $$e{"fstype"} ne "LVM2_member" and not grep({/\A-(?:f|ff|y|\w*f)\z/;} @a)
defined $$e{"fstype"} $$e{"fstype"} ne "LVM2_member" not grep({/\A-(?:f|ff|y|\w*f)\z/;} @a)
Truth table25%1/4
A and B and not(C)
A= defined $$e{"fstype"}B= $$e{"fstype"} ne "LVM2_member"C= not grep({/\A-(?:f|ff|y|\w*f)\z/;} @a)
ABCresult
0XX0
10X0
1100
1111
421 0 return ( "WARNING: $e->{fstype} signature detected on $p at offset 1080. Wipe it? [y/n]: [n]\n Aborted wiping of $e->{fstype}.\n 1 existing signature left on the device.", 0 );
422 }
423 1 ▶ return ( " Can't initialize physical volume \"$p\" of volume group \"" . _vg_of_pv( $dev, $c ) . "\" without -ff", 0 ) if _vg_of_pv( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _vg_of_pv($dev, $c) 0 1 1
424 1 $e->{fstype} = 'LVM2_member';
425 1 delete @{$e}{qw( uuid label offline fssize )};
426 1 $e->{uuid} = _uuid( $dev, $c, 'pv' );
427 1 push @o, " Physical volume \"$p\" successfully created.";
428 }
429 1 return ( join( "\n", @o ), 1 );
430 }
431 4 ▶ if ( $prog eq 'vgextend' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "vgextend") 1 3 4
432 1 my ( $vg, @pvs ) = @args;
433 1 ▶ return ( " Volume group \"" . ( $vg // '' ) . "\" not found", 0 ) unless defined $vg && $s->{vgs}{$vg};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $vg and $$s{"vgs"}{$vg} 0 1 1
Condition20%1/5
defined $vg and $$s{"vgs"}{$vg}
!ll&&!rl&&r
001
$vg // ""
l!l
00
MC/DC0%0/2
defined $vg and $$s{"vgs"}{$vg}
defined $vg $$s{"vgs"}{$vg}
MC/DC0%0/1
$vg // ""
$vg
Truth table33%1/3
A and B
A= defined $vgB= $$s{"vgs"}{$vg}
ABresult
0X0
100
111
Truth table0%0/2
A
A= $vg
Aresult
11
00
434 1 my @o;
435 1 for my $p (@pvs) {
436 1 my $c = canon( $dev, $p );
437 1 ▶ my $e = $c && $s->{disks}{$c};
Condition33%1/3
$c && $$s{'disks'}{$c}
!ll&&!rl&&r
001
MC/DC0%0/2
$c && $$s{'disks'}{$c}
$c $$s{'disks'}{$c}
Truth table33%1/3
A && B
A= $cB= $$s{'disks'}{$c}
ABresult
0X0
100
111
438 1 ▶ return ( " No device found for $p.", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 1 1
439 1 ▶ if ( ( $e->{fstype} // '' ) ne 'LVM2_member' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (($$e{"fstype"} // "") ne "LVM2_member") 1 0 1
Condition50%1/2
$$e{"fstype"} // ""
l!l
01
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
Truth table50%1/2
A
A= $$e{"fstype"}
Aresult
11
00
440 1 my ( $o, $ok ) = lvm( $dev, [ $p, grep {/\A-/} @a ], $ctx, 'pvcreate' );
441 1 ▶ return ( $o, 0 ) unless $ok;
Branch: 1 branch
BranchTrueFalseTotal
unless $ok 0 1 1
442 1 push @o, $o;
443 }
444 1 my $other = _vg_of_pv( $dev, $c );
445 1 ▶ return ( " Physical volume '$p' is already in volume group '$other'", 0 ) if $other;
Branch: 1 branch
BranchTrueFalseTotal
if $other 0 1 1
446 1 push @{ $s->{vgs}{$vg}{pvs} }, $c;
447 }
448 1 push @o, " Volume group \"$vg\" successfully extended";
449 1 return ( join( "\n", @o ), 1 );
450 }
451 3 ▶ if ( $prog =~ /\Alv(?:extend|resize|create)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog =~ /\Alv(?:extend|resize|create)\z/) 3 0 3
452 3 my ( $size, $ext, $name, $snap, $resize );
453 3 my @w = @a;
454 3 my @pos;
455 3 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 7 3 10
456 7 my $x = shift @w;
457 7 ▶ if ( $x =~ /\A(?:-L|--size)(?:=?(.+))?\z/ ) { $size = $1 // shift @w }
Branch: 6 branches
BranchTrueFalseTotal
if ($x =~ /\A(?:-L|--size)(?:=?(.+))?\z/) { } 2 5 7
elsif ($x =~ /\A(?:-l|--extents)(?:=?(.+))?\z/) { } 1 4 5
elsif ($x =~ /\A(?:-n|--name)(?:=?(.+))?\z/) { } 0 4 4
elsif ($x eq '-s' or $x eq '--snapshot') { } 0 4 4
elsif ($x eq '-r' or $x eq '--resizefs') { } 1 3 4
elsif ($x =~ /\A-/) { } 0 3 3
Condition33%1/3
$1 // shift @w
l!l&&r!l&&!r
020
MC/DC0%0/2
$1 // shift @w
$1 shift @w
Truth table33%1/3
A // B
A= $1B= shift @w
ABresult
1X1
011
000
458 1 ▶ elsif ( $x =~ /\A(?:-l|--extents)(?:=?(.+))?\z/ ) { $ext = $1 // shift @w }
Condition33%1/3
$1 // shift @w
l!l&&r!l&&!r
010
MC/DC0%0/2
$1 // shift @w
$1 shift @w
Truth table33%1/3
A // B
A= $1B= shift @w
ABresult
1X1
011
000
459 0 ▶ elsif ( $x =~ /\A(?:-n|--name)(?:=?(.+))?\z/ ) { $name = $1 // shift @w }
Condition0%0/3
$1 // shift @w
l!l&&r!l&&!r
000
MC/DC0%0/2
$1 // shift @w
$1 shift @w
Truth table0%0/3
A // B
A= $1B= shift @w
ABresult
1X1
011
000
460 0 ▶ elsif ( $x eq '-s' || $x eq '--snapshot' ) { $snap = 1 }
Condition33%1/3
$x eq "-s" or $x eq "--snapshot"
l!l&&r!l&&!r
004
MC/DC0%0/2
$x eq "-s" or $x eq "--snapshot"
$x eq "-s" $x eq "--snapshot"
Truth table33%1/3
A or B
A= $x eq "-s"B= $x eq "--snapshot"
ABresult
1X1
011
000
461 1 ▶ elsif ( $x eq '-r' || $x eq '--resizefs' ) { $resize = 1 }
Condition66%2/3
$x eq "-r" or $x eq "--resizefs"
l!l&&r!l&&!r
103
MC/DC50%1/2
$x eq "-r" or $x eq "--resizefs"
$x eq "-r" $x eq "--resizefs"
Truth table66%2/3
A or B
A= $x eq "-r"B= $x eq "--resizefs"
ABresult
1X1
011
000
462 elsif ( $x =~ /\A-/ ) { }
463 3 else { push @pos, $x }
464 }
465 3 ▶ if ( $prog eq 'lvcreate' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "lvcreate") 0 3 3
466 0 ▶ my $target = shift @pos // return ( ' Please specify a volume group or logical volume', 0 );
Condition0%0/2
shift @pos // (return " Please specify a volume group or logical volume", 0)
l!l
00
MC/DC0%0/1
shift @pos // (return " Please specify a volume group or logical volume", 0)
shift @pos
Truth table0%0/2
A
A= shift @pos
Aresult
11
00
467 0 my ( $vg, $origin );
468 0 ▶ if ($snap) {
Branch: 1 branch
BranchTrueFalseTotal
if ($snap) { } 0 0 0
469 0 ▶ my $c = canon( $dev, $target ) // return ( " Failed to find logical volume \"$target\"", 0 );
Condition0%0/2
canon($dev, $target) // (return qq[ Failed to find logical volume "$target"], 0)
l!l
00
MC/DC0%0/1
canon($dev, $target) // (return qq[ Failed to find logical volume "$target"], 0)
canon($dev, $target)
Truth table0%0/2
A
A= canon($dev, $target)
Aresult
11
00
470 0 ▶ ( $vg, $origin ) = $c =~ m{\A/dev/mapper/([\w.]+)-(.+)\z} or return ( " Failed to find logical volume \"$target\"", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $c =~ m[\A/dev/mapper/([\w.]+)-(.+)\z] or return qq[ Failed to find logical volume "$target"], 0 0 0 0
471 }
472 0 ▶ else { $vg = $target; return ( " Volume group \"$vg\" not found", 0 ) unless $s->{vgs}{$vg} }
Branch: 1 branch
BranchTrueFalseTotal
unless $$s{"vgs"}{$vg} 0 0 0
473 0 ▶ return ( ' Please specify a name.', 0 ) if !defined $name && $snap;
Branch: 1 branch
BranchTrueFalseTotal
if not defined $name and $snap 0 0 0
Condition0%0/3
not defined $name and $snap
!ll&&!rl&&r
000
MC/DC0%0/2
not defined $name and $snap
not defined $name $snap
Truth table0%0/3
not(A) and B
A= not defined $nameB= $snap
ABresult
0X0
100
111
474 0 ▶ $name //= 'lvol0';
Condition0%0/2
$name //= "lvol0"
l!l
00
MC/DC0%0/1
$name //= "lvol0"
$name
Truth table0%0/2
A
A= $name
Aresult
11
00
475 0 ▶ return ( " Logical Volume \"$name\" already exists in volume group \"$vg\"", 0 ) if $s->{vgs}{$vg}{lvs}{$name};
Branch: 1 branch
BranchTrueFalseTotal
if $$s{"vgs"}{$vg}{"lvs"}{$name} 0 0 0
476 0 my ( $vsize, $free ) = _vg_size( $dev, $vg );
477 0 ▶ my $want = defined $size ? _b( $size =~ s/i?B\z//ir ) : defined $ext && $ext =~ /\A(\d+)%FREE\z/i ? int( $free * $1 / 100 ) : 0;
Branch: 2 branches
BranchTrueFalseTotal
defined $size ? : 0 0 0
defined $ext && $ext =~ /\A(\d+)%FREE\z/i ? : 0 0 0
Condition0%0/3
defined $ext and $ext =~ /\A(\d+)%FREE\z/i
!ll&&!rl&&r
000
MC/DC0%0/2
defined $ext and $ext =~ /\A(\d+)%FREE\z/i
defined $ext $ext =~ /\A(\d+)%FREE\z/i
Truth table0%0/3
A and B
A= defined $extB= $ext =~ /\A(\d+)%FREE\z/i
ABresult
0X0
100
111
478 0 ▶ return ( ' Please specify either size or extents.', 0 ) unless $want;
Branch: 1 branch
BranchTrueFalseTotal
unless $want 0 0 0
479 0 ▶ return ( sprintf( " Volume group \"%s\" has insufficient free space (%d extents): %d required.", $vg, $free / 4194304, $want / 4194304 ), 0 ) if $want > $free;
Branch: 1 branch
BranchTrueFalseTotal
if $want > $free 0 0 0
480 0 ▶ $s->{vgs}{$vg}{lvs}{$name} = { size => _h($want), ( $snap ? ( origin => $origin ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
$snap ? : 0 0 0
481 0 return ( " Logical volume \"$name\" created.", 1 );
482 }
483 3 ▶ my $target = shift @pos // return ( ' Please specify a logical volume path.', 0 );
Condition50%1/2
shift @pos // (return " Please specify a logical volume path.", 0)
l!l
30
MC/DC0%0/1
shift @pos // (return " Please specify a logical volume path.", 0)
shift @pos
Truth table50%1/2
A
A= shift @pos
Aresult
11
00
484 3 ▶ my $c = canon( $dev, $target ) // return ( " Failed to find logical volume \"$target\"", 0 );
Condition50%1/2
canon($dev, $target) // (return qq[ Failed to find logical volume "$target"], 0)
l!l
30
MC/DC0%0/1
canon($dev, $target) // (return qq[ Failed to find logical volume "$target"], 0)
canon($dev, $target)
Truth table50%1/2
A
A= canon($dev, $target)
Aresult
11
00
485 3 ▶ my ( $vg, $lv ) = $c =~ m{\A/dev/mapper/([\w.]+)-(.+)\z} or return ( " Failed to find logical volume \"$target\"", 0 );
Branch: 1 branch
BranchTrueFalseTotal
() = $c =~ m[\A/dev/mapper/([\w.]+)-(.+)\z] or return qq[ Failed to find logical volume "$target"], 0 3 0 3
486 3 my $e = $s->{vgs}{$vg}{lvs}{$lv};
487 3 my $old = _b( $e->{size} );
488 3 my ( $vsize, $free ) = _vg_size( $dev, $vg );
489 3 my $new;
490 3 ▶ if ( defined $size ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $size) { } 2 1 3
elsif (defined $ext and $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i) { } 1 0 1
491 2 my ($rel) = $size =~ /\A([+-]?)/;
492 2 ( my $v = $size ) =~ s/\A[+-]//;
493 2 $v =~ s/i?B\z//i;
494 2 ▶ $new = $rel eq '+' ? $old + _b($v) : $rel eq '-' ? $old - _b($v) : _b($v);
Branch: 2 branches
BranchTrueFalseTotal
$rel eq '+' ? : 2 0 2
$rel eq '-' ? : 0 0 0
495 }
496 1 ▶ elsif ( defined $ext && $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i ) { $new = $old + int( ( uc $2 eq 'FREE' ? $free : $vsize ) * $1 / 100 ) }
Branch: 1 branch
BranchTrueFalseTotal
uc $2 eq 'FREE' ? : 1 0 1
Condition33%1/3
defined $ext and $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i
!ll&&!rl&&r
001
MC/DC0%0/2
defined $ext and $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i
defined $ext $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i
Truth table33%1/3
A and B
A= defined $extB= $ext =~ /\A\+?(\d+)%(FREE|VG)\z/i
ABresult
0X0
100
111
497 0 else { return ( ' Please specify either size or extents but not both.', 0 ) }
498 3 ▶ return ( " New size given (" . int( $new / 4194304 ) . " extents) not larger than existing size (" . int( $old / 4194304 ) . " extents)", 0 )
Branch: 1 branch
BranchTrueFalseTotal
if $prog eq "lvextend" and $new <= $old 0 3 3
Condition33%1/3
$prog eq "lvextend" and $new <= $old
!ll&&!rl&&r
030
MC/DC0%0/2
$prog eq "lvextend" and $new <= $old
$prog eq "lvextend" $new <= $old
Truth table33%1/3
A and B
A= $prog eq "lvextend"B= $new <= $old
ABresult
0X0
100
111
499 if $prog eq 'lvextend' && $new <= $old;
500 3 ▶ return ( " Insufficient free space: " . int( ( $new - $old ) / 4194304 ) . " extents needed, but only " . int( $free / 4194304 ) . " available", 0 )
Branch: 1 branch
BranchTrueFalseTotal
if $new - $old > $free 1 2 3
501 if $new - $old > $free;
502 2 ▶ return ( " WARNING: Reducing active and open logical volume to " . _gib($new) . ".\n THIS MAY DESTROY YOUR DATA (filesystem etc.)\nDo you really want to reduce $vg/$lv? [y/n]: [n]\n Logical volume $vg/$lv NOT reduced.", 0 )
Branch: 1 branch
BranchTrueFalseTotal
if $new < $old 0 2 2
503 if $new < $old;
504 2 $e->{size} = _h($new);
505 2 my @o = ( " Size of logical volume $vg/$lv changed from " . _gib($old) . ' (' . int( $old / 4194304 ) . ' extents) to ' . _gib($new) . ' (' . int( $new / 4194304 ) . ' extents).',
506 " Logical volume $vg/$lv successfully resized." );
507 2 ▶ if ($resize) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resize) 1 1 2
508 1 my ($mp) = _mounted_at( $dev, $c );
509 1 ▶ my ( $ro, $rok ) = ( $e->{fstype} // '' ) eq 'xfs' ? xfs_growfs( $dev, [ $mp // $c ] ) : resize2fs( $dev, [$c] );
Branch: 1 branch
BranchTrueFalseTotal
($$e{'fstype'} // '') eq 'xfs' ? : 0 1 1
Condition20%1/5
$$e{"fstype"} // ""
l!l
10
$mp // $c
l!l&&r!l&&!r
000
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
MC/DC0%0/2
$mp // $c
$mp $c
Truth table50%1/2
A
A= $$e{"fstype"}
Aresult
11
00
Truth table0%0/3
A // B
A= $mpB= $c
ABresult
1X1
011
000
510 1 push @o, $ro;
511 1 return ( join( "\n", @o ), $rok );
512 }
513 1 return ( join( "\n", @o ), 1 );
514 }
515 0 return ( '', 0 );
516 }
517  
518 3 ▶sub _uuid {
Subroutine _uuid: called CC=3 SCAR=11.0
519 3 my ( $dev, $c, $salt ) = @_;
520 3 require Digest::SHA;
521 3 ▶ my $h = Digest::SHA::sha1_hex( join '|', $dev->{hostname} // '', $c, $salt, scalar keys %{ _all($dev) } );
Condition50%1/2
$$dev{"hostname"} // ""
l!l
30
MC/DC0%0/1
$$dev{"hostname"} // ""
$$dev{"hostname"}
Truth table50%1/2
A
A= $$dev{"hostname"}
Aresult
11
00
522 3 ▶ return $salt eq 'pv' ? join( '-', substr( $h, 0, 6 ), substr( $h, 6, 4 ), substr( $h, 10, 4 ), substr( $h, 14, 4 ), substr( $h, 18, 4 ), substr( $h, 22, 4 ), substr( $h, 26, 6 ) )
Branch: 1 branch
BranchTrueFalseTotal
$salt eq 'pv' ? : 1 2 3
523 : join( '-', substr( $h, 0, 8 ), substr( $h, 8, 4 ), substr( $h, 12, 4 ), substr( $h, 16, 4 ), substr( $h, 20, 12 ) );
524 }
525  
526 # --- Dateisysteme ------------------------------------------------------------------
527  
528 3 ▶sub _grow {
Subroutine _grow: called CC=4 SCAR=17.2
529 3 my ( $dev, $c, $e, $to ) = @_;
530 3 my @mp = _mounted_at( $dev, $c );
531 3 ▶ if (@mp) { $dev->{mounts}{$_}{size} = _h($to) for @mp; delete $e->{fssize} }
Branch: 1 branch
BranchTrueFalseTotal
if (@mp) { } 3 0 3
532 0 ▶ else { if ( $to == _b( $e->{size} ) ) { delete $e->{fssize} } else { $e->{fssize} = _h($to) } }
Branch: 1 branch
BranchTrueFalseTotal
if ($to == _b($$e{'size'})) { } 0 0 0
533 3 return @mp;
534 }
535  
536  
537 3 ▶sub resize2fs {
Subroutine resize2fs: called CC=13 SCAR=28.0
Pod documented
538 3 my ( $dev, $av ) = @_;
539 3 my @a = grep { !/\A-/ } @$av;
540 3 my ( $p, $want ) = @a;
541 3 ▶ return ( "Usage: resize2fs [-d debug_flags] [-f] [-F] [-M] [-P] [-p] device [-b|-s|new_size] [-S RAID-stride] [-z undo_file]", 0 ) unless defined $p;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $p 0 3 3
542 3 my ( $c, $e ) = _bd( $dev, $p );
543 3 ▶ return ( "resize2fs 1.47.0 (5-Feb-2023)\nopen: No such file or directory while opening $p", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 3 3
544 return ( "resize2fs 1.47.0 (5-Feb-2023)\nresize2fs: Bad magic number in super-block while trying to open $p\nCouldn't find valid filesystem superblock.", 0 )
545 3 ▶ unless ( $e->{fstype} // '' ) =~ /\Aext[234]\z/;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$e{"fstype"} // "") =~ /\Aext[234]\z/ 1 2 3
Condition50%1/2
$$e{"fstype"} // ""
l!l
30
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
Truth table50%1/2
A
A= $$e{"fstype"}
Aresult
11
00
546 2 my @mp = _mounted_at( $dev, $c );
547 2 ▶ my $cur = @mp ? _b( $dev->{mounts}{ $mp[0] }{size} ) : _fssize($e);
Branch: 1 branch
BranchTrueFalseTotal
@mp ? : 2 0 2
548 2 ▶ my $to = defined $want ? _b( $want =~ s/i?B\z//ir ) : _b( $e->{size} );
Branch: 1 branch
BranchTrueFalseTotal
defined $want ? : 0 2 2
549 2 ▶ my $blocks = sub { int( $_[0] / 4096 ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
550 return ( "resize2fs 1.47.0 (5-Feb-2023)\nThe containing partition (or device) is only " . $blocks->( _b( $e->{size} ) ) . " (4k) blocks.\nYou requested a new size of " . $blocks->($to) . " blocks.\n", 0 )
551 2 ▶ if $to > _b( $e->{size} );
Branch: 1 branch
BranchTrueFalseTotal
if $to > _b($$e{"size"}) 0 2 2
552 2 ▶ return ( "resize2fs 1.47.0 (5-Feb-2023)\nThe filesystem is already " . $blocks->($cur) . " (4k) blocks long. Nothing to do!\n", 1 ) if $to == $cur;
Branch: 1 branch
BranchTrueFalseTotal
if $to == $cur 0 2 2
553 2 ▶ return ( "resize2fs 1.47.0 (5-Feb-2023)\nFilesystem at $c is mounted on $mp[0]; on-line resizing required\nresize2fs: On-line shrinking not supported", 0 ) if $to < $cur && @mp;
Branch: 1 branch
BranchTrueFalseTotal
if $to < $cur and @mp 0 2 2
Condition33%1/3
$to < $cur and @mp
!ll&&!rl&&r
200
MC/DC0%0/2
$to < $cur and @mp
$to < $cur @mp
Truth table33%1/3
A and B
A= $to < $curB= @mp
ABresult
0X0
100
111
554 2 ▶ return ( "resize2fs 1.47.0 (5-Feb-2023)\nPlease run 'e2fsck -f $p' first.\n", 0 ) if $to < $cur;
Branch: 1 branch
BranchTrueFalseTotal
if $to < $cur 0 2 2
555 2 _grow( $dev, $c, $e, $to );
556 2 ▶ return ( "resize2fs 1.47.0 (5-Feb-2023)\n" . ( @mp ? "Filesystem at $c is mounted on $mp[0]; on-line resizing required\nold_desc_blocks = 3, new_desc_blocks = 4\n" : "Resizing the filesystem on $c to " . $blocks->($to) . " (4k) blocks.\n" )
Branch: 1 branch
BranchTrueFalseTotal
@mp ? : 2 0 2
557 . "The filesystem on $c is now " . $blocks->($to) . " (4k) blocks long.\n", 1 );
558 }
559  
560  
561 1 ▶sub xfs_growfs {
Subroutine xfs_growfs: called CC=11 SCAR=26.3
Pod documented
562 1 my ( $dev, $av ) = @_;
563 1 my ($t) = grep { !/\A-/ } @$av;
564 1 ▶ return ( "Usage: xfs_growfs [options] mountpoint", 0 ) unless defined $t;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $t 0 1 1
565 1 $t =~ s{(?<=.)/+\z}{};
566 1 ▶ my $m = $dev->{mounts} || {};
Condition50%1/2
$$dev{'mounts'} || {}
l!l
10
MC/DC0%0/1
$$dev{'mounts'} || {}
$$dev{'mounts'}
Truth table50%1/2
A
A= $$dev{'mounts'}
Aresult
11
00
567 1 ▶ my ($mp) = grep { $_ eq $t || ( canon( $dev, $m->{$_}{dev} ) // '' ) eq ( canon( $dev, $t ) // '-' ) } sort keys %$m;
Condition57%4/7
$_ eq $t || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $t) // '-')
l!l&&r!l&&!r
103
canon($dev, $$m{$_}{"dev"}) // ""
l!l
30
canon($dev, $t) // "-"
l!l
03
MC/DC0%0/2
$_ eq $t || (canon($dev, $$m{$_}{'dev'}) // '') eq (canon($dev, $t) // '-')
$_ eq $t canon($dev, $$m{$_}{"dev"})
MC/DC0%0/1
canon($dev, $t) // "-"
canon($dev, $t)
Truth table66%2/3
A || B
A= $_ eq $tB= canon($dev, $$m{$_}{"dev"})
ABresult
1X1
011
000
Truth table50%1/2
A
A= canon($dev, $t)
Aresult
11
00
568 1 ▶ my ( $c, $e ) = defined $mp ? _bd( $dev, $m->{$mp}{dev} ) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $mp ? : 1 0 1
569 1 ▶ return ( "xfs_growfs: $t is not a mounted XFS filesystem", 0 ) unless $e && ( $e->{fstype} // '' ) eq 'xfs';
Branch: 1 branch
BranchTrueFalseTotal
unless $e and ($$e{"fstype"} // "") eq "xfs" 0 1 1
Condition40%2/5
$e and ($$e{"fstype"} // "") eq "xfs"
!ll&&!rl&&r
001
$$e{"fstype"} // ""
l!l
10
MC/DC0%0/2
$e and ($$e{"fstype"} // "") eq "xfs"
$e $$e{"fstype"}
Truth table33%1/3
A and B
A= $eB= $$e{"fstype"}
ABresult
0X0
100
111
570 1 my $old = _b( $m->{$mp}{size} );
571 1 my $new = _b( $e->{size} );
572 1 my $info = "meta-data=$c isize=512 agcount=4, agsize=" . int( $old / 16384 ) . " blks\ndata = bsize=4096 blocks=" . int( $old / 4096 ) . ", imaxpct=25";
573 1 ▶ return ( "$info\n", 1 ) if $new <= $old;
Branch: 1 branch
BranchTrueFalseTotal
if $new <= $old 0 1 1
574 1 _grow( $dev, $c, $e, $new );
575 1 return ( "$info\ndata blocks changed from " . int( $old / 4096 ) . ' to ' . int( $new / 4096 ), 1 );
576 }
577  
578  
579 3 ▶sub mkfs {
Subroutine mkfs: called CC=23 SCAR=38.4
Pod documented
580 3 my ( $dev, $av, $ctx, $prog ) = @_;
581 3 my @a = @$av;
582 3 my ( $type, $force, $label, @pos );
583 3 ($type) = $prog =~ /\Amkfs\.(\w+)\z/;
584 3 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 4 3 7
585 4 my $x = shift @a;
586 0 ▶ if ( $x eq '-t' ) { $type = shift @a }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq '-t') { } 0 4 4
elsif ($x eq '-L') { } 1 3 4
elsif ($x =~ /\A-[Ff]+\z/) { } 0 3 3
elsif ($x =~ /\A-/) { } 0 3 3
587 1 elsif ( $x eq '-L' ) { $label = shift @a }
588 0 elsif ( $x =~ /\A-[Ff]+\z/ ) { $force = 1 }
589 elsif ( $x =~ /\A-/ ) { }
590 3 else { push @pos, $x }
591 }
592 3 ▶ $type //= 'ext2';
Condition50%1/2
$type //= "ext2"
l!l
30
MC/DC0%0/1
$type //= "ext2"
$type
Truth table50%1/2
A
A= $type
Aresult
11
00
593 3 my ($p) = @pos;
594 3 ▶ my ( $c, $e ) = _bd( $dev, $p // '' );
Condition50%1/2
$p // ""
l!l
30
MC/DC0%0/1
$p // ""
$p
Truth table50%1/2
A
A= $p
Aresult
11
00
595 3 ▶ return ( "mke2fs 1.47.0 (5-Feb-2023)\nThe file " . ( $p // '' ) . " does not exist and no size was specified.", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 3 3
Condition0%0/2
$p // ""
l!l
00
MC/DC0%0/1
$p // ""
$p
Truth table0%0/2
A
A= $p
Aresult
11
00
596 0 ▶ if ( _mounted_at( $dev, $c ) || grep { _mounted_at( $dev, $_ ) } _parts( $dev, $c ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (_mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c)) 2 1 3
Condition66%2/3
_mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c)
l!l&&r!l&&!r
201
MC/DC50%1/2
_mounted_at($dev, $c) or grep {_mounted_at($dev, $_);} _parts($dev, $c)
_mounted_at($dev, $c) grep {_mounted_at($dev, $_);} _parts($dev, $c)
Truth table66%2/3
A or B
A= _mounted_at($dev, $c)B= grep {_mounted_at($dev, $_);} _parts($dev, $c)
ABresult
1X1
011
000
597 2 ▶ return $type eq 'xfs' ? ( "mkfs.xfs: $p contains a mounted filesystem\nUsage: mkfs.xfs", 0 ) : ( "mke2fs 1.47.0 (5-Feb-2023)\n$p contains a $e->{fstype} file system\n\tlast mounted on " . ( _mounted_at( $dev, $c ) )[0] . "\n/dev: $p is mounted; will not make a filesystem here!", 0 );
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'xfs' ? : 0 2 2
598 }
599 1 ▶ return ( "mkfs.$type: $p is apparently in use by the system; will not make a filesystem here!", 0 ) if _vg_of_pv( $dev, $c ) || grep { exists( ( $_->{members} || {} )->{$c} ) } values %{ _st($dev)->{md} || {} };
Branch: 1 branch
BranchTrueFalseTotal
if _vg_of_pv($dev, $c) or grep {exists(($$_{"members"} || {})->{$c});} values %{_st($dev)->{"md"} or {};} 0 1 1
Condition42%3/7
_vg_of_pv($dev, $c) or grep {exists(($$_{"members"} || {})->{$c});} values %{_st($dev)->{"md"} or {};}
l!l&&r!l&&!r
001
$$_{'members'} || {}
l!l
10
_st($dev)->{'md'} || {}
l!l
10
MC/DC0%0/2
_vg_of_pv($dev, $c) or grep {exists(($$_{"members"} || {})->{$c});} values %{_st($dev)->{"md"} or {};}
_vg_of_pv($dev, $c) grep {exists(($$_{"members"} || {})->{$c});} values %{_st($dev)->{"md"} or {};}
MC/DC0%0/1
$$_{'members'} || {}
$$_{'members'}
MC/DC0%0/1
_st($dev)->{'md'} || {}
_st($dev)->{'md'}
Truth table33%1/3
A or B
A= _vg_of_pv($dev, $c)B= grep {exists(($$_{"members"} || {})->{$c});} values %{_st($dev)->{"md"} or {};}
ABresult
1X1
011
000
Truth table50%1/2
A
A= $$_{'members'}
Aresult
11
00
Truth table50%1/2
A
A= _st($dev)->{'md'}
Aresult
11
00
600 1 ▶ if ( $e->{fstype} && !$force ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$e{"fstype"} and not $force) 0 1 1
Condition33%1/3
$$e{"fstype"} and not $force
!ll&&!rl&&r
100
MC/DC0%0/2
$$e{"fstype"} and not $force
$$e{"fstype"} not $force
Truth table33%1/3
A and not(B)
A= $$e{"fstype"}B= not $force
ABresult
0X0
100
111
601 0 ▶ return $type eq 'xfs' ? ( "mkfs.xfs: $p appears to contain an existing filesystem ($e->{fstype}).\nmkfs.xfs: Use the -f option to force overwrite.", 0 )
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'xfs' ? : 0 0 0
602 : ( "mke2fs 1.47.0 (5-Feb-2023)\n$p contains a $e->{fstype} file system\nProceed anyway? (y,N) ", 0 );
603 }
604 1 delete @{$e}{qw( offline fssize errors reserved_pct )};
605 1 $e->{fstype} = $type;
606 1 $e->{uuid} = _uuid( $dev, $c, "fs-$type" );
607 0 ▶ if ( defined $label ) { $e->{label} = $label } else { delete $e->{label} }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $label) { } 1 0 1
608 1 ▶ $e->{reserved_pct} = 5 if $type =~ /\Aext/;
Branch: 1 branch
BranchTrueFalseTotal
if $type =~ /\Aext/ 1 0 1
609 1 ▶ return ( $type eq 'xfs' ? "meta-data=$p isize=512 agcount=4\ndata = bsize=4096 blocks=" . int( _b( $e->{size} ) / 4096 ) : "mke2fs 1.47.0 (5-Feb-2023)\nCreating filesystem with " . int( _b( $e->{size} ) / 4096 ) . " 4k blocks and 6553600 inodes\nFilesystem UUID: $e->{uuid}\nWriting superblocks and filesystem accounting information: done\n", 1 );
Branch: 1 branch
BranchTrueFalseTotal
$type eq 'xfs' ? : 0 1 1
610 }
611  
612  
613 1 ▶sub tune2fs {
Subroutine tune2fs: called CC=24 SCAR=42.4
Pod documented
614 1 my ( $dev, $av ) = @_;
615 1 my @a = @$av;
616 1 my ( $list, $pct, $p );
617 1 ▶ while (@a) {
Branch: 1 branch
BranchTrueFalseTotal
if (@a) 2 1 3
618 2 my $x = shift @a;
619 0 ▶ if ( $x eq '-l' ) { $list = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if ($x eq '-l') { } 0 2 2
elsif ($x eq '-m') { } 1 1 2
elsif ($x =~ /\A-m(\d+(?:\.\d+)?)\z/) { } 0 1 1
elsif (not $x =~ /\A-/) { } 1 0 1
620 1 elsif ( $x eq '-m' ) { $pct = shift @a }
621 0 elsif ( $x =~ /\A-m(\d+(?:\.\d+)?)\z/ ) { $pct = $1 }
622 1 elsif ( $x !~ /\A-/ ) { $p = $x }
623 }
624 1 ▶ my ( $c, $e ) = _bd( $dev, $p // '' );
Condition50%1/2
$p // ""
l!l
10
MC/DC0%0/1
$p // ""
$p
Truth table50%1/2
A
A= $p
Aresult
11
00
625 1 ▶ return ( "tune2fs 1.47.0 (5-Feb-2023)\ntune2fs: No such file or directory while trying to open " . ( $p // '' ) . "\nCouldn't find valid filesystem superblock.", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 1 1
Condition0%0/2
$p // ""
l!l
00
MC/DC0%0/1
$p // ""
$p
Truth table0%0/2
A
A= $p
Aresult
11
00
626 1 ▶ return ( "tune2fs 1.47.0 (5-Feb-2023)\ntune2fs: Bad magic number in super-block while trying to open $p", 0 ) unless ( $e->{fstype} // '' ) =~ /\Aext/;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$e{"fstype"} // "") =~ /\Aext/ 0 1 1
Condition50%1/2
$$e{"fstype"} // ""
l!l
10
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
Truth table50%1/2
A
A= $$e{"fstype"}
Aresult
11
00
627 1 my @mp = _mounted_at( $dev, $c );
628 1 ▶ my $size = @mp ? _b( $dev->{mounts}{ $mp[0] }{size} ) : _fssize($e);
Branch: 1 branch
BranchTrueFalseTotal
@mp ? : 1 0 1
629 1 ▶ my $cur = @mp ? $dev->{mounts}{ $mp[0] }{reserved_pct} // $e->{reserved_pct} // 5 : $e->{reserved_pct} // 5;
Branch: 1 branch
BranchTrueFalseTotal
@mp ? : 1 0 1
Condition28%2/7
($$dev{"mounts"}{$mp[0]}{"reserved_pct"} // $$e{"reserved_pct"}) // 5
l!l
10
$$dev{"mounts"}{$mp[0]}{"reserved_pct"} // $$e{"reserved_pct"}
l!l&&r!l&&!r
100
$$e{"reserved_pct"} // 5
l!l
00
MC/DC0%0/2
($$dev{"mounts"}{$mp[0]}{"reserved_pct"} // $$e{"reserved_pct"}) // 5
$$dev{"mounts"}{$mp[0]}{"reserved_pct"} $$e{"reserved_pct"}
MC/DC0%0/1
$$e{"reserved_pct"} // 5
$$e{"reserved_pct"}
Truth table33%1/3
A // B
A= $$dev{"mounts"}{$mp[0]}{"reserved_pct"}B= $$e{"reserved_pct"}
ABresult
1X1
011
000
Truth table0%0/2
A
A= $$e{"reserved_pct"}
Aresult
11
00
630 1 ▶ if ( defined $pct ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $pct) 1 0 1
631 1 ▶ return ( "tune2fs 1.47.0 (5-Feb-2023)\nbad reserved block ratio - $pct", 0 ) unless $pct =~ /\A\d+(?:\.\d+)?\z/ && $pct <= 50;
Branch: 1 branch
BranchTrueFalseTotal
unless $pct =~ /\A\d+(?:\.\d+)?\z/ and $pct <= 50 0 1 1
Condition33%1/3
$pct =~ /\A\d+(?:\.\d+)?\z/ and $pct <= 50
!ll&&!rl&&r
001
MC/DC0%0/2
$pct =~ /\A\d+(?:\.\d+)?\z/ and $pct <= 50
$pct =~ /\A\d+(?:\.\d+)?\z/ $pct <= 50
Truth table33%1/3
A and B
A= $pct =~ /\A\d+(?:\.\d+)?\z/B= $pct <= 50
ABresult
0X0
100
111
632 1 $pct = 0 + $pct;
633 1 ▶ if (@mp) { $dev->{mounts}{$_}{reserved_pct} = $pct for @mp }
Branch: 1 branch
BranchTrueFalseTotal
if (@mp) 1 0 1
634 1 $e->{reserved_pct} = $pct;
635 1 return ( "tune2fs 1.47.0 (5-Feb-2023)\nSetting reserved blocks percentage to $pct% (" . int( $size / 4096 * $pct / 100 ) . " blocks)", 1 );
636 }
637 return ( join( "\n", 'tune2fs 1.47.0 (5-Feb-2023)', "Filesystem volume name: " . ( $e->{label} // '<none>' ), "Filesystem UUID: " . ( $e->{uuid} // '' ),
638 0 ▶ 'Filesystem state: ' . ( $e->{errors} ? 'not clean with errors' : 'clean' ), 'Errors behavior: Continue',
Branch: 1 branch
BranchTrueFalseTotal
$$e{'errors'} ? : 0 0 0
Condition0%0/4
$$e{"label"} // "<none>"
l!l
00
$$e{"uuid"} // ""
l!l
00
MC/DC0%0/1
$$e{"label"} // "<none>"
$$e{"label"}
MC/DC0%0/1
$$e{"uuid"} // ""
$$e{"uuid"}
Truth table0%0/2
A
A= $$e{"label"}
Aresult
11
00
Truth table0%0/2
A
A= $$e{"uuid"}
Aresult
11
00
639 'Block count: ' . int( $size / 4096 ), 'Reserved block count: ' . int( $size / 4096 * $cur / 100 ), 'Block size: 4096' ), 1 );
640 }
641  
642  
643 2 ▶sub fsck {
Subroutine fsck: called CC=11 SCAR=29.5
Pod documented
644 2 my ( $dev, $av ) = @_;
645 2 my ($p) = grep { !/\A-/ } @$av;
646 2 my $dry = grep { $_ eq '-n' } @$av;
647 2 ▶ my ( $c, $e ) = _bd( $dev, $p // '' );
Condition50%1/2
$p // ""
l!l
20
MC/DC0%0/1
$p // ""
$p
Truth table50%1/2
A
A= $p
Aresult
11
00
648 2 ▶ return ( "e2fsck 1.47.0 (5-Feb-2023)\ne2fsck: No such file or directory while trying to open " . ( $p // '' ), 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 0 2 2
Condition0%0/2
$p // ""
l!l
00
MC/DC0%0/1
$p // ""
$p
Truth table0%0/2
A
A= $p
Aresult
11
00
649 2 ▶ return ( "e2fsck 1.47.0 (5-Feb-2023)\n$p is mounted.\ne2fsck: Cannot continue, aborting.\n", 0 ) if _mounted_at( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _mounted_at($dev, $c) 1 1 2
650 1 ▶ return ( "fsck.$e->{fstype}: not supported here", 0 ) unless ( $e->{fstype} // '' ) =~ /\Aext/;
Branch: 1 branch
BranchTrueFalseTotal
unless ($$e{"fstype"} // "") =~ /\Aext/ 0 1 1
Condition50%1/2
$$e{"fstype"} // ""
l!l
10
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
Truth table50%1/2
A
A= $$e{"fstype"}
Aresult
11
00
651 1 ▶ if ( $e->{errors} && !$dry && grep { /\A-\w*[yp]/ } @$av ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($$e{"errors"} and not $dry and grep {/\A-\w*[yp]/;} @$av) 1 0 1
Condition33%2/6
$$e{"errors"} and not $dry and grep {/\A-\w*[yp]/;} @$av
!ll&&!rl&&r
001
$$e{"errors"} and not $dry
!ll&&!rl&&r
001
MC/DC0%0/3
$$e{"errors"} and not $dry and grep {/\A-\w*[yp]/;} @$av
$$e{"errors"} not $dry grep {/\A-\w*[yp]/;} @$av
Truth table25%1/4
A and not(B) and C
A= $$e{"errors"}B= not $dryC= grep {/\A-\w*[yp]/;} @$av
ABCresult
0XX0
10X0
1100
1111
652 1 delete $e->{errors};
653 1 return ( "e2fsck 1.47.0 (5-Feb-2023)\nPass 1: Checking inodes, blocks, and sizes\nInode 1311 has illegal block(s). Clear? yes\nPass 2: Checking directory structure\nPass 3: Checking directory connectivity\nPass 4: Checking reference counts\nPass 5: Checking group summary information\n\n$p: ***** FILE SYSTEM WAS MODIFIED *****\n$p: 41022/6553600 files (0.4% non-contiguous), 3820112/26214400 blocks", 1 );
654 }
655 0 ▶ return ( "e2fsck 1.47.0 (5-Feb-2023)\nPass 1: Checking inodes, blocks, and sizes\nInode 1311 has illegal block(s). Clear? no\n\n$p: ********** WARNING: Filesystem still has errors **********", 0 ) if $e->{errors};
Branch: 1 branch
BranchTrueFalseTotal
if $$e{"errors"} 0 0 0
656 0 return ( "e2fsck 1.47.0 (5-Feb-2023)\n$p: clean, 41022/6553600 files, 3820112/26214400 blocks", 1 );
657 }
658  
659 # --- Swap --------------------------------------------------------------------------
660  
661 # frei fuer root (darf die reservierten Bloecke nutzen) auf dem Dateisystem eines Pfads
662 1 ▶sub _root_free {
Subroutine _root_free: called CC=5 SCAR=17.2
663 1 my ( $dev, $path ) = @_;
664 1 ▶ my $mp = _L( '_mount_of', $dev, $path ) // return 0 + 'inf';
Condition50%1/2
_L("_mount_of", $dev, $path) // (return "Inf")
l!l
10
MC/DC0%0/1
_L("_mount_of", $dev, $path) // (return "Inf")
_L("_mount_of", $dev, $path)
Truth table50%1/2
A
A= _L("_mount_of", $dev, $path)
Aresult
11
00
665 1 my ($r) = grep { $_->{mount} eq $mp } _L( '_df_rows', $dev );
666 1 ▶ my $old = ( $dev->{files} || {} )->{$path};
Condition50%1/2
$$dev{'files'} || {}
l!l
10
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
667 1 ▶ return $r ? $r->{size} - $r->{used} + ( ref $old eq 'HASH' ? _L( '_file_size', $old ) : 0 ) : 0 + 'inf';
Branch: 2 branches
BranchTrueFalseTotal
$r ? : 1 0 1
ref $old eq 'HASH' ? : 0 1 1
668 }
669  
670  
671 5 ▶sub swap {
Subroutine swap: called CC=59 SCAR=64.8
Pod documented
672 5 my ( $dev, $av, $ctx, $prog ) = @_;
673 5 my $s = _st($dev);
674 5 my @a = @$av;
675 5 my @pos = grep { !/\A-/ } @a;
676 5 ▶ my $abs = sub { _L( '_absp', $_[0] ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
677 5 ▶ if ( $prog eq 'fallocate' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "fallocate") 1 4 5
678 1 my ($len) = join( ' ', @a ) =~ /(?:-l\s*|--length[= ])(\S+)/;
679 1 ▶ my ($f) = grep { $_ ne ( $len // '' ) } @pos;
Condition50%1/2
$len // ""
l!l
20
MC/DC0%0/1
$len // ""
$len
Truth table50%1/2
A
A= $len
Aresult
11
00
680 1 ▶ return ( "fallocate: no length argument specified", 0 ) unless defined $len && defined $f;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $len and defined $f 0 1 1
Condition33%1/3
defined $len and defined $f
!ll&&!rl&&r
001
MC/DC0%0/2
defined $len and defined $f
defined $len defined $f
Truth table33%1/3
A and B
A= defined $lenB= defined $f
ABresult
0X0
100
111
681 1 $f = $abs->($f);
682 1 ▶ return ( "fallocate: fallocate failed: No space left on device", 0 ) if _b($len) > _root_free( $dev, $f );
Branch: 1 branch
BranchTrueFalseTotal
if _b($len) > _root_free($dev, $f) 0 1 1
683 1 ▶ my $old = ( $dev->{files} || {} )->{$f};
Condition50%1/2
$$dev{'files'} || {}
l!l
10
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
684 1 ▶ $dev->{files}{$f} = { size => _b($len), owner => 'root', group => 'root', mode => ref $old eq 'HASH' ? $old->{mode} // '0644' : '0644', mtime => 'Oct 20 12:00', content => '' };
Branch: 1 branch
BranchTrueFalseTotal
ref $old eq 'HASH' ? : 0 1 1
Condition0%0/2
$$old{"mode"} // "0644"
l!l
00
MC/DC0%0/1
$$old{"mode"} // "0644"
$$old{"mode"}
Truth table0%0/2
A
A= $$old{"mode"}
Aresult
11
00
685 1 return ( '', 1 );
686 }
687 4 ▶ if ( $prog eq 'dd' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "dd") 0 4 4
688 0 ▶ my %o = map { /\A(\w+)=(.*)\z/ ? ( $1 => $2 ) : () } @a;
Branch: 1 branch
BranchTrueFalseTotal
/\A(\w+)=(.*)\z/ ? : 0 0 0
689 0 ▶ return ( '', 0 ) unless defined $o{of};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $o{"of"} 0 0 0
690 0 ▶ my $bs = _b( $o{bs} // '512' );
Condition0%0/2
$o{"bs"} // 512
l!l
00
MC/DC0%0/1
$o{"bs"} // 512
$o{"bs"}
Truth table0%0/2
A
A= $o{"bs"}
Aresult
11
00
691 0 ▶ my $n = $o{count} // 0;
Condition0%0/2
$o{"count"} // 0
l!l
00
MC/DC0%0/1
$o{"count"} // 0
$o{"count"}
Truth table0%0/2
A
A= $o{"count"}
Aresult
11
00
692 0 my $f = $abs->( $o{of} );
693 0 my $room = _root_free( $dev, $f );
694 0 ▶ if ( $bs * $n > $room ) { # schreibt bis die Platte voll ist
Branch: 1 branch
BranchTrueFalseTotal
if ($bs * $n > $room) 0 0 0
695 0 ▶ my $k = int( $room / ( $bs || 1 ) );
Condition0%0/2
$bs || 1
l!l
00
MC/DC0%0/1
$bs || 1
$bs
Truth table0%0/2
A
A= $bs
Aresult
11
00
696 0 $dev->{files}{$f} = { size => $k * $bs, owner => 'root', group => 'root', mode => '0644', mtime => 'Oct 20 12:00', content => '' };
697 0 return ( "dd: error writing '$o{of}': No space left on device\n$k+0 records in\n$k+0 records out\n" . ( $k * $bs ) . " bytes copied, 2.0 s, 1.4 GB/s", 0 );
698 }
699 0 $dev->{files}{$f} = { size => $bs * $n, owner => 'root', group => 'root', mode => '0644', mtime => 'Oct 20 12:00', content => '' };
700 0 return ( "$n+0 records in\n$n+0 records out\n" . ( $bs * $n ) . " bytes copied, 3.1 s, 1.4 GB/s", 1 );
701 }
702 4 ▶ if ( $prog eq 'free' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "free") 0 4 4
703 0 my $h = grep {/\A-\w*h/} @a;
704 0 my $sw = 0;
705 0 ▶ $sw += _b( $_->{size} ) for @{ $s->{swaps} || [] };
Condition0%0/2
$$s{'swaps'} || []
l!l
00
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table0%0/2
A
A= $$s{'swaps'}
Aresult
11
00
706 0 ▶ my $f = $h ? sub { _h( $_[0] ) . 'i' } : sub { int( $_[0] / 1024 ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
Subroutine __ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$h ? : 0 0 0
707 return ( join( "\n", sprintf( '%15s %11s %11s %11s %11s %11s', qw( total used free shared buff/cache available ) ),
708 0 ▶ sprintf( 'Mem: %10s %11s %11s %11s %11s %11s', map { $f->( _b($_) ) } qw( 8G 6G 400M 120M 1.6G 1.5G ) ),
Branch: 2 branches
BranchTrueFalseTotal
$sw ? : 0 0 0
$sw ? : 0 0 0
709 sprintf( 'Swap:%10s %11s %11s', $f->($sw), $f->( $sw ? int( $sw / 4 ) : 0 ), $f->( $sw - ( $sw ? int( $sw / 4 ) : 0 ) ) ) ), 1 );
710 }
711 4 ▶ if ( $prog eq 'mkswap' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "mkswap") 1 3 4
712 1 ▶ my $p = $pos[-1] // return ( 'mkswap: no device specified', 0 );
Condition50%1/2
$pos[-1] // (return "mkswap: no device specified", 0)
l!l
10
MC/DC0%0/1
$pos[-1] // (return "mkswap: no device specified", 0)
$pos[-1]
Truth table50%1/2
A
A= $pos[-1]
Aresult
11
00
713 1 my ( $c, $e ) = _bd( $dev, $p );
714 1 ▶ if ($e) {
Branch: 1 branch
BranchTrueFalseTotal
if ($e) 0 1 1
715 0 ▶ return ( "mkswap: error: $p is mounted; will not make swapspace", 0 ) if _mounted_at( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _mounted_at($dev, $c) 0 0 0
716 0 $e->{fstype} = 'swap';
717 0 $e->{uuid} = _uuid( $dev, $c, 'swap' );
718 0 return ( "Setting up swapspace version 1, size = " . _gib( _b( $e->{size} ) ) . "\nno label, UUID=$e->{uuid}", 1 );
719 }
720 1 my $f = $abs->($p);
721 1 ▶ my $fe = ( $dev->{files} || {} )->{$f};
Condition50%1/2
$$dev{'files'} || {}
l!l
10
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
722 1 ▶ return ( "mkswap: cannot open $p: No such file or directory", 0 ) unless ref $fe eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $fe eq "HASH" 0 1 1
723 1 $fe->{swap} = _uuid( $dev, $f, 'swap' );
724 1 ▶ my $w = ( $fe->{mode} // '0644' ) ne '0600' ? "mkswap: $f: insecure permissions " . ( $fe->{mode} // '0644' ) . ", fix with: chmod 0600 $f\n" : '';
Branch: 1 branch
BranchTrueFalseTotal
($$fe{'mode'} // '0644') ne '0600' ? : 0 1 1
Condition25%1/4
$$fe{"mode"} // "0644"
l!l
10
$$fe{"mode"} // "0644"
l!l
00
MC/DC0%0/1
$$fe{"mode"} // "0644"
$$fe{"mode"}
MC/DC0%0/1
$$fe{"mode"} // "0644"
$$fe{"mode"}
Truth table50%1/2
A
A= $$fe{"mode"}
Aresult
11
00
Truth table0%0/2
A
A= $$fe{"mode"}
Aresult
11
00
725 1 return ( $w . "Setting up swapspace version 1, size = " . _gib( _b( $fe->{size} ) ) . "\nno label, UUID=$fe->{swap}", 1 );
726 }
727 3 ▶ if ( $prog eq 'swapon' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "swapon") 3 0 3
728 3 ▶ if ( !@pos || grep { $_ eq '--show' || $_ eq '-s' } @a and !grep { $_ eq '-a' } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (!@pos || grep({$_ eq "--show" or $_ eq "-s";} @a) and not grep({$_ eq "-a";} @a)) 1 2 3
Condition55%5/9
!@pos || grep({$_ eq "--show" or $_ eq "-s";} @a) and not grep({$_ eq "-a";} @a)
!ll&&!rl&&r
201
not @pos or grep {$_ eq "--show" or $_ eq "-s";} @a
l!l&&r!l&&!r
102
$_ eq '--show' || $_ eq '-s'
l!l&&r!l&&!r
002
MC/DC33%1/3
!@pos || grep({$_ eq "--show" or $_ eq "-s";} @a) and not grep({$_ eq "-a";} @a)
not @pos grep {$_ eq "--show" or $_ eq "-s";} @a not grep({$_ eq "-a";} @a)
MC/DC0%0/2
$_ eq '--show' || $_ eq '-s'
$_ eq '--show' $_ eq '-s'
Truth table40%2/5
not(A) or B and not(C)
A= not @posB= grep {$_ eq "--show" or $_ eq "-s";} @aC= not grep({$_ eq "-a";} @a)
ABCresult
00X0
1X00
0100
1X11
0111
Truth table33%1/3
A || B
A= $_ eq '--show'B= $_ eq '-s'
ABresult
1X1
011
000
729 1 ▶ return ( '', 1 ) unless @{ $s->{swaps} || [] };
Branch: 1 branch
BranchTrueFalseTotal
unless @{$$s{"swaps"} or [];} 0 1 1
Condition50%1/2
$$s{'swaps'} || []
l!l
10
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table50%1/2
A
A= $$s{'swaps'}
Aresult
11
00
730 return ( join( "\n", sprintf( '%-15s %-9s %5s %4s %4s', qw( NAME TYPE SIZE USED PRIO ) ),
731 1 ▶ map { sprintf '%-15s %-9s %5s %4s %4s', $_->{name}, $_->{name} =~ m{\A/dev/} ? 'partition' : 'file', $_->{size}, '0B', -2 } @{ $s->{swaps} } ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$$_{'name'} =~ m[\A/dev/] ? : 0 1 1
732 }
733 2 my @targets = @pos;
734 0 ▶ if ( grep { $_ eq '-a' } @a ) { push @targets, map { $_->{src} } grep { $_->{type} eq 'swap' && $_->{opts} !~ /noauto/ } _fstab($dev) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-a";} @a) 0 2 2
Condition0%0/3
$$_{'type'} eq 'swap' && !($$_{'opts'} =~ /noauto/)
!ll&&!rl&&r
000
MC/DC0%0/2
$$_{'type'} eq 'swap' && !($$_{'opts'} =~ /noauto/)
$$_{'type'} eq 'swap' !($$_{'opts'} =~ /noauto/)
Truth table0%0/3
A && not(B)
A= $$_{'type'} eq 'swap'B= !($$_{'opts'} =~ /noauto/)
ABresult
0X0
100
111
735 2 my @o;
736 2 my $ok = 1;
737 2 for my $t (@targets) {
738 2 my ( $c, $e ) = _bd( $dev, $t );
739 2 my ( $name, $size, $sig );
740 0 ▶ if ($e) { ( $name, $size, $sig ) = ( $c, $e->{size}, ( $e->{fstype} // '' ) eq 'swap' ) }
Branch: 1 branch
BranchTrueFalseTotal
if ($e) { } 0 2 2
Condition0%0/2
$$e{"fstype"} // ""
l!l
00
MC/DC0%0/1
$$e{"fstype"} // ""
$$e{"fstype"}
Truth table0%0/2
A
A= $$e{"fstype"}
Aresult
11
00
741 else {
742 2 my $f = $abs->($t);
743 2 ▶ my $fe = ( $dev->{files} || {} )->{$f};
Condition50%1/2
$$dev{'files'} || {}
l!l
20
MC/DC0%0/1
$$dev{'files'} || {}
$$dev{'files'}
Truth table50%1/2
A
A= $$dev{'files'}
Aresult
11
00
744 0 ▶ if ( ref $fe ne 'HASH' ) { push @o, "swapon: cannot open $t: No such file or directory"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fe ne "HASH") 0 2 2
745 2 ▶ push @o, "swapon: $f: insecure permissions " . ( $fe->{mode} // '0644' ) . ", 0600 suggested." if ( $fe->{mode} // '0644' ) ne '0600';
Branch: 1 branch
BranchTrueFalseTotal
if ($$fe{"mode"} // "0644") ne "0600" 1 1 2
Condition50%2/4
$$fe{"mode"} // "0644"
l!l
20
$$fe{"mode"} // "0644"
l!l
10
MC/DC0%0/1
$$fe{"mode"} // "0644"
$$fe{"mode"}
MC/DC0%0/1
$$fe{"mode"} // "0644"
$$fe{"mode"}
Truth table50%1/2
A
A= $$fe{"mode"}
Aresult
11
00
Truth table50%1/2
A
A= $$fe{"mode"}
Aresult
11
00
746 2 ( $name, $size, $sig ) = ( $f, $fe->{size}, $fe->{swap} );
747 }
748 0 ▶ next if grep { $_->{name} eq $name } @{ $s->{swaps} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if grep {$$_{"name"} eq $name;} @{$$s{"swaps"} or [];} 0 2 2
Condition50%1/2
$$s{'swaps'} || []
l!l
02
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table50%1/2
A
A= $$s{'swaps'}
Aresult
11
00
749 2 ▶ if ( !$sig ) { push @o, "swapon: $name: read swap header failed"; $ok = 0; next }
Branch: 1 branch
BranchTrueFalseTotal
unless ($sig) 1 1 2
750 1 push @{ $s->{swaps} }, { name => $name, size => _h( _b($size) ) };
751 }
752 2 return ( join( "\n", @o ), $ok );
753 }
754 0 ▶ if ( $prog eq 'swapoff' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "swapoff") 0 0 0
755 0 my @t = grep { $_ ne '-a' } @pos;
756 0 ▶ if ( grep { $_ eq '-a' } @a ) { delete $s->{swaps}; return ( '', 1 ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-a";} @a) 0 0 0
757 0 for my $t (@t) {
758 0 ▶ my $n = canon( $dev, $t ) // $abs->($t);
Condition0%0/3
canon($dev, $t) // &$abs($t)
l!l&&r!l&&!r
000
MC/DC0%0/2
canon($dev, $t) // &$abs($t)
canon($dev, $t) &$abs($t)
Truth table0%0/3
A // B
A= canon($dev, $t)B= &$abs($t)
ABresult
1X1
011
000
759 0 ▶ my @k = grep { $_->{name} ne $n } @{ $s->{swaps} || [] };
Condition0%0/2
$$s{'swaps'} || []
l!l
00
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table0%0/2
A
A= $$s{'swaps'}
Aresult
11
00
760 0 ▶ return ( "swapoff: $t: swapoff failed: Invalid argument", 0 ) if @k == @{ $s->{swaps} || [] };
Branch: 1 branch
BranchTrueFalseTotal
if @k == @{$$s{"swaps"} or [];} 0 0 0
Condition0%0/2
$$s{'swaps'} || []
l!l
00
MC/DC0%0/1
$$s{'swaps'} || []
$$s{'swaps'}
Truth table0%0/2
A
A= $$s{'swaps'}
Aresult
11
00
761 0 $s->{swaps} = \@k;
762 }
763 0 return ( '', 1 );
764 }
765 0 return ( '', 0 );
766 }
767  
768 # --- Partitionen -------------------------------------------------------------------
769  
770  
771 4 ▶sub part {
Subroutine part: called CC=41 SCAR=56.0
Pod documented
772 4 my ( $dev, $av, $ctx, $prog ) = @_;
773 4 my $s = _st($dev);
774 4 ▶ my $d = $s->{disks} ||= {};
Condition50%1/2
$$s{"disks"} ||= {}
l!l
40
MC/DC0%0/1
$$s{"disks"} ||= {}
$$s{"disks"}
Truth table50%1/2
A
A= $$s{"disks"}
Aresult
11
00
775 4 my @a = @$av;
776 4 my @pos = grep { !/\A-/ } @a;
777 4 ▶ return ( '', 1 ) if $prog eq 'partprobe';
Branch: 1 branch
BranchTrueFalseTotal
if $prog eq "partprobe" 0 4 4
778 4 ▶ if ( $prog eq 'fdisk' ) { # nur fdisk -l; interaktiv ist eine Luecke der Simulation
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "fdisk") 0 4 4
779 0 ▶ unless ( grep { $_ eq '-l' || $_ eq '--list' } @a ) { push @Langertha::Holmgang::Sim::Linux::GAPS, join( ' ', 'fdisk', @a ); return ( '', 0 ) }
Branch: 1 branch
BranchTrueFalseTotal
unless (grep {$_ eq "-l" or $_ eq "--list";} @a) 0 0 0
Condition0%0/3
$_ eq '-l' || $_ eq '--list'
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq '-l' || $_ eq '--list'
$_ eq '-l' $_ eq '--list'
Truth table0%0/3
A || B
A= $_ eq '-l'B= $_ eq '--list'
ABresult
1X1
011
000
780 0 ▶ my @disks = @pos ? map { canon( $dev, $_ ) // () } @pos : grep { !$d->{$_}{parent} } sort keys %$d;
Branch: 1 branch
BranchTrueFalseTotal
@pos ? : 0 0 0
Condition0%0/3
canon($dev, $_) // ()
l!l&&r!l&&!r
000
MC/DC0%0/2
canon($dev, $_) // ()
canon($dev, $_) ()
Truth table0%0/3
A // B
A= canon($dev, $_)B= ()
ABresult
1X1
011
000
781 0 my @l;
782 0 for my $k (@disks) {
783 0 my $bytes = _b( $d->{$k}{size} );
784 0 push @l, sprintf( 'Disk %s: %s, %d bytes, %d sectors', $k, _gib($bytes), $bytes, $bytes / 512 ), 'Units: sectors of 1 * 512 = 512 bytes',
785 'Sector size (logical/physical): 512 bytes / 512 bytes', 'Disklabel type: gpt', '';
786 0 my @p = _parts( $dev, $k );
787 0 ▶ next unless @p;
Branch: 1 branch
BranchTrueFalseTotal
unless @p 0 0 0
788 0 push @l, sprintf( '%-12s %10s %10s %10s %5s %s', qw( Device Start End Sectors Size Type ) );
789 0 ▶ my $pos = sub { $d->{ $_[0] }{start} // ( $_[0] =~ /(\d+)\z/ )[0] };
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/3
$$d{$_[0]}{"start"} // ($_[0] =~ /(\d+)\z/)[0]
l!l&&r!l&&!r
000
MC/DC0%0/2
$$d{$_[0]}{"start"} // ($_[0] =~ /(\d+)\z/)[0]
$$d{$_[0]}{"start"} ($_[0] =~ /(\d+)\z/)[0]
Truth table0%0/3
A // B
A= $$d{$_[0]}{"start"}B= ($_[0] =~ /(\d+)\z/)[0]
ABresult
1X1
011
000
790 0 my $start = 2048;
791 0 for my $p ( sort { $pos->($a) <=> $pos->($b) } @p ) {
792 0 my $sec = int( _b( $d->{$p}{size} ) / 512 );
793 push @l, sprintf( '%-12s %10d %10d %10d %5s %s', $p, $start, $start + $sec - 1, $sec, _h( _b( $d->{$p}{size} ) ),
794 0 ▶ ( $d->{$p}{fstype} // '' ) eq 'vfat' ? 'EFI System' : ( $d->{$p}{fstype} // '' ) eq 'LVM2_member' ? 'Linux LVM' : 'Linux filesystem' );
Branch: 2 branches
BranchTrueFalseTotal
($$d{$p}{'fstype'} // '') eq 'vfat' ? : 0 0 0
($$d{$p}{'fstype'} // '') eq 'LVM2_member' ? : 0 0 0
Condition0%0/4
$$d{$p}{"fstype"} // ""
l!l
00
$$d{$p}{"fstype"} // ""
l!l
00
MC/DC0%0/1
$$d{$p}{"fstype"} // ""
$$d{$p}{"fstype"}
MC/DC0%0/1
$$d{$p}{"fstype"} // ""
$$d{$p}{"fstype"}
Truth table0%0/2
A
A= $$d{$p}{"fstype"}
Aresult
11
00
Truth table0%0/2
A
A= $$d{$p}{"fstype"}
Aresult
11
00
795 0 $start += $sec;
796 }
797 0 push @l, '';
798 }
799 0 return ( join( "\n", @l ) =~ s/\n+\z//r, 1 );
800 }
801 4 ▶ my $pname = sub { my ( $disk, $n ) = @_; return $disk =~ /\d\z/ ? "${disk}p$n" : "$disk$n" };
Subroutine __ANON__: called CC=2 SCAR=7.1
Branch: 1 branch
BranchTrueFalseTotal
$disk =~ /\d\z/ ? : 0 4 4
802 1 ▶ my $copy = sub {
Subroutine __ANON__: called CC=13 SCAR=29.1
803 1 my ( $from, $to ) = @_;
804 1 ▶ return ( "sfdisk: cannot open $to: No such file or directory", 0 ) unless $d->{$to} && !$d->{$to}{parent};
Branch: 1 branch
BranchTrueFalseTotal
unless $$d{$to} and not $$d{$to}{"parent"} 0 1 1
Condition33%1/3
$$d{$to} and not $$d{$to}{"parent"}
!ll&&!rl&&r
001
MC/DC0%0/2
$$d{$to} and not $$d{$to}{"parent"}
$$d{$to} not $$d{$to}{"parent"}
Truth table33%1/3
A and not(B)
A= $$d{$to}B= not $$d{$to}{"parent"}
ABresult
0X0
100
111
805 return ( "This disk is currently in use - repartitioning is probably a bad idea.\nUmount all file systems, and swapoff all swap partitions on this disk.\nUse the --no-reread flag to suppress this check.\nsfdisk: Use the --force flag to overrule all checks.", 0 )
806 1 ▶ if grep { _mounted_at( $dev, $_ ) || _vg_of_pv( $dev, $_ ) || grep { ( $_->{members}{$_} // '' ) eq 'active' } values %{ $s->{md} || {} } } $to, _parts( $dev, $to );
Branch: 1 branch
BranchTrueFalseTotal
if grep {_mounted_at($dev, $_) or _vg_of_pv($dev, $_) or grep {($$_{"members"}{$_} // "") eq "active";} values %{$$s{"md"} or {};};} $to, _parts($dev, $to) 0 1 1
Condition40%4/10
_mounted_at($dev, $_) || _vg_of_pv($dev, $_) || grep({($$_{'members'}{$_} // '') eq 'active';} values %{$$s{'md'} or {};})
l!l&&r!l&&!r
001
_mounted_at($dev, $_) or _vg_of_pv($dev, $_)
l!l&&r!l&&!r
001
$$_{"members"}{$_} // ""
l!l
01
$$s{'md'} || {}
l!l
10
MC/DC0%0/3
_mounted_at($dev, $_) || _vg_of_pv($dev, $_) || grep({($$_{'members'}{$_} // '') eq 'active';} values %{$$s{'md'} or {};})
_mounted_at($dev, $_) _vg_of_pv($dev, $_) grep({($$_{'members'}{$_} // '') eq 'active';} values %{$$s{'md'} or {};})
MC/DC0%0/1
$$_{"members"}{$_} // ""
$$_{"members"}{$_}
MC/DC0%0/1
$$s{'md'} || {}
$$s{'md'}
Truth table25%1/4
A or B || C
A= _mounted_at($dev, $_)B= _vg_of_pv($dev, $_)C= grep({($$_{'members'}{$_} // '') eq 'active';} values %{$$s{'md'} or {};})
ABCresult
1XX1
01X1
0011
0000
Truth table50%1/2
A
A= $$_{"members"}{$_}
Aresult
11
00
Truth table50%1/2
A
A= $$s{'md'}
Aresult
11
00
807 1 my @src = _parts( $dev, $from );
808 1 my $need = 0;
809 1 $need += _b( $d->{$_}{size} ) for @src;
810 1 ▶ return ( "sfdisk: failed to add #1 partition: Numerical result out of range", 0 ) if $need > _b( $d->{$to}{size} );
Branch: 1 branch
BranchTrueFalseTotal
if $need > _b($$d{$to}{"size"}) 0 1 1
811 1 delete $d->{$_} for _parts( $dev, $to );
812 1 for my $p (@src) {
813 1 my ($n) = $p =~ /(\d+)\z/;
814 1 ▶ $d->{ $pname->( $to, $n ) } = { size => $d->{$p}{size}, parent => $to, ( defined $d->{$p}{ptype} ? ( ptype => $d->{$p}{ptype} ) : () ) };
Branch: 1 branch
BranchTrueFalseTotal
defined $$d{$p}{'ptype'} ? : 1 0 1
815 }
816 1 delete $d->{$to}{fstype};
817 1 return ( "Checking that no-one is using this disk right now ... OK\n\n>>> Script header accepted.\nNew situation:\n" . join( "\n", map { $pname->( $to, ( $_ =~ /(\d+)\z/ )[0] ) . " " . $d->{$_}{size} } @src )
818 . "\n\nThe partition table has been altered.\nSyncing disks.", 1 );
819 4 };
820 4 ▶ if ( $prog eq 'sfdisk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "sfdisk") 2 2 4
821 2 ▶ if ( grep { $_ eq '-d' || $_ eq '--dump' } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-d" or $_ eq "--dump";} @a) 1 1 2
Condition66%2/3
$_ eq '-d' || $_ eq '--dump'
l!l&&r!l&&!r
102
MC/DC50%1/2
$_ eq '-d' || $_ eq '--dump'
$_ eq '-d' $_ eq '--dump'
Truth table66%2/3
A || B
A= $_ eq '-d'B= $_ eq '--dump'
ABresult
1X1
011
000
822 1 ▶ my $disk = $pos[0] // return ( 'sfdisk: no disk device specified', 0 );
Condition50%1/2
$pos[0] // (return "sfdisk: no disk device specified", 0)
l!l
10
MC/DC0%0/1
$pos[0] // (return "sfdisk: no disk device specified", 0)
$pos[0]
Truth table50%1/2
A
A= $pos[0]
Aresult
11
00
823 1 ▶ return ( "sfdisk: cannot open $disk: No such file or directory", 0 ) unless $d->{$disk};
Branch: 1 branch
BranchTrueFalseTotal
unless $$d{$disk} 0 1 1
824 1 my @p = _parts( $dev, $disk );
825 1 my $start = 2048;
826 1 my @l = ( 'label: dos', 'label-id: 0x5d1e2c3f', "device: $disk", 'unit: sectors', 'sector-size: 512', '' );
827 1 for my $p (@p) {
828 1 my $sec = int( _b( $d->{$p}{size} ) / 512 );
829 1 ▶ push @l, "$p : start=$start, size=$sec, type=" . ( $d->{$p}{ptype} // '83' );
Condition50%1/2
$$d{$p}{"ptype"} // 83
l!l
10
MC/DC0%0/1
$$d{$p}{"ptype"} // 83
$$d{$p}{"ptype"}
Truth table50%1/2
A
A= $$d{$p}{"ptype"}
Aresult
11
00
830 1 $start += $sec;
831 }
832 1 return ( join( "\n", @l ), 1 );
833 }
834 1 ▶ my $stdin = $ctx->{stdin} // '';
Condition50%1/2
$$ctx{"stdin"} // ""
l!l
10
MC/DC0%0/1
$$ctx{"stdin"} // ""
$$ctx{"stdin"}
Truth table50%1/2
A
A= $$ctx{"stdin"}
Aresult
11
00
835 1 my ($from) = $stdin =~ /^device:\s*(\S+)/m;
836 1 my $to = $pos[0];
837 1 ▶ return ( 'sfdisk: no disk device specified', 0 ) unless defined $to;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 1 1
838 1 ▶ return ( "sfdisk: failed to read script", 0 ) unless defined $from && $d->{$from};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from and $$d{$from} 0 1 1
Condition33%1/3
defined $from and $$d{$from}
!ll&&!rl&&r
001
MC/DC0%0/2
defined $from and $$d{$from}
defined $from $$d{$from}
Truth table33%1/3
A and B
A= defined $fromB= $$d{$from}
ABresult
0X0
100
111
839 1 return $copy->( $from, $to );
840 }
841 2 ▶ if ( $prog eq 'sgdisk' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "sgdisk") 0 2 2
842 0 my $j = join ' ', @a;
843 0 ▶ return ( 'The operation has completed successfully.', 1 ) if $j =~ /(?:\A|\s)(?:-G|--randomize-guids)\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $j =~ /(?:\A|\s)(?:-G|--randomize-guids)\b/ 0 0 0
844 0 ▶ if ( my ($to) = $j =~ /(?:-R|--replicate)[= ]?(\S+)/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my($to) = $j =~ /(?:-R|--replicate)[= ]?(\S+)/) 0 0 0
845 0 ▶ my ($from) = grep { $_ ne $to && $d->{$_} } @pos;
Condition0%0/3
$_ ne $to && $$d{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
$_ ne $to && $$d{$_}
$_ ne $to $$d{$_}
Truth table0%0/3
A && B
A= $_ ne $toB= $$d{$_}
ABresult
0X0
100
111
846 0 ▶ return ( 'Problem opening for reading!', 0 ) unless defined $from;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from 0 0 0
847 0 my ( $o, $ok ) = $copy->( $from, $to );
848 0 ▶ return ( $ok ? 'The operation has completed successfully.' : $o, $ok );
Branch: 1 branch
BranchTrueFalseTotal
$ok ? : 0 0 0
849 }
850 0 ▶ if ( grep { $_ eq '-p' || $_ eq '--print' } @a ) { return lsblk( $dev, [ $pos[0] ] ) }
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "-p" or $_ eq "--print";} @a) 0 0 0
Condition0%0/3
$_ eq '-p' || $_ eq '--print'
l!l&&r!l&&!r
000
MC/DC0%0/2
$_ eq '-p' || $_ eq '--print'
$_ eq '-p' $_ eq '--print'
Truth table0%0/3
A || B
A= $_ eq '-p'B= $_ eq '--print'
ABresult
1X1
011
000
851 0 return ( '', 0 );
852 }
853 2 ▶ if ( $prog eq 'growpart' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($prog eq "growpart") 2 0 2
854 2 my ( $disk, $n ) = @pos;
855 2 ▶ return ( 'usage: growpart disk partition', 0 ) unless defined $n;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $n 0 2 2
856 2 my $p = $pname->( $disk, $n );
857 2 ▶ return ( "FAILED: $disk: does not exist", 0 ) unless $d->{$disk};
Branch: 1 branch
BranchTrueFalseTotal
unless $$d{$disk} 0 2 2
858 2 ▶ return ( "FAILED: partition $n does not exist", 0 ) unless $d->{$p};
Branch: 1 branch
BranchTrueFalseTotal
unless $$d{$p} 0 2 2
859 2 my @p = _parts( $dev, $disk );
860 2 my $used = 0;
861 2 $used += _b( $d->{$_}{size} ) for @p;
862 2 my $free = _b( $d->{$disk}{size} ) - $used - 1024**2;
863 # die physisch letzte Partition (start, sonst die Nummer; Cloud-Abbilder haben z. B. 15 vorn)
864 2 ▶ my $pos = sub { $d->{ $_[0] }{start} // ( $_[0] =~ /(\d+)\z/ )[0] };
Subroutine __ANON__: called CC=2 SCAR=8.1
Condition33%1/3
$$d{$_[0]}{"start"} // ($_[0] =~ /(\d+)\z/)[0]
l!l&&r!l&&!r
040
MC/DC0%0/2
$$d{$_[0]}{"start"} // ($_[0] =~ /(\d+)\z/)[0]
$$d{$_[0]}{"start"} ($_[0] =~ /(\d+)\z/)[0]
Truth table33%1/3
A // B
A= $$d{$_[0]}{"start"}B= ($_[0] =~ /(\d+)\z/)[0]
ABresult
1X1
011
000
865 2 my ($last) = sort { $pos->($b) <=> $pos->($a) } @p;
866 2 ▶ return ( "NOCHANGE: partition $n is size " . int( _b( $d->{$p}{size} ) / 512 ) . ". it cannot be grown", 0 ) if $free <= 0 || $last ne $p;
Branch: 1 branch
BranchTrueFalseTotal
if $free <= 0 or $last ne $p 1 1 2
Condition66%2/3
$free <= 0 or $last ne $p
l!l&&r!l&&!r
101
MC/DC50%1/2
$free <= 0 or $last ne $p
$free <= 0 $last ne $p
Truth table66%2/3
A or B
A= $free <= 0B= $last ne $p
ABresult
1X1
011
000
867 1 my $old = _b( $d->{$p}{size} );
868 1 $d->{$p}{size} = _h( $old + $free + 1024**2 );
869 1 return ( "CHANGED: partition=$n start=2048 old: size=" . int( $old / 512 ) . " end=" . int( $old / 512 + 2048 ) . " new: size=" . int( _b( $d->{$p}{size} ) / 512 ) . " end=" . int( _b( $d->{$p}{size} ) / 512 + 2048 ), 1 );
870 }
871 0 return ( '', 0 );
872 }
873  
874 # --- mdadm -------------------------------------------------------------------------
875  
876 1 ▶sub _mdstat {
Subroutine _mdstat: called CC=7 SCAR=19.8
877 1 my ($dev) = @_;
878 1 ▶ my $md = _st($dev)->{md} || {};
Condition50%1/2
_st($dev)->{'md'} || {}
l!l
10
MC/DC0%0/1
_st($dev)->{'md'} || {}
_st($dev)->{'md'}
Truth table50%1/2
A
A= _st($dev)->{'md'}
Aresult
11
00
879 1 my @l = ('Personalities : [raid1] [linear] [multipath] [raid0] [raid6] [raid5] [raid4] [raid10]');
880 1 for my $n ( sort keys %$md ) {
881 1 my $m = $md->{$n};
882 1 ▶ my $mem = $m->{members} || {};
Condition50%1/2
$$m{'members'} || {}
l!l
10
MC/DC0%0/1
$$m{'members'} || {}
$$m{'members'}
Truth table50%1/2
A
A= $$m{'members'}
Aresult
11
00
883 1 my $i = 0;
884 1 ▶ my @parts = map { ( my $x = $_ ) =~ s{\A/dev/}{}; $x . '[' . $i++ . ']' . ( $mem->{$_} eq 'faulty' ? '(F)' : $mem->{$_} eq 'spare' ? '(S)' : '' ) } sort keys %$mem;
Branch: 2 branches
BranchTrueFalseTotal
$$mem{$_} eq 'faulty' ? : 0 2 2
$$mem{$_} eq 'spare' ? : 0 2 2
885 1 my $act = grep { $mem->{$_} eq 'active' } keys %$mem;
886 1 my $reb = grep { $mem->{$_} eq 'rebuilding' } keys %$mem;
887 1 ( my $short = $n ) =~ s{\A/dev/}{};
888 push @l, "$short : active $m->{level} @parts", sprintf( ' %d blocks super 1.2 [%d/%d] [%s]', int( _b( $m->{size} ) / 1024 ), $m->{raid_disks}, $act,
889 1 join( '', ('U') x $act, ('_') x ( $m->{raid_disks} - $act ) ) );
890 1 ▶ push @l, ' [=>...................] recovery = 8.4% (3290112/39062464) finish=12.3min speed=48412K/sec' if $reb;
Branch: 1 branch
BranchTrueFalseTotal
if $reb 1 0 1
891 1 push @l, '';
892 }
893 1 push @l, 'unused devices: <none>';
894 1 return join "\n", @l;
895 }
896  
897  
898  
899 1 ▶sub mdstat { return _mdstat( $_[0] ) }
Subroutine mdstat: called CC=1 SCAR=0.0
Pod documented
900  
901 4 ▶sub mdadm {
Subroutine mdadm: called CC=40 SCAR=55.9
Pod documented
902 4 my ( $dev, $av ) = @_;
903 4 my $s = _st($dev);
904 4 my @a = grep { $_ ne '--manage' } @$av;
905 4 ▶ if ( grep { $_ eq '--detail' || $_ eq '-D' } @a ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_ eq "--detail" or $_ eq "-D";} @a) 0 4 4
Condition33%1/3
$_ eq '--detail' || $_ eq '-D'
l!l&&r!l&&!r
0012
MC/DC0%0/2
$_ eq '--detail' || $_ eq '-D'
$_ eq '--detail' $_ eq '-D'
Truth table33%1/3
A || B
A= $_ eq '--detail'B= $_ eq '-D'
ABresult
1X1
011
000
906 0 my ($n) = grep { !/\A-/ } @a;
907 0 ▶ my $m = ( $s->{md} || {} )->{ $n // '' } or return ( "mdadm: cannot open " . ( $n // '' ) . ": No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $m = ($$s{"md"} || {})->{$n // ""} or return 'mdadm: cannot open ' . ($n // "") . ': No such file or directory', 0 0 0 0
Condition0%0/6
$$s{'md'} || {}
l!l
00
$n // ""
l!l
00
$n // ""
l!l
00
MC/DC0%0/1
$$s{'md'} || {}
$$s{'md'}
MC/DC0%0/1
$n // ""
$n
MC/DC0%0/1
$n // ""
$n
Truth table0%0/2
A
A= $$s{'md'}
Aresult
11
00
Truth table0%0/2
A
A= $n
Aresult
11
00
Truth table0%0/2
A
A= $n
Aresult
11
00
908 0 ▶ my $mem = $m->{members} || {};
Condition0%0/2
$$m{'members'} || {}
l!l
00
MC/DC0%0/1
$$m{'members'} || {}
$$m{'members'}
Truth table0%0/2
A
A= $$m{'members'}
Aresult
11
00
909 0 my $act = grep { $mem->{$_} eq 'active' } keys %$mem;
910 0 ▶ my $state = $act == $m->{raid_disks} ? 'clean' : ( grep { $mem->{$_} eq 'rebuilding' } keys %$mem ) ? 'clean, degraded, recovering' : 'clean, degraded';
Branch: 2 branches
BranchTrueFalseTotal
$act == $$m{'raid_disks'} ? : 0 0 0
grep({$$mem{$_} eq 'rebuilding';} keys %$mem) ? : 0 0 0
911 0 my $i = 0;
912 return ( join( "\n", "$n:", ' Version : 1.2', " Raid Level : $m->{level}", ' Array Size : ' . int( _b( $m->{size} ) / 1024 ),
913 " Raid Devices : $m->{raid_disks}", ' Total Devices : ' . scalar( keys %$mem ), " State : $state", " Active Devices : $act",
914 '', ' Number Major Minor RaidDevice State',
915 0 map { sprintf( ' %d 8 %2d %s %s %s', $i, $i * 16 + 1, $mem->{$_} eq 'active' ? $i++ : '-',
916 0 ▶ { active => 'active sync', faulty => 'faulty', spare => 'spare', rebuilding => 'spare rebuilding' }->{ $mem->{$_} } // $mem->{$_}, $_ ) } sort keys %$mem ), 1 );
Branch: 1 branch
BranchTrueFalseTotal
$$mem{$_} eq 'active' ? : 0 0 0
Condition0%0/3
{"active", "active sync", "faulty", "faulty", "spare", "spare", "rebuilding", "spare rebuilding"}->{$$mem{$_}} // $$mem{$_}
l!l&&r!l&&!r
000
MC/DC0%0/2
{"active", "active sync", "faulty", "faulty", "spare", "spare", "rebuilding", "spare rebuilding"}->{$$mem{$_}} // $$mem{$_}
{"active", "active sync", "faulty", "faulty", "spare", "spare", "rebuilding", "spare rebuilding"}->{$$mem{$_}} $$mem{$_}
Truth table0%0/3
A // B
A= {"active", "active sync", "faulty", "faulty", "spare", "spare", "rebuilding", "spare rebuilding"}->{$$mem{$_}}B= $$mem{$_}
ABresult
1X1
011
000
917 }
918 4 my ($n) = grep { m{\A/dev/md} } @a;
919 4 ▶ my $m = ( $s->{md} || {} )->{ $n // '' } or return ( "mdadm: error opening " . ( $n // '' ) . ": No such file or directory", 0 );
Branch: 1 branch
BranchTrueFalseTotal
my $m = ($$s{"md"} || {})->{$n // ""} or return 'mdadm: error opening ' . ($n // "") . ': No such file or directory', 0 4 0 4
Condition33%2/6
$$s{'md'} || {}
l!l
40
$n // ""
l!l
40
$n // ""
l!l
00
MC/DC0%0/1
$$s{'md'} || {}
$$s{'md'}
MC/DC0%0/1
$n // ""
$n
MC/DC0%0/1
$n // ""
$n
Truth table50%1/2
A
A= $$s{'md'}
Aresult
11
00
Truth table50%1/2
A
A= $n
Aresult
11
00
Truth table0%0/2
A
A= $n
Aresult
11
00
920 4 my @w = grep { $_ ne $n } @a;
921 4 my @o;
922 4 ▶ while (@w) {
Branch: 1 branch
BranchTrueFalseTotal
if (@w) 4 2 6
923 4 my $op = shift @w;
924 4 ▶ my $d = shift @w // return ( "mdadm: No devices given.", 0 );
Condition50%1/2
shift @w // (return "mdadm: No devices given.", 0)
l!l
40
MC/DC0%0/1
shift @w // (return "mdadm: No devices given.", 0)
shift @w
Truth table50%1/2
A
A= shift @w
Aresult
11
00
925 4 ▶ my $mem = $m->{members} ||= {};
Condition50%1/2
$$m{"members"} ||= {}
l!l
40
MC/DC0%0/1
$$m{"members"} ||= {}
$$m{"members"}
Truth table50%1/2
A
A= $$m{"members"}
Aresult
11
00
926 4 ▶ if ( $op eq '--fail' || $op eq '-f' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($op eq '--fail' or $op eq '-f') { } 0 4 4
elsif ($op eq '--remove' or $op eq '-r') { } 2 2 4
elsif ($op eq '--add' or $op eq '-a' or $op eq '--re-add') { } 2 0 2
Condition33%1/3
$op eq "--fail" or $op eq "-f"
l!l&&r!l&&!r
004
MC/DC0%0/2
$op eq "--fail" or $op eq "-f"
$op eq "--fail" $op eq "-f"
Truth table33%1/3
A or B
A= $op eq "--fail"B= $op eq "-f"
ABresult
1X1
011
000
927 0 ▶ return ( "mdadm: set device faulty failed for $d: No such device", 0 ) unless exists $mem->{$d};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$mem{$d} 0 0 0
928 0 $mem->{$d} = 'faulty';
929 0 push @o, "mdadm: set $d faulty in $n";
930 }
931 ▶ elsif ( $op eq '--remove' || $op eq '-r' ) {
Condition66%2/3
$op eq "--remove" or $op eq "-r"
l!l&&r!l&&!r
202
MC/DC50%1/2
$op eq "--remove" or $op eq "-r"
$op eq "--remove" $op eq "-r"
Truth table66%2/3
A or B
A= $op eq "--remove"B= $op eq "-r"
ABresult
1X1
011
000
932 2 ▶ return ( "mdadm: hot remove failed for $d: No such device or address", 0 ) unless exists $mem->{$d};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $$mem{$d} 0 2 2
933 2 ▶ return ( "mdadm: hot remove failed for $d: Device or resource busy", 0 ) if $mem->{$d} eq 'active' || $mem->{$d} eq 'rebuilding';
Branch: 1 branch
BranchTrueFalseTotal
if $$mem{$d} eq "active" or $$mem{$d} eq "rebuilding" 1 1 2
Condition66%2/3
$$mem{$d} eq "active" or $$mem{$d} eq "rebuilding"
l!l&&r!l&&!r
101
MC/DC50%1/2
$$mem{$d} eq "active" or $$mem{$d} eq "rebuilding"
$$mem{$d} eq "active" $$mem{$d} eq "rebuilding"
Truth table66%2/3
A or B
A= $$mem{$d} eq "active"B= $$mem{$d} eq "rebuilding"
ABresult
1X1
011
000
934 1 delete $mem->{$d};
935 1 push @o, "mdadm: hot removed $d from $n";
936 }
937 ▶ elsif ( $op eq '--add' || $op eq '-a' || $op eq '--re-add' ) {
Condition33%2/6
$op eq "--add" or $op eq "-a" or $op eq "--re-add"
l!l&&r!l&&!r
200
$op eq "--add" or $op eq "-a"
l!l&&r!l&&!r
200
MC/DC0%0/3
$op eq "--add" or $op eq "-a" or $op eq "--re-add"
$op eq "--add" $op eq "-a" $op eq "--re-add"
Truth table25%1/4
A or B or C
A= $op eq "--add"B= $op eq "-a"C= $op eq "--re-add"
ABCresult
1XX1
01X1
0011
0000
938 2 my ( $c, $e ) = _bd( $dev, $d );
939 2 ▶ return ( "mdadm: cannot find $d: No such file or directory", 0 ) unless $e;
Branch: 1 branch
BranchTrueFalseTotal
unless $e 1 1 2
940 1 ▶ return ( "mdadm: $d is already a member of $n", 0 ) if exists $mem->{$d};
Branch: 1 branch
BranchTrueFalseTotal
if exists $$mem{$d} 0 1 1
941 0 ▶ return ( "mdadm: Cannot open $d: Device or resource busy", 0 ) if _mounted_at( $dev, $c ) || _vg_of_pv( $dev, $c ) || _parts( $dev, $c ) && grep { _mounted_at( $dev, $_ ) } _parts( $dev, $c );
Branch: 1 branch
BranchTrueFalseTotal
if _mounted_at($dev, $c) or _vg_of_pv($dev, $c) or _parts($dev, $c) and grep {_mounted_at($dev, $_);} _parts($dev, $c) 0 1 1
Condition33%3/9
_mounted_at($dev, $c) or _vg_of_pv($dev, $c) or _parts($dev, $c) and grep {_mounted_at($dev, $_);} _parts($dev, $c)
l!l&&r!l&&!r
001
_mounted_at($dev, $c) or _vg_of_pv($dev, $c)
l!l&&r!l&&!r
001
_parts($dev, $c) and grep {_mounted_at($dev, $_);} _parts($dev, $c)
!ll&&!rl&&r
100
MC/DC0%0/4
_mounted_at($dev, $c) or _vg_of_pv($dev, $c) or _parts($dev, $c) and grep {_mounted_at($dev, $_);} _parts($dev, $c)
_mounted_at($dev, $c) _vg_of_pv($dev, $c) _parts($dev, $c) grep {_mounted_at($dev, $_);} _parts($dev, $c)
Truth table20%1/5
A or B or C and D
A= _mounted_at($dev, $c)B= _vg_of_pv($dev, $c)C= _parts($dev, $c)D= grep {_mounted_at($dev, $_);} _parts($dev, $c)
ABCDresult
1XXX1
01XX1
00111
000X0
00100
942 1 ▶ return ( "mdadm: $d not large enough to join array", 0 ) if _b( $e->{size} ) < _b( $m->{member_size} // $m->{size} );
Branch: 1 branch
BranchTrueFalseTotal
if _b($$e{"size"}) < _b($$m{"member_size"} // $$m{"size"}) 0 1 1
Condition33%1/3
$$m{"member_size"} // $$m{"size"}
l!l&&r!l&&!r
010
MC/DC0%0/2
$$m{"member_size"} // $$m{"size"}
$$m{"member_size"} $$m{"size"}
Truth table33%1/3
A // B
A= $$m{"member_size"}B= $$m{"size"}
ABresult
1X1
011
000
943 1 ▶ my $act = grep { $mem->{$_} eq 'active' || $mem->{$_} eq 'rebuilding' } keys %$mem;
Condition33%1/3
$$mem{$_} eq 'active' || $$mem{$_} eq 'rebuilding'
l!l&&r!l&&!r
100
MC/DC0%0/2
$$mem{$_} eq 'active' || $$mem{$_} eq 'rebuilding'
$$mem{$_} eq 'active' $$mem{$_} eq 'rebuilding'
Truth table33%1/3
A || B
A= $$mem{$_} eq 'active'B= $$mem{$_} eq 'rebuilding'
ABresult
1X1
011
000
944 1 ▶ $mem->{$c} = $act < $m->{raid_disks} ? 'rebuilding' : 'spare';
Branch: 1 branch
BranchTrueFalseTotal
$act < $$m{'raid_disks'} ? : 1 0 1
945 1 $e->{fstype} = 'linux_raid_member';
946 1 push @o, "mdadm: added $c";
947 }
948 0 else { return ( "mdadm: unknown option $op", 0 ) }
949 }
950 2 return ( join( "\n", @o ), 1 );
951 }
952  
953 2 1;
954  
955 __END__
« blib/lib/Langertha/Holmgang/Sim/Linux/Http.pm ↑ Summary blib/lib/Langertha/Holmgang/Sim/Linux/Git.pm »