---
plugins/ocaml/NBDKit.mli | 7 +++++++
plugins/ocaml/NBDKit.ml | 4 ++++
plugins/ocaml/bindings.c | 33 +++++++++++++++++++++++++++++++++
3 files changed, 44 insertions(+)
diff --git a/plugins/ocaml/NBDKit.mli b/plugins/ocaml/NBDKit.mli
index ececd5fd..66423821 100644
--- a/plugins/ocaml/NBDKit.mli
+++ b/plugins/ocaml/NBDKit.mli
@@ -162,3 +162,10 @@ val shutdown : unit -> unit
(** Print a debug message when nbdkit is in verbose mode. *)
val debug : ('a, unit, string, unit) format4 -> 'a
+
+(** Binding for [nbdkit_peer_pid]. *)
+val peer_pid : unit -> int64
+(** Binding for [nbdkit_peer_uid]. *)
+val peer_uid : unit -> int64
+(** Binding for [nbdkit_peer_gid]. *)
+val peer_gid : unit -> int64
diff --git a/plugins/ocaml/NBDKit.ml b/plugins/ocaml/NBDKit.ml
index 739210fa..a907f5a2 100644
--- a/plugins/ocaml/NBDKit.ml
+++ b/plugins/ocaml/NBDKit.ml
@@ -257,3 +257,7 @@ external _debug : string -> unit = "ocaml_nbdkit_debug"
"noalloc"
let debug fs =
ksprintf _debug fs
+
+external peer_pid : unit -> int64 = "ocaml_nbdkit_peer_pid"
+external peer_uid : unit -> int64 = "ocaml_nbdkit_peer_uid"
+external peer_gid : unit -> int64 = "ocaml_nbdkit_peer_gid"
diff --git a/plugins/ocaml/bindings.c b/plugins/ocaml/bindings.c
index 6c92cd3e..5d8e8c6a 100644
--- a/plugins/ocaml/bindings.c
+++ b/plugins/ocaml/bindings.c
@@ -190,3 +190,36 @@ ocaml_nbdkit_debug (value strv)
return Val_unit;
}
+
+value
+ocaml_nbdkit_peer_pid (value unitv)
+{
+ CAMLparam1 (unitv);
+ CAMLlocal1 (rv);
+ int64_t id = nbdkit_peer_pid ();
+ if (id == -1) caml_failwith ("nbdkit_peer_pid");
+ rv = caml_copy_int64 (id);
+ CAMLreturn (rv);
+}
+
+value
+ocaml_nbdkit_peer_uid (value unitv)
+{
+ CAMLparam1 (unitv);
+ CAMLlocal1 (rv);
+ int64_t id = nbdkit_peer_uid ();
+ if (id == -1) caml_failwith ("nbdkit_peer_uid");
+ rv = caml_copy_int64 (id);
+ CAMLreturn (rv);
+}
+
+value
+ocaml_nbdkit_peer_gid (value unitv)
+{
+ CAMLparam1 (unitv);
+ CAMLlocal1 (rv);
+ int64_t id = nbdkit_peer_gid ();
+ if (id == -1) caml_failwith ("nbdkit_peer_gid");
+ rv = caml_copy_int64 (id);
+ CAMLreturn (rv);
+}
--
2.27.0