File: get_size.ml

package info (click to toggle)
libnbd 1.24.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 10,956 kB
  • sloc: ansic: 55,063; ml: 12,364; sh: 8,817; python: 4,757; makefile: 3,036; perl: 165; cpp: 24
file content (22 lines) | stat: -rw-r--r-- 576 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
(* This example is similar to nbdinfo --size <URI>.  It connects to an
 * NBD URI and queries the size of the default export.  To try it out
 * do this from the top build directory:
 *
 * nbdkit -U - null 1G --run './run ocaml/examples/get_size.opt "$uri"'
 *)

open Printf

let () =
  if Array.length Sys.argv <> 2 then
    failwith "usage: get_size URI";
  let uri = Sys.argv.(1) in

  NBD.with_handle (
    fun nbd ->
      (* Connect to the NBD URI. *)
      NBD.connect_uri nbd uri;

      let size = NBD.get_size nbd in
      printf "uri = %s size = %Ld\n" uri size
  )