diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2000-03-20 19:27:10 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2000-03-20 19:27:10 +0000 |
commit | a10bc69094bf47216b0621e154c4fd6a8ff61689 (patch) | |
tree | ae118e32e17e2ae95964ccdc17be246d57141e01 /perl-install/loopback.pm | |
parent | bdbc1b603d0a0cb61bfa3518858bbe333c1a2b16 (diff) | |
download | drakx-backup-do-not-use-a10bc69094bf47216b0621e154c4fd6a8ff61689.tar drakx-backup-do-not-use-a10bc69094bf47216b0621e154c4fd6a8ff61689.tar.gz drakx-backup-do-not-use-a10bc69094bf47216b0621e154c4fd6a8ff61689.tar.bz2 drakx-backup-do-not-use-a10bc69094bf47216b0621e154c4fd6a8ff61689.tar.xz drakx-backup-do-not-use-a10bc69094bf47216b0621e154c4fd6a8ff61689.zip |
no_comment
Diffstat (limited to 'perl-install/loopback.pm')
-rw-r--r-- | perl-install/loopback.pm | 51 |
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; |