Signed-off-by: Chen Hanxiao <chenhanxiao(a)cn.fujitsu.com>
---
resize/resize.ml | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/resize/resize.ml b/resize/resize.ml
index 9b4b49f..d793e50 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -808,6 +808,34 @@ read the man page virt-resize(1).
)
);
+ (* caculate the size of logical partitions *)
+ let logical_sizes = List.fold_left (
+ fun total p ->
+ if p.p_mbr_p_type <> LogicalPartition then 0L else
+ match p.p_operation with
+ | OpDelete -> total +^ 0L
+ (* the start of logical partitions is aligned *)
+ | OpCopy | OpIgnore -> total +^ (roundup64 p.p_part.G.part_size (alignment
*^ sectsize))
+ | OpResize newsize -> total +^ (roundup64 newsize (alignment *^ sectsize))
+ ) 0L partitions in
+
+ (* handle resizing of logical partitions *)
+ List.iter (
+ fun p ->
+ if p.p_type = ContentExtendedPartition then (
+ let alignment = if alignment = 1L then 2L else alignment in
+ let size = roundup64 p.p_part.G.part_size sectsize in
+ (* resizing extended partition by --resize or --expand is supported *)
+ let size = match p.p_operation with OpResize s -> s | _ -> size in
+ (* the first logical partition is aligned *)
+ let logical_sizes_align = logical_sizes +^ alignment *^ sectsize in
+ if logical_sizes_align > size then
+ p.p_operation <- OpResize logical_sizes_align
+ (* don't touch the extended partition if logical sizes less
+ * than the original size *)
+ )
+ ) partitions;
+
(* Calculate the final surplus.
* At this point, this number must be >= 0.
*)
--
2.1.0