summaryrefslogtreecommitdiffstats
path: root/perl
diff options
context:
space:
mode:
authorRichard Jones <rjones@trick.home.annexia.org>2009-07-09 14:35:34 +0100
committerRichard Jones <rjones@trick.home.annexia.org>2009-07-09 15:33:33 +0100
commit7058e5c63ecc8ed41c9fcc011fbe215bad6f6369 (patch)
tree2ce6eebe8b279e79c06851af6d0a0b35222805b6 /perl
parent2f70ca487bee8babe5aef27f00a2131ea86ebd50 (diff)
downloadlibguestfs-7058e5c63ecc8ed41c9fcc011fbe215bad6f6369.tar.gz
libguestfs-7058e5c63ecc8ed41c9fcc011fbe215bad6f6369.tar.xz
libguestfs-7058e5c63ecc8ed41c9fcc011fbe215bad6f6369.zip
Move 'get_partitions' call into Sys::Guestfs::Lib.
Diffstat (limited to 'perl')
-rw-r--r--perl/lib/Sys/Guestfs/Lib.pm39
1 files changed, 38 insertions, 1 deletions
diff --git a/perl/lib/Sys/Guestfs/Lib.pm b/perl/lib/Sys/Guestfs/Lib.pm
index ae497406..75b20565 100644
--- a/perl/lib/Sys/Guestfs/Lib.pm
+++ b/perl/lib/Sys/Guestfs/Lib.pm
@@ -58,7 +58,7 @@ require Exporter;
use vars qw(@EXPORT_OK @ISA);
@ISA = qw(Exporter);
-@EXPORT_OK = qw(open_guest);
+@EXPORT_OK = qw(open_guest get_partitions);
=head2 open_guest
@@ -182,6 +182,43 @@ sub open_guest
return wantarray ? ($g, $conn, $dom) : $g
}
+=head2 get_partitions
+
+ @partitions = get_partitions ($g);
+
+This function takes an open libguestfs handle C<$g> and returns all
+partitions and logical volumes found on it.
+
+What is returned is everything that could contain a filesystem (or
+swap). Physical volumes are excluded from the list, and so are any
+devices which are partitioned (eg. C</dev/sda> would not be returned
+if C</dev/sda1> exists).
+
+=cut
+
+sub get_partitions
+{
+ my $g = shift;
+
+ my @partitions = $g->list_partitions ();
+ my @pvs = $g->pvs ();
+ @partitions = grep { ! is_pv ($_, @pvs) } @partitions;
+
+ my @lvs = $g->lvs ();
+
+ return sort (@lvs, @partitions);
+}
+
+sub is_pv {
+ local $_;
+ my $t = shift;
+
+ foreach (@_) {
+ return 1 if $_ eq $t;
+ }
+ 0;
+}
+
1;
=head1 COPYRIGHT