2 ###APPNAME: diskimg-setup
3 ###APPAUTHOR: xiaoranzzz
4 ###APPDATE: Sun Oct 7 02:52:13 2007
6 ###APPDESC: setup loopback device for disk image
7 ###APPUSAGE: (disk image file) (partition NUM)
8 ###APPEXAMPLE: diskimg-setup disk.img 1
9 ###APPOPTION: -d:Delete loopback device setup
11 $ARGV[0]="-h" unless(@ARGV);
18 exit(system("plhelp",$0,@ARGV)) if($_ eq "-h" || $_ eq "--help");
22 elsif (-f
$_ && !$disk) {
30 die("You must be root for running $0.\n") unless($>==0);
31 die("File not exists\n") unless(-f
$disk);
32 $num=1 unless(defined($num));
34 #print join("\t","Disk=$disk","Partition=$num","Delete=$do_delete"),"\n";
39 $name .= $num if($num > 0);
40 my $ln_loop="/share/system/loopback";
43 my $offset=`diskimg-offset "$disk" "$num"`;
45 die("Could not calculat offset for $disk partition $num\n") unless($offset>=0);
46 my $freeloop=`losetup -f`;
48 die("No free loopback device found\n") unless($freeloop);
49 if(system("losetup","-o",$offset,$freeloop,$disk)==0) {
50 system("losetup",$freeloop);
51 # system("ln", "-vsf",$freeloop,$ln_loop . "/" . $name);