diff options
author | Pascal Rigaux <pixel@mandriva.com> | 2003-11-05 10:33:56 +0000 |
---|---|---|
committer | Pascal Rigaux <pixel@mandriva.com> | 2003-11-05 10:33:56 +0000 |
commit | 3a2102d8c1abec791f7ac972f8a29610572b6af6 (patch) | |
tree | 1b7114d000df7904b4c4ebe539c61a9dd9ef3398 /move/tree | |
parent | de29f69264c0d565d6685ff13f0ff203e325702a (diff) | |
download | drakx-3a2102d8c1abec791f7ac972f8a29610572b6af6.tar drakx-3a2102d8c1abec791f7ac972f8a29610572b6af6.tar.gz drakx-3a2102d8c1abec791f7ac972f8a29610572b6af6.tar.bz2 drakx-3a2102d8c1abec791f7ac972f8a29610572b6af6.tar.xz drakx-3a2102d8c1abec791f7ac972f8a29610572b6af6.zip |
find out the association (loopX <=> clp) instead of hard writing it
Diffstat (limited to 'move/tree')
-rwxr-xr-x | move/tree/mdk_move_loop | 26 |
1 files changed, 17 insertions, 9 deletions
diff --git a/move/tree/mdk_move_loop b/move/tree/mdk_move_loop index 6b239316b..01f7a78fb 100755 --- a/move/tree/mdk_move_loop +++ b/move/tree/mdk_move_loop @@ -1,17 +1,24 @@ #!/usr/bin/perl -my %loop = (boot => 'loop0', always => 'loop1', totem => 'loop2'); - -sub check { - my ($loop, $file) = @_; - `sudo losetup /dev/$loop 2>/dev/null` =~ m!/$file!; -} - sub name2file { my ($name) = @_; "live_tree_$name.clp"; } +sub get_file2loop { + my (@names) = @_; + my %files = map { name2file($_) => 1 } @names; + my %file2loop; + foreach (0 .. 9) { + my ($file) = `sudo losetup /dev/loop$_ 2>/dev/null` =~ m!\([^)]*/([^)]*)\)! or last; + if (delete $files{$file}) { + $file2loop{$file} = "loop$_"; + last if !%files; + } + } + %file2loop; +} + sub to_memory { my ($loop, $file) = @_; @@ -38,9 +45,10 @@ my ($direction, @names) = @ARGV; my $f = $direction eq 'to_memory' && \&to_memory || $direction eq 'to_cdrom' && \&to_cdrom; $f && @names or usage(); +my %file2loop = get_file2loop(@names); + foreach my $name (@names) { - my $loop = $loop{$name} or die "unknown name $name\n"; my $file = name2file($name); - check($loop, $file) or next; + my $loop = $file2loop{$file} or die "unknown name $name\n"; $f->($loop, $file); } |