We previously mapped the C type uint32_t count to int32. However this will cause a negative number to be passed for counts >= 2G. This is theoretically not wrong, but could obviously cause problems for plugins which are not prepared to deal with a negative count (by converting it to int64 and adding 0x1_0000_0000). As well as future-proofing the plugin, it's easier for us to just pass counts as int64. Note I did not change pread - see next commit. --- plugins/ocaml/NBDKit.mli | 8 ++++---- plugins/ocaml/plugin.c | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/plugins/ocaml/NBDKit.mli b/plugins/ocaml/NBDKit.mli index 198c250b..dc83c9e9 100644 --- a/plugins/ocaml/NBDKit.mli +++ b/plugins/ocaml/NBDKit.mli @@ -111,10 +111,10 @@ val register_plugin : pread: ('a -> int32 -> int64 -> flags -> string) -> ?pwrite: ('a -> string -> int64 -> flags -> unit) -> ?flush: ('a -> flags -> unit) -> - ?trim: ('a -> int32 -> int64 -> flags -> unit) -> - ?zero: ('a -> int32 -> int64 -> flags -> unit) -> - ?extents: ('a -> int32 -> int64 -> flags -> extent list) -> - ?cache: ('a -> int32 -> int64 -> flags -> unit) -> + ?trim: ('a -> int64 -> int64 -> flags -> unit) -> + ?zero: ('a -> int64 -> int64 -> flags -> unit) -> + ?extents: ('a -> int64 -> int64 -> flags -> extent list) -> + ?cache: ('a -> int64 -> int64 -> flags -> unit) -> (* Miscellaneous. *) ?dump_plugin: (unit -> unit) -> diff --git a/plugins/ocaml/plugin.c b/plugins/ocaml/plugin.c index b6964046..74550993 100644 --- a/plugins/ocaml/plugin.c +++ b/plugins/ocaml/plugin.c @@ -656,7 +656,7 @@ trim_wrapper (void *h, uint32_t count, uint64_t offset, uint32_t flags) CAMLlocal4 (rv, countv, offsetv, flagsv); LEAVE_BLOCKING_SECTION_FOR_CURRENT_SCOPE (); - countv = caml_copy_int32 (count); + countv = caml_copy_int64 (count); offsetv = caml_copy_int64 (offset); flagsv = Val_flags (flags); @@ -677,7 +677,7 @@ zero_wrapper (void *h, uint32_t count, uint64_t offset, uint32_t flags) CAMLlocal4 (rv, countv, offsetv, flagsv); LEAVE_BLOCKING_SECTION_FOR_CURRENT_SCOPE (); - countv = caml_copy_int32 (count); + countv = caml_copy_int64 (count); offsetv = caml_copy_int64 (offset); flagsv = Val_flags (flags); @@ -699,7 +699,7 @@ extents_wrapper (void *h, uint32_t count, uint64_t offset, uint32_t flags, CAMLlocal5 (rv, countv, offsetv, flagsv, v); LEAVE_BLOCKING_SECTION_FOR_CURRENT_SCOPE (); - countv = caml_copy_int32 (count); + countv = caml_copy_int64 (count); offsetv = caml_copy_int64 (offset); flagsv = Val_flags (flags); @@ -739,7 +739,7 @@ cache_wrapper (void *h, uint32_t count, uint64_t offset, uint32_t flags) CAMLlocal4 (rv, countv, offsetv, flagsv); LEAVE_BLOCKING_SECTION_FOR_CURRENT_SCOPE (); - countv = caml_copy_int32 (count); + countv = caml_copy_int64 (count); offsetv = caml_copy_int64 (offset); flagsv = Val_flags (flags); -- 2.32.0