Add function get_blockdev.

This function will return you the block device of a given partition path.
This commit is contained in:
Wolfgang Link
2016-12-19 15:15:37 +01:00
committed by Dietmar Maurer
parent 3196c387d2
commit 0d28307d2f

View File

@ -544,4 +544,20 @@ sub get_partnum {
return $partnum;
}
sub get_blockdev {
my ($part_path) = @_;
my $dev = $1 if $part_path =~ m|^/dev/(.*)$|;
my $link = readlink "/sys/class/block/$dev";
my $block_dev = $1 if $link =~ m|([^/]*)/$dev$|;
die "Can't parse parent device\n" if !defined($block_dev);
die "No valid block device\n" if index($dev, $block_dev) == -1;
$block_dev = "/dev/$block_dev";
die "Block device does not exsists\n" if !(-b $block_dev);
return $block_dev;
}
1;