On Fri, Sep 19, 2014 at 03:39:06PM +0800, Hu Tao wrote:
Signed-off-by: Hu Tao <hutao@cn.fujitsu.com> --- resize/resize.ml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
diff --git a/resize/resize.ml b/resize/resize.ml index e69e486..660ac86 100644 --- a/resize/resize.ml +++ b/resize/resize.ml @@ -453,14 +453,19 @@ read the man page virt-resize(1). error (f_"the source disk has no partitions");
(* Filter out logical partitions. See note above. *) - let parts = + let filter_part part_type parts = match parttype with | GPT -> parts | MBR -> - List.filter (function - | { G.part_num = part_num } when part_num >= 5_l -> false - | _ -> true - ) parts in + match part_type with + | PrimaryPartition -> + List.filter (function + | { G.part_num = part_num } when part_num >= 5_l -> false + | _ -> true + ) parts + in + + let parts = filter_part PrimaryPartition parts in
let partitions = List.map ( -- 1.9.3
The code isn't particularly natural for OCaml. There's a built-in List.filter function which basically does this already, and it's relatively easy to use too: let parts = List.filter (fun p -> parttype <> MBR || p.G.part_num <= 4_l) parts in (You can completely remove the filter_part function). To filter only logical partitions (in patch 12), you will need to do: let parts = List.filter (fun p -> parttype = MBR && p.G.part_num >= 5_l) parts in (BTW I don't think that patch 12 would work correctly for GPT) Rich. -- Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com libguestfs lets you edit virtual machines. Supports shell scripting, bindings from many languages. http://libguestfs.org