4 let disk = Bytes.make
(nr_sectors*sector_size) '
\000'
(* disk image *)
5 let sparse = Bytes.make
nr_sectors '
\000'
(* sparseness bitmap *)
8 NBDKit.debug
"test ocaml plugin loaded"
11 NBDKit.debug
"test ocaml plugin unloaded"
16 params := (k
, v
) :: !params
18 let test_config_complete () =
19 let params = List.rev
!params in
20 assert (params = [ "a", "1"; "b", "2"; "c", "3" ])
22 let test_open readonly
=
23 NBDKit.debug
"test ocaml plugin handle opened readonly=%b" readonly
;
29 let test_get_size () =
30 Int64.of_int
(Bytes.length
disk)
32 let test_pread () count offset _
=
33 let count = Int32.to_int
count in
34 let buf = Bytes.create
count in
35 Bytes.blit
disk (Int64.to_int offset
) buf 0 count;
36 Bytes.unsafe_to_string
buf
38 let set_non_sparse offset len
=
39 Bytes.fill
sparse (offset
/sector_size) ((len
-1)/sector_size) '
\001'
41 let test_pwrite () buf offset _
=
42 let len = String.length
buf in
43 let offset = Int64.to_int
offset in
44 String.blit
buf 0 disk offset len;
45 set_non_sparse offset len
47 let test_extents () count offset _
=
48 let extents = Array.init
nr_sectors (
50 { NBDKit.offset = Int64.of_int
(sector
*sector_size);
51 length
= Int64.of_int
sector_size;
52 is_hole
= true; is_zero
= false }
56 if c
= '
\001'
then (* not sparse *)
57 extents.(i
) <- { extents.(i
) with is_hole
= false }
62 NBDKit.default_callbacks
with
63 NBDKit.name
= "testocaml";
66 load
= Some
test_load;
67 unload
= Some
test_unload;
68 config
= Some
test_config;
69 config_complete
= Some
test_config_complete;
71 open_connection
= Some
test_open;
72 close
= Some
test_close;
73 get_size
= Some
test_get_size;
74 pread
= Some
test_pread;
75 pwrite
= Some
test_pwrite;
77 extents = Some
test_extents;
78 thread_model
= Some
(fun () -> NBDKit.THREAD_MODEL_SERIALIZE_CONNECTIONS
);
81 let () = NBDKit.register_plugin
plugin