summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPascal Rigaux <pixel@mandriva.com>2003-11-05 10:33:56 +0000
committerPascal Rigaux <pixel@mandriva.com>2003-11-05 10:33:56 +0000
commit3a2102d8c1abec791f7ac972f8a29610572b6af6 (patch)
tree1b7114d000df7904b4c4ebe539c61a9dd9ef3398
parentde29f69264c0d565d6685ff13f0ff203e325702a (diff)
downloaddrakx-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
-rwxr-xr-xmove/tree/mdk_move_loop26
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);
}