Richard W.M. Jones wrote:
...
Subject: [PATCH] inspector: Canonicalize device names (fix
RHBZ#526717).
Make filesystem device names canonical, so they are /dev/sd*
instead of /dev/vd*.
---
perl/lib/Sys/Guestfs/Lib.pm | 14 +++++++++++++-
1 files changed, 13 insertions(+), 1 deletions(-)
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index a9868e2..068cde5 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -575,7 +575,19 @@ sub inspect_all_partitions
my $g = shift;
my $parts = shift;
my @parts = @$parts;
- return map { $_ => inspect_partition ($g, $_, @_) } @parts;
+ return map { _canonical_dev ($_) => inspect_partition ($g, $_, @_) } @parts;
+}
+
+# Turn /dev/vd* and /dev/hd* into canonical device names
+# (see BLOCK DEVICE NAMING in guestfs(3)).
+
+sub _canonical_dev
+{
+ local $_ = shift;
+
+ return "/dev/sd$1" if m{^/dev/hd(\w+)};
+ return "/dev/sd$1" if m{^/dev/vd(\w+)};
+ return $_;
}
=head2 inspect_partition
Hi Rich,
I prefer to define such functions before
their first use, and using the prototype notation,
so that perl can check the number of arguments in any use:
sub _canonical_dev ($)
{
my ($dev) = @_;
$dev =~ m{^/dev/[vh]d(\w+)}
and $dev = "/dev/sd$1";
return $dev;
}
Also, I find that not using $_ (even when declared local)
improves maintainability.
Finally, you can combine those two matches into one.