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

[Libguestfs] [PATCH v2 02/13] add function div_roundup64



Signed-off-by: Hu Tao <hutao cn fujitsu com>
---
 mllib/common_utils.ml  | 1 +
 mllib/common_utils.mli | 1 +
 resize/resize.ml       | 4 ++--
 3 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/mllib/common_utils.ml b/mllib/common_utils.ml
index 5aa41c2..62d0782 100644
--- a/mllib/common_utils.ml
+++ b/mllib/common_utils.ml
@@ -33,6 +33,7 @@ let ( ~^ ) = Int64.lognot
 
 (* Return 'i' rounded up to the next multiple of 'a'. *)
 let roundup64 i a = let a = a -^ 1L in (i +^ a) &^ (~^ a)
+let div_roundup64 i a = (i +^ a -^ 1L) /^ a
 
 let int_of_le32 str =
   assert (String.length str = 4);
diff --git a/mllib/common_utils.mli b/mllib/common_utils.mli
index e77fcd2..5bf4fba 100644
--- a/mllib/common_utils.mli
+++ b/mllib/common_utils.mli
@@ -28,6 +28,7 @@ val ( ~^ ) : int64 -> int64
 (** Various int64 operators. *)
 
 val roundup64 : int64 -> int64 -> int64
+val div_roundup64 : int64 -> int64 -> int64
 val int_of_le32 : string -> int64
 val le32_of_int : int64 -> string
 
diff --git a/resize/resize.ml b/resize/resize.ml
index e1634de..794a574 100644
--- a/resize/resize.ml
+++ b/resize/resize.ml
@@ -1026,7 +1026,7 @@ read the man page virt-resize(1).
 
         | OpIgnore | OpCopy ->          (* same size *)
           (* Size in sectors. *)
-          let size = (p.p_part.G.part_size +^ sectsize -^ 1L) /^ sectsize in
+          let size = div_roundup64 p.p_part.G.part_size sectsize in
           (* Start of next partition + alignment. *)
           let end_ = start +^ size in
           let next = roundup64 end_ alignment in
@@ -1040,7 +1040,7 @@ read the man page virt-resize(1).
 
         | OpResize newsize ->           (* resized partition *)
           (* New size in sectors. *)
-          let size = (newsize +^ sectsize -^ 1L) /^ sectsize in
+          let size = div_roundup64 newsize sectsize in
           (* Start of next partition + alignment. *)
           let next = start +^ size in
           let next = roundup64 next alignment in
-- 
1.9.3


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