1libnbd-ocaml(3) LIBNBD libnbd-ocaml(3)
2
3
4
6 libnbd-ocaml - how to use libnbd from OCaml
7
9 let nbd = NBD.create () in
10 NBD.connect_uri nbd "nbd://localhost";
11 let size = NBD.get_size nbd in
12 printf "%Ld\n" size;
13 NBD.close ()
14
15 Alternate syntax which ensures that close is called even if an
16 exception is thrown:
17
18 let size =
19 NBD.with_handle (
20 fun nbd ->
21 NBD.connect_uri nbd "nbd://localhost";
22 NBD.get_size nbd
23 ) in
24 printf "%Ld\n" size
25
26 To compile:
27
28 ocamlopt -I +nbd mlnbd.cmxa prog.ml -o prog
29
30 or using findlib:
31
32 ocamlfind opt -package nbd -linkpkg prog.ml -o prog
33
35 This manual page documents how to use libnbd to access Network Block
36 Device (NBD) servers from the OCaml programming language.
37
38 The OCaml bindings work very similarly to the C bindings so you should
39 start by reading libnbd(3).
40
41 For OCaml API documentation see NBD(3).
42
44 Create a libnbd handle of type "NBD.t" by calling "NBD.create ()".
45
46 You can either close the handle explicitly by calling "NBD.close" or it
47 will be closed automatically when it is garbage collected. If you call
48 any other method on a handle which you have explicitly closed then the
49 API will throw an "NBD.Closed" exception.
50
51 "NBD.with_handle" can be used to make sure the handle is closed in a
52 timely manner. See the example in the "SYNOPSIS" above.
53
55 Libnbd errors are turned automatically into "NBD.Error (str, errno)"
56 exceptions. This exception has two parameters. The first is a string
57 which is the printable error message. The second is the raw "errno",
58 if available (see nbd_get_errno(3)). The raw "errno" is not compatible
59 with errors in the OCaml "Unix" module unfortunately.
60
62 This directory contains examples written in OCaml:
63
64 https://gitlab.com/nbdkit/libnbd/tree/master/ocaml/examples
65
67 libnbd(3), NBD(3).
68
70 Richard W.M. Jones
71
73 Copyright (C) 2019-2021 Red Hat Inc.
74
76 This library is free software; you can redistribute it and/or modify it
77 under the terms of the GNU Lesser General Public License as published
78 by the Free Software Foundation; either version 2 of the License, or
79 (at your option) any later version.
80
81 This library is distributed in the hope that it will be useful, but
82 WITHOUT ANY WARRANTY; without even the implied warranty of
83 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
84 Lesser General Public License for more details.
85
86 You should have received a copy of the GNU Lesser General Public
87 License along with this library; if not, write to the Free Software
88 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
89 02110-1301 USA
90
91
92
93libnbd-1.12.5 2022-07-10 libnbd-ocaml(3)