[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[Libguestfs] [PATCH v2 02/11] resize: add logical_partitions and extended_partition



For MBR, logical partitions laid inside extended partition.
Add 3 variables to describe this:
 - partitions
  flat list of primary partitions (as now, the global 'partitions').
  extended partitions is essentially  primary partition

 - logical_partitions
  flat list of logical partitions

 - extended_partition
  one MBR extended partition

Signed-off-by: Chen Hanxiao <chenhanxiao cn fujitsu com>
---
 resize/resize.ml | 37 +++++++++++++++++++++++--------------
 1 file changed, 23 insertions(+), 14 deletions(-)

diff --git a/resize/resize.ml b/resize/resize.ml
index 4c97405..d7a8ce1 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -26,19 +26,16 @@ module G = Guestfs
 (* Minimum surplus before we create an extra partition. *)
 let min_extra_partition = 10L *^ 1024L *^ 1024L
 
+(* mbr extended partition *)
+let extended_partition_list = []
+
 (* Command line argument parsing. *)
 type align_first_t = [ `Never | `Always | `Auto ]
 
 (* Source partition type. *)
 type parttype = MBR | GPT
 
-(* Data structure describing the source disk's partition layout.
- *
- * NOTE: For MBR, only primary/extended partitions are tracked here.
- * Logical partitions are contained within an extended partition, and
- * we don't track them (they are just copied within the extended
- * partition).  For the same reason we cannot resize logical partitions.
- *)
+(* Data structure describing the source disk's partition layout. *)
 type partition = {
   p_name : string;               (* Device name, like /dev/sda1. *)
   p_part : G.partition;          (* SOURCE partition data from libguestfs. *)
@@ -496,12 +493,6 @@ read the man page virt-resize(1).
             p_target_start = 0L; p_target_end = 0L }
       ) parts in
 
-    (* Filter out logical partitions.  See note above. *)
-    let partitions =
-      (* for GPT, all partitions are regarded as Primary Partition,
-       * e.g. there is no Extended Partition or Logical Partition. *)
-      List.filter (fun p -> parttype <> MBR || p.p_mbr_p_type <> LogicalPartition) partitions in
-
     (* 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.
@@ -533,11 +524,29 @@ read the man page virt-resize(1).
       error (f_"%s: this partition overlaps the previous one") name
     | { p_part = { G.part_end = part_end } } :: parts -> loop part_end parts
   in
+
+  let extended_partition_list = List.append
+    extended_partition_list
+    (List.filter (fun p -> parttype = MBR && p.p_mbr_p_type = ExtendedPartition) partitions) in
+  let extended_partition = if (List.length extended_partition_list) > 0 then
+    List.hd extended_partition_list else List.hd partitions in
+  let logical_partitions =
+    List.filter (fun p -> parttype = MBR && p.p_mbr_p_type = LogicalPartition) partitions in
+  (* Filter out logical partitions.  See note above. *)
+  let partitions =
+    (* for GPT, all partitions are regarded as Primary Partition,
+     * e.g. there is no Extended Partition or Logical Partition. *)
+    List.filter (fun p -> parttype <> MBR || p.p_mbr_p_type <> LogicalPartition) partitions in
+
   loop 0L partitions;
+  loop 0L logical_partitions;
 
   if verbose () then (
     printf "%d partitions found\n" (List.length partitions);
-    List.iter (debug_partition ~sectsize) partitions
+    List.iter (debug_partition ~sectsize) partitions;
+    List.iter (debug_partition ~sectsize) logical_partitions;
+    if (List.length extended_partition_list) > 0 then
+      printf "%s is extended partition\n" extended_partition.p_name
     );
 
   (* Build a data structure describing LVs on the source disk. *)
-- 
2.1.0


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]