summaryrefslogtreecommitdiffstats
path: root/perl-install/loopback.pm
diff options
context:
space:
mode:
Diffstat (limited to 'perl-install/loopback.pm')
-rw-r--r--perl-install/loopback.pm51
1 files changed, 30 insertions, 21 deletions
diff --git a/perl-install/loopback.pm b/perl-install/loopback.pm
index 04b3786ae..88623fbe2 100644
--- a/perl-install/loopback.pm
+++ b/perl-install/loopback.pm
@@ -70,35 +70,44 @@ sub create {
$f;
}
-sub getFree {
+sub inspect {
my ($part, $prefix) = @_;
- if ($part->{isFormatted} || !$part->{notFormatted}) {
- $part->{freespace} = $part->{size};
- } elsif (!$part->{freespace}) {
- isMountableRW($part) or return;
-
- my $dir = "/tmp/loopback_tmp";
- if ($part->{isMounted}) {
- $dir = ($prefix || '') . $part->{mntpoint};
- } else {
- mkdir $dir, 0700;
- fs::mount($part->{device}, $dir, type2fs($part->{type}), 'rdonly');
- }
- my $buf = ' ' x 20000;
- syscall_('statfs', $dir, $buf) or return;
- my (undef, $blocksize, $size, undef, $free, undef) = unpack "L2L4", $buf;
- $_ *= $blocksize / 512 foreach $size, $free;
+ isMountableRW($part) or return;
-
+ my $dir = "/tmp/loopback_tmp";
+
+ if ($part->{isMounted}) {
+ $dir = ($prefix || '') . $part->{mntpoint};
+ } else {
+ mkdir $dir, 0700;
+ fs::mount($part->{device}, $dir, type2fs($part->{type}), 'rdonly');
+ }
+ my $h = bless \$dir, "loopback::inspect";
+ common::add_f4before_leaving(sub {
unless ($part->{isMounted}) {
fs::umount($dir);
- unlink $dir;
+ unlink($dir)
}
+ }, $h, 'DESTROY');
+ $h;
+}
+
+sub getFree {
+ my ($dir, $part) = @_;
+ my ($freespace);
- $part->{freespace} = $free;
+ if ($part->{isFormatted} || !$part->{notFormatted}) {
+ $freespace = $part->{size};
+ } else {
+ my $buf = ' ' x 20000;
+ syscall_('statfs', $dir, $buf) or return;
+ my (undef, $blocksize, $size, undef, $free, undef) = unpack "L2L4", $buf;
+ $_ *= $blocksize / 512 foreach $free;
+
+ $freespace = $free;
}
- $part->{freespace} - sum map { $_->{size} } @{$part->{loopback} || []};
+ $freespace - sum map { $_->{size} } @{$part->{loopback} || []};
}
1;