[Libguestfs] [PATCH v3 3/7] resize: add function find_partitions

Hu Tao hutao at cn.fujitsu.com
Mon Sep 22 07:47:36 UTC 2014


find_partitions can find partitions of given type.

Signed-off-by: Hu Tao <hutao at cn.fujitsu.com>
---
 resize/resize.ml | 21 ++++++++++++---------
 1 file changed, 12 insertions(+), 9 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index 8f2105c..cfd02fc 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -446,14 +446,15 @@ read the man page virt-resize(1).
     | MBR_ID _ | GPT_Type _ | No_ID -> false
   in
 
-  let partitions : partition list =
+  let find_partitions part_type =
     let parts = Array.to_list (g#part_list "/dev/sda") in
 
-    if List.length parts = 0 then
-      error (f_"the source disk has no partitions");
-
     (* Filter out logical partitions.  See note above. *)
     let parts =
+      match part_type with
+      (* for GPT, all partitions are regarded as Primary Partition,
+       * e.g. there is no Extended Partition or Logical Partition. *)
+      | PrimaryPartition ->
         List.filter (fun p -> parttype <> MBR || p.G.part_num <= 4_l)
         parts in
 
@@ -485,11 +486,6 @@ read the man page virt-resize(1).
             p_target_start = 0L; p_target_end = 0L }
       ) parts in
 
-    if verbose then (
-      eprintf "%d partitions found\n" (List.length partitions);
-      List.iter debug_partition partitions
-    );
-
     (* Check content isn't larger than partitions.  If it is then
      * something has gone wrong and we shouldn't continue.  Old
      * virt-resize didn't do these checks.
@@ -521,6 +517,13 @@ read the man page virt-resize(1).
 
     partitions in
 
+  let partitions = find_partitions PrimaryPartition in
+
+  if verbose then (
+    eprintf "%d partitions found\n" (List.length partitions);
+    List.iter debug_partition partitions
+    );
+
   (* Build a data structure describing LVs on the source disk. *)
   let lvs =
     let lvs = Array.to_list (g#lvs ()) in
-- 
1.9.3




More information about the Libguestfs mailing list