find_partitions can find partitions of given type.
Signed-off-by: Hu Tao <hutao(a)cn.fujitsu.com>
---
resize/resize.ml | 24 +++++++++++++++---------
1 file changed, 15 insertions(+), 9 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml
index 81bb270..cfd02fc 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -73,6 +73,9 @@ and partition_id =
| MBR_ID of int (* MBR ID. *)
| GPT_Type of string (* GPT UUID. *)
+type partition_type =
+ | PrimaryPartition
+
let rec debug_partition p =
eprintf "%s:\n" p.p_name;
eprintf "\tpartition data: %ld %Ld-%Ld (%Ld bytes)\n"
@@ -443,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
@@ -482,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.
@@ -518,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