File: cc_shebang.ml

package info (click to toggle)
nbdkit 1.46.2-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 15,504 kB
  • sloc: ansic: 63,658; sh: 18,717; makefile: 6,814; python: 1,848; cpp: 1,143; perl: 504; ml: 504; tcl: 62
file content (46 lines) | stat: -rwxr-xr-x 1,234 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
(*/.)>/dev/null 2>&1

# The above line is parsed by OCaml as an opening comment and by the
# shell as an impossible command which is ignored.  The line below is
# run by the shell and ignored by OCaml.

exec nbdkit cc "$0" CC=ocamlopt CFLAGS="-output-obj -runtime-variant _pic $OCAML_STD_INCLUDES $OCAML_PLUGIN_LIBRARIES NBDKit.cmx -cclib -L../plugins/ocaml/.libs -cclib -lnbdkitocaml" "$@"
*)

open Printf

let disk = ref (Bytes.make (1024*1024) '\000')

let config k v =
  match k with
  | "size" ->
     let size = NBDKit.parse_size v in
     let size = Int64.to_int size in
     disk := Bytes.make size '\000'
  | _ ->
     failwith (sprintf "unknown parameter: %s" k)

let open_connection _ = ()

let get_size () = Bytes.length !disk |> Int64.of_int

let pread () buf offset _ =
  let len = NBDKit.buf_len buf in
  let offset = Int64.to_int offset in
  NBDKit.blit_bytes_to_buf !disk offset buf 0 len

let pwrite () buf offset _ =
  let len = NBDKit.buf_len buf in
  let offset = Int64.to_int offset in
  NBDKit.blit_buf_to_bytes buf 0 !disk offset len

let () =
  NBDKit.register_plugin
    ~name:    "cc-shebang.ml"
    ~version: (NBDKit.version ())
    ~config
    ~open_connection
    ~get_size
    ~pread
    ~pwrite
    ()