5 guestfs-ocaml - How to use libguestfs from OCaml
11 let g = Guestfs.create () in
12 Guestfs.add_drive_opts g ~format:"raw" ~readonly:true "disk.img";
15 Object-oriented style:
17 let g = new Guestfs.guestfs () in
18 g#add_drive_opts ~format:"raw" ~readonly:true "disk.img";
21 ocamlfind opt prog.ml -package guestfs -linkpkg -o prog
23 ocamlopt -I +guestfs mlguestfs.cmxa prog.ml -o prog
27 This manual page documents how to call libguestfs from the OCaml
28 programming language. This page just documents the differences from
29 the C API and gives some examples. If you are not familiar with using
30 libguestfs, you also need to read L<guestfs(3)>.
32 =head2 PROGRAMMING STYLES
34 There are two different programming styles supported by the OCaml
35 bindings. You can use a module style, with each C function mapped to
38 int guestfs_set_verbose (guestfs_h *g, int flag);
42 val Guestfs.set_verbose : Guestfs.t -> bool -> unit
44 Alternately you can use an object-oriented style, calling methods
45 on the class C<Guestfs.guestfs>:
47 method set_verbose : bool -> unit
49 The object-oriented style is usually briefer, and the minor performance
50 penalty isn't noticable in the general overhead of performing
53 =head2 CLOSING THE HANDLE
55 The handle is closed when it is reaped by the garbage collector.
56 Because libguestfs handles include a lot of state, it is also
57 possible to close (and hence free) them explicitly by calling
58 C<Guestfs.close> or the C<#close> method.
62 Errors from libguestfs functions are mapped into the C<Guestfs.Error>
63 exception. This has a single parameter which is the error message (a
66 Calling any function/method on a closed handle raises
67 C<Guestfs.Handle_closed>. The single parameter is the name of the
68 function that you called.
70 =head1 EXAMPLE 1: CREATE A DISK IMAGE
74 =head1 EXAMPLE 2: INSPECT A VIRTUAL MACHINE DISK IMAGE
81 L<guestfs-examples(3)>,
85 L<guestfs-recipes(1)>,
87 L<http://libguestfs.org/>,
88 L<http://caml.inria.fr/>.
92 Richard W.M. Jones (C<rjones at redhat dot com>)
96 Copyright (C) 2010 Red Hat Inc. L<http://libguestfs.org/>
98 The examples in this manual page may be freely copied, modified and
99 distributed without any restrictions.
101 This library is free software; you can redistribute it and/or
102 modify it under the terms of the GNU Lesser General Public
103 License as published by the Free Software Foundation; either
104 version 2 of the License, or (at your option) any later version.
106 This library is distributed in the hope that it will be useful,
107 but WITHOUT ANY WARRANTY; without even the implied warranty of
108 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
109 Lesser General Public License for more details.
111 You should have received a copy of the GNU Lesser General Public
112 License along with this library; if not, write to the Free Software
113 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA