diff options
Diffstat (limited to 'perl-install/devices.pm')
-rw-r--r-- | perl-install/devices.pm | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/perl-install/devices.pm b/perl-install/devices.pm index 7228f9410..4ccac4901 100644 --- a/perl-install/devices.pm +++ b/perl-install/devices.pm @@ -32,17 +32,38 @@ sub size($) { $low + 1; } +sub del_loop { + my ($dev) = @_; + run_program::run("losetup", "-d", $dev); +} +sub find_free_loop { + foreach (0..7) { + my $dev = make("loop$_"); + { + local *F; + sysopen F, $dev, 2 or next; + !ioctl(F, c::LOOP_GET_STATUS(), my $tmp) && $! == 6 or next; #- 6 == ENXIO + close F; + } + return $dev; + } + die "no free loop found"; +} sub set_loop { - my ($file) = @_; + my ($file, $encrypt_key, $encryption) = @_; + my $dev = find_free_loop(); - foreach (0..7) { + if ($encrypt_key && $encryption) { + my $cmd = "losetup -p 0 -e $encryption $dev $file"; + log::l("calling $cmd"); local *F; - my $dev = make("loop$_"); - sysopen F, $dev, 2 or next; - !ioctl(F, c::LOOP_GET_STATUS(), my $tmp) && $! == 6 or next; #- 6 == ENXIO - log::l("trying with loop $dev"); - return c::set_loop(fileno F, $file) && $dev; + open F, "|$cmd"; + print F $encrypt_key; + close F or die "losetup failed"; + } else { + run_program::run("losetup", $dev, $file) or return; } + $dev; } sub entry { |