summaryrefslogtreecommitdiffstats
path: root/ocaml
diff options
context:
space:
mode:
authorRichard Jones <rjones@redhat.com>2009-04-08 23:06:51 +0100
committerRichard Jones <rjones@redhat.com>2009-04-08 23:06:51 +0100
commitbf26360e5e91148a4479f812c2b43acce4f5884e (patch)
treefe1e185b51b8e0a87a9fc7caa273c7fe7ff82eba /ocaml
parent13339826ea01f8dbd581b5d2544e7692171cf386 (diff)
downloadlibguestfs-bf26360e5e91148a4479f812c2b43acce4f5884e.tar.gz
libguestfs-bf26360e5e91148a4479f812c2b43acce4f5884e.tar.xz
libguestfs-bf26360e5e91148a4479f812c2b43acce4f5884e.zip
Added OCaml examples.
Diffstat (limited to 'ocaml')
-rw-r--r--ocaml/Makefile.am2
-rw-r--r--ocaml/examples/LICENSE2
-rw-r--r--ocaml/examples/Makefile.am10
-rw-r--r--ocaml/examples/README9
-rw-r--r--ocaml/examples/lvs.ml26
5 files changed, 49 insertions, 0 deletions
diff --git a/ocaml/Makefile.am b/ocaml/Makefile.am
index ca8a0acd..00e8027e 100644
--- a/ocaml/Makefile.am
+++ b/ocaml/Makefile.am
@@ -20,6 +20,8 @@ EXTRA_DIST = \
guestfs_c.c guestfs_c.h guestfs_c_actions.c \
.depend META.in
+SUBDIRS = examples
+
if HAVE_OCAML
noinst_DATA = mlguestfs.cma mlguestfs.cmxa META
diff --git a/ocaml/examples/LICENSE b/ocaml/examples/LICENSE
new file mode 100644
index 00000000..8f0b20b7
--- /dev/null
+++ b/ocaml/examples/LICENSE
@@ -0,0 +1,2 @@
+All the examples in the ocaml/examples/ subdirectory may be freely
+copied without any restrictions.
diff --git a/ocaml/examples/Makefile.am b/ocaml/examples/Makefile.am
new file mode 100644
index 00000000..48191e78
--- /dev/null
+++ b/ocaml/examples/Makefile.am
@@ -0,0 +1,10 @@
+EXTRA_DIST = LICENSE README lvs.ml
+
+if HAVE_OCAML
+
+lvs: lvs.ml
+ $(OCAMLFIND) ocamlopt -I .. mlguestfs.cmxa $< -o $@
+
+CLEANFILES = *.cmi *.cmo *.cmx *.o *~ lvs
+
+endif \ No newline at end of file
diff --git a/ocaml/examples/README b/ocaml/examples/README
new file mode 100644
index 00000000..679f5063
--- /dev/null
+++ b/ocaml/examples/README
@@ -0,0 +1,9 @@
+This directory contains various example programs which use the OCaml
+Guestfs bindings to the libguestfs API.
+
+As they are examples, these are licensed so they can be freely copied
+and used without any restrictions.
+
+Tips:
+
+(1) To enable verbose messages, set environment variable LIBGUESTFS_DEBUG=1
diff --git a/ocaml/examples/lvs.ml b/ocaml/examples/lvs.ml
new file mode 100644
index 00000000..12c7c15a
--- /dev/null
+++ b/ocaml/examples/lvs.ml
@@ -0,0 +1,26 @@
+(* An example using the OCaml bindings. *)
+
+open Printf
+
+let () =
+ if Array.length Sys.argv <= 1 || not (Sys.file_exists Sys.argv.(1)) then (
+ eprintf "Usage: lvs guest.img\n";
+ exit 1
+ );
+
+ let h = Guestfs.create () in
+ Guestfs.add_drive h Sys.argv.(1);
+ Guestfs.launch h;
+ Guestfs.wait_ready h;
+
+ let pvs = Guestfs.pvs h in
+ printf "PVs found: [ %s ]\n" (String.concat "; " (Array.to_list pvs));
+
+ let vgs = Guestfs.vgs h in
+ printf "VGs found: [ %s ]\n" (String.concat "; " (Array.to_list vgs));
+
+ let lvs = Guestfs.lvs h in
+ printf "LVs found: [ %s ]\n" (String.concat "; " (Array.to_list lvs));
+
+ (* Helps to find any allocation errors. *)
+ Gc.compact ()