line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# |
4
|
|
|
|
|
|
|
# Copyright (c) 1998 Alan R. Barclay. All rights reserved. This program |
5
|
|
|
|
|
|
|
# is free software; you can redistribute it and/or modify it under |
6
|
|
|
|
|
|
|
# the same terms as Perl itself. |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Filesys::DiskFree; |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
2134
|
use Carp; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
111
|
|
11
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
#qw(); |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
5
|
use vars qw($VERSION $Format %Df); |
|
1
|
|
|
|
|
16
|
|
|
1
|
|
|
|
|
181
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
$VERSION = 0.06; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# |
20
|
|
|
|
|
|
|
# The format table |
21
|
|
|
|
|
|
|
# |
22
|
|
|
|
|
|
|
# Note, the format names are not gauranteed. If I find that there |
23
|
|
|
|
|
|
|
# is a reason to rename one, then they be renamed. |
24
|
|
|
|
|
|
|
# |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
%Df = ( |
27
|
|
|
|
|
|
|
'linux' => { |
28
|
|
|
|
|
|
|
'blocks' => "df -P", |
29
|
|
|
|
|
|
|
'inodes' => "df -Pi", |
30
|
|
|
|
|
|
|
'format' => "linuxish", |
31
|
|
|
|
|
|
|
}, |
32
|
|
|
|
|
|
|
'solaris' => { |
33
|
|
|
|
|
|
|
'blocks' => "df -k", |
34
|
|
|
|
|
|
|
'inodes' => "df -k -o i -F ufs", |
35
|
|
|
|
|
|
|
'format' => "svish", |
36
|
|
|
|
|
|
|
}, |
37
|
|
|
|
|
|
|
'bsdos' => { |
38
|
|
|
|
|
|
|
'blocks' => "df -i", |
39
|
|
|
|
|
|
|
'inodes' => "df -i", |
40
|
|
|
|
|
|
|
'format' => 'bsdish', |
41
|
|
|
|
|
|
|
}, |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
'irix' => { |
44
|
|
|
|
|
|
|
'blocks' => "df", |
45
|
|
|
|
|
|
|
'inodes' => "df -i", |
46
|
|
|
|
|
|
|
'format' => "irixish", |
47
|
|
|
|
|
|
|
}, |
48
|
|
|
|
|
|
|
'hpux' => { |
49
|
|
|
|
|
|
|
'blocks' => "bdf -l -i", |
50
|
|
|
|
|
|
|
'inodes' => "bdf -l -i", |
51
|
|
|
|
|
|
|
'format' => 'hpuxish', |
52
|
|
|
|
|
|
|
}, |
53
|
|
|
|
|
|
|
'dec_osf' => { |
54
|
|
|
|
|
|
|
'blocks' => "df", |
55
|
|
|
|
|
|
|
'inodes' => "df -i", |
56
|
|
|
|
|
|
|
'format' => 'svish', |
57
|
|
|
|
|
|
|
}, |
58
|
|
|
|
|
|
|
); |
59
|
|
|
|
|
|
|
|
60
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
33
|
|
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
BEGIN { |
63
|
1
|
|
|
1
|
|
8665
|
$Format = $^O; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub new { |
67
|
0
|
|
|
0
|
0
|
|
my $proto = shift; |
68
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
69
|
0
|
|
|
|
|
|
my $self = { |
70
|
|
|
|
|
|
|
FORMAT => $Format, |
71
|
|
|
|
|
|
|
DEVICES => undef, |
72
|
|
|
|
|
|
|
MOUNTS => undef, |
73
|
|
|
|
|
|
|
MODE => 'blocks' |
74
|
|
|
|
|
|
|
}; |
75
|
|
|
|
|
|
|
|
76
|
0
|
|
|
|
|
|
bless ($self, $class); |
77
|
0
|
|
|
|
|
|
return $self; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub set(){ |
81
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
82
|
0
|
|
|
|
|
|
my @return; |
83
|
|
|
|
|
|
|
|
84
|
0
|
0
|
|
|
|
|
return undef if(defined $self->{'DEVICES'}); |
85
|
|
|
|
|
|
|
|
86
|
0
|
0
|
|
|
|
|
if(@_){ |
87
|
0
|
0
|
|
|
|
|
if($_[0] =~ m/format/i){ |
88
|
0
|
|
|
|
|
|
push(@return,$self->{'FORMAT'}); |
89
|
0
|
0
|
|
|
|
|
$self->{'FORMAT'}=$_[1] if(defined $_[1]); |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
if($_[0] =~ m/mode/i){ |
93
|
0
|
|
|
|
|
|
push(@return,$self->{'MODE'}); |
94
|
0
|
0
|
0
|
|
|
|
$self->{'MODE'}='blocks' if($_[1] =~ m/block/i and defined $_[1]); |
95
|
0
|
0
|
0
|
|
|
|
$self->{'MODE'}='inodes' if($_[1] =~ m/inode/i and defined $_[1]); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
0
|
|
|
|
|
|
return @return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub command () { |
102
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
103
|
0
|
|
|
|
|
|
return $Df{"\L".$self->{'FORMAT'}."\E"}{$self->{'MODE'}}; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
sub df(){ |
106
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
107
|
0
|
|
|
|
|
|
my $cmd="df"; |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
$cmd=$self->command() or |
110
|
|
|
|
|
|
|
croak "No df command known for format ".$self->{'FORMAT'}; |
111
|
0
|
0
|
|
|
|
|
open(HANDLE,"$cmd|") or croak("Cannot fork $!"); |
112
|
0
|
|
|
|
|
|
return $self->load(\*HANDLE); |
113
|
0
|
0
|
|
|
|
|
close(HANDLE) or croak("Cannot df $!"); |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub load() { |
117
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
118
|
0
|
|
|
|
|
|
my $handle=shift; |
119
|
|
|
|
|
|
|
|
120
|
0
|
0
|
|
|
|
|
if(ref $handle eq "GLOB"){ |
121
|
0
|
|
|
|
|
|
while(<$handle>){ |
122
|
0
|
|
|
|
|
|
$self->readline($_); |
123
|
|
|
|
|
|
|
} |
124
|
|
|
|
|
|
|
} else { |
125
|
0
|
|
|
|
|
|
map { $self->readline($_) } split(/$\//,$handle); |
|
0
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
return 'true'; |
128
|
|
|
|
|
|
|
} |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
sub readline() { |
131
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
132
|
0
|
|
|
|
|
|
my $line=shift; |
133
|
0
|
|
|
|
|
|
my ($device,$btotal,$bused,$bavail,$iused,$iavail,$mount, |
134
|
|
|
|
|
|
|
$total,$used,$avail); |
135
|
|
|
|
|
|
|
|
136
|
0
|
|
|
|
|
|
chomp($line); |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$_=$Df{"\L".$self->{'FORMAT'}."\E"}{'format'}; |
139
|
|
|
|
|
|
|
|
140
|
0
|
0
|
|
|
|
|
if(/linuxish/i){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
141
|
0
|
0
|
|
|
|
|
return undef if($line =~ /^Filesystem.*Mounted on/i); |
142
|
0
|
|
|
|
|
|
($device,$total,$used,$avail,undef,$mount)=split(' ',$line); |
143
|
0
|
0
|
|
|
|
|
if($self->{'MODE'} eq 'blocks'){ |
144
|
0
|
|
|
|
|
|
$total *= 1024; |
145
|
0
|
|
|
|
|
|
$used *= 1024; |
146
|
0
|
|
|
|
|
|
$avail *= 1024; |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
} elsif(/svish/i){ |
149
|
0
|
0
|
|
|
|
|
return undef if($line =~ /^Filesystem.*Mounted on/i); |
150
|
0
|
0
|
|
|
|
|
if($self->{'MODE'} eq 'blocks'){ |
151
|
0
|
|
|
|
|
|
($device,$total,$used,$avail,undef,$mount)=split(' ',$line); |
152
|
0
|
|
|
|
|
|
$total *= 1024; |
153
|
0
|
|
|
|
|
|
$used *= 1024; |
154
|
0
|
|
|
|
|
|
$avail *= 1024; |
155
|
|
|
|
|
|
|
} else { |
156
|
0
|
|
|
|
|
|
($device,$used,$avail,undef,$mount)=split(' ',$line); |
157
|
0
|
|
|
|
|
|
$total=$used+$avail; |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
} elsif(/bsdish/){ |
160
|
0
|
0
|
|
|
|
|
return undef if($line =~ /^Filesystem.*Mounted on/i); |
161
|
0
|
|
|
|
|
|
($device,$btotal,$bused,$bavail,undef,$iused,$iavail,undef,$mount)= |
162
|
|
|
|
|
|
|
split(' ',$line); |
163
|
0
|
0
|
|
|
|
|
if($self->{'MODE'} eq 'blocks'){ |
|
|
0
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
$total=$btotal*512; |
165
|
0
|
|
|
|
|
|
$used=$bused*512; |
166
|
0
|
|
|
|
|
|
$avail=$bavail*512; |
167
|
|
|
|
|
|
|
} elsif($self->{'MODE'} eq 'inodes'){ |
168
|
0
|
|
|
|
|
|
$total=undef; |
169
|
0
|
|
|
|
|
|
$used=$iused*512; |
170
|
0
|
|
|
|
|
|
$avail=$iavail*512; |
171
|
|
|
|
|
|
|
} |
172
|
|
|
|
|
|
|
} elsif(/irixish/){ |
173
|
0
|
0
|
|
|
|
|
return undef if($line =~ /^Filesystem.*Mounted on/i); |
174
|
0
|
0
|
|
|
|
|
if($self->{'MODE'} eq 'blocks'){ |
|
|
0
|
|
|
|
|
|
175
|
0
|
|
|
|
|
|
($device,undef,$btotal,$bused,$bavail,undef,$mount)=split(' ',$line); |
176
|
0
|
|
|
|
|
|
$total=$btotal*512; |
177
|
0
|
|
|
|
|
|
$used=$bused*512; |
178
|
0
|
|
|
|
|
|
$avail=$bavail*512; |
179
|
|
|
|
|
|
|
} elsif($self->{'MODE'} eq 'inodes'){ |
180
|
0
|
|
|
|
|
|
($device,undef,$btotal,$bused,$bavail,undef,$iused,$iavail,undef,$mount)= |
181
|
|
|
|
|
|
|
split(' ',$line); |
182
|
0
|
0
|
0
|
|
|
|
return undef if $iused =~ /[A-Za-z]+/ or $iused == 0; |
183
|
0
|
|
|
|
|
|
$total = ($iused + $iavail) * 512; |
184
|
0
|
|
|
|
|
|
$used=$iused*512; |
185
|
0
|
|
|
|
|
|
$avail=$iavail*512; |
186
|
|
|
|
|
|
|
} |
187
|
|
|
|
|
|
|
} elsif(/hpuxish/){ |
188
|
0
|
0
|
|
|
|
|
return undef if($line =~ /^Filesystem.*Mounted on/i); |
189
|
0
|
|
|
|
|
|
($device,$btotal,$bused,$bavail,undef,$iused,$iavail,undef,$mount)= |
190
|
|
|
|
|
|
|
split(' ',$line); |
191
|
0
|
0
|
|
|
|
|
if($self->{'MODE'} eq 'blocks'){ |
|
|
0
|
|
|
|
|
|
192
|
0
|
|
|
|
|
|
$total=$btotal*1024; |
193
|
0
|
|
|
|
|
|
$used=$bused*1024; |
194
|
0
|
|
|
|
|
|
$avail=$bavail*1024; |
195
|
|
|
|
|
|
|
} elsif($self->{'MODE'} eq 'inodes'){ |
196
|
0
|
|
|
|
|
|
$total=($iused + $iavail); |
197
|
0
|
|
|
|
|
|
$used=$iused; |
198
|
0
|
|
|
|
|
|
$avail=$iavail; |
199
|
|
|
|
|
|
|
} |
200
|
|
|
|
|
|
|
} else { |
201
|
0
|
|
|
|
|
|
croak "Unknown encoding ".$Df{"\L".$self->{'FORMAT'}."\E"}{'format'}. |
202
|
|
|
|
|
|
|
" for format ".$self->{'FORMAT'}; |
203
|
|
|
|
|
|
|
} |
204
|
0
|
|
|
|
|
|
$self->{'MOUNTS'}{$mount}=$device; |
205
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}={}; |
206
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}{'device'}=$device; |
207
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}{'total'} =$total; |
208
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}{'used'} =$used; |
209
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}{'avail'} =$avail; |
210
|
0
|
|
|
|
|
|
$self->{'DEVICES'}{$device}{'mount'} =$mount; |
211
|
|
|
|
|
|
|
} |
212
|
|
|
|
|
|
|
|
213
|
0
|
|
|
0
|
1
|
|
sub device() { return extract(@_,'device'); } |
214
|
0
|
|
|
0
|
1
|
|
sub total() { return extract(@_,'total'); } |
215
|
0
|
|
|
0
|
1
|
|
sub used() { return extract(@_,'used'); } |
216
|
0
|
|
|
0
|
1
|
|
sub avail() { return extract(@_,'avail'); } |
217
|
0
|
|
|
0
|
1
|
|
sub mount() { return extract(@_,'mount'); } |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
sub extract () { |
220
|
0
|
|
|
0
|
0
|
|
my $self=shift; |
221
|
0
|
|
|
|
|
|
my $device; |
222
|
0
|
0
|
|
|
|
|
if(@_) { |
223
|
0
|
|
|
|
|
|
my $thingy=shift; |
224
|
0
|
0
|
|
|
|
|
if(defined($self->{'DEVICES'}{$thingy})){ |
225
|
0
|
|
|
|
|
|
$device=$thingy; |
226
|
|
|
|
|
|
|
} else { |
227
|
0
|
0
|
|
|
|
|
return undef unless(defined($self->{'MOUNTS'})); |
228
|
0
|
|
|
|
|
|
while(not defined($self->{'MOUNTS'}{$thingy})){ |
229
|
0
|
0
|
|
|
|
|
return undef if($thingy eq '/'); |
230
|
0
|
0
|
|
|
|
|
$thingy =~ s!/[^/]*?$!! unless($thingy =~ s!/$!!); |
231
|
0
|
0
|
|
|
|
|
$thingy = "/" unless($thingy =~ "/"); |
232
|
|
|
|
|
|
|
} |
233
|
0
|
|
|
|
|
|
$device=$self->{'MOUNTS'}{$thingy} |
234
|
|
|
|
|
|
|
} |
235
|
0
|
|
|
|
|
|
return $self->{'DEVICES'}{$device}{$_[0]}; |
236
|
|
|
|
|
|
|
} |
237
|
0
|
|
|
|
|
|
return undef; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
sub disks () { |
241
|
0
|
|
|
0
|
1
|
|
my $self=shift; |
242
|
0
|
0
|
|
|
|
|
return undef unless(defined($self->{'MOUNTS'})); |
243
|
0
|
|
|
|
|
|
return keys %{$self->{'MOUNTS'}}; |
|
0
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
1; |
247
|
|
|
|
|
|
|
__END__ |