#!/usr/bin/perl -w ######################################################################## ## 'lodisk' lets you mount partitions within partitioned disk images, ## ## such as one might create with a command like 'dd if=/dev/hda ## ## of=disk.img'. You can also perform other commands than 'mount', ## ## such as 'fsck' or 'mkfs'. ## ######################################################################## ## Besides perl, 'lodisk' requires 'sfdisk' and (for commands other ## ## than 'mount') 'losetup'. These are in the 'util-linux' package. ## ######################################################################## sub xq { open PIPE, '-|', @_; my @res = ; close PIPE ? @res : undef; } sub usage { die <> 8 : 0); } sub losetdown { system(qw(losetup -d), $dev) == 0 or die ("$0: losetup -d $dev: $?\n"); } sub losetup { ($offset, $file) = @_; $dev = qx(losetup -f) or die "$0: losetup -f: [$?] $!\n"; chomp($dev); system(qw(losetup -o), $offset, $dev, $file) == 0 or die "$0: losetup $dev: [$?] $!\n"; $SIG{__DIE__} = \&losetdown; return $dev; }