package mirage-block

  1. Overview
  2. Docs
Legend:
Page
Library
Module
Module type
Parameter
Class
Class type
Source

Source file mirage_block.ml

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
47
48
49
50
51
52
53
54
55
(*
 * Copyright (C) 2015-present David Scott <dave.scott@unikernel.com>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 *
 *)

type error = [ `Disconnected ]

let pp_error ppf = function
  | `Disconnected -> Fmt.string ppf "Device is disconnected"

type write_error = [ error | `Is_read_only ]

let pp_write_error ppf = function
  | #error as e -> pp_error ppf e
  | `Is_read_only -> Fmt.pf ppf "attempted to write to a read-only disk"

type info = {
  read_write: bool;    (** True if we can write, false if read/only *)
  sector_size: int;    (** Octets per sector *)
  size_sectors: int64; (** Total sectors per device *)
}

let pp_info ppf { read_write; sector_size; size_sectors } =
  Format.fprintf ppf
    "@[<2>{ \
     @[Mirage_block.read_write =@ %B@];@ \
     @[sector_size =@ %d@];@ \
     @[size_sectors =@ %LdL@]@ \
     }@]"
    read_write sector_size size_sectors

module type S = sig
  type nonrec error = private [> error ]
  val pp_error: error Fmt.t
  type nonrec write_error = private [> write_error ]
  val pp_write_error: write_error Fmt.t
  type t
  val disconnect : t -> unit Lwt.t
  val get_info: t -> info Lwt.t
  val read: t -> int64 -> Cstruct.t list -> (unit, error) result Lwt.t
  val write: t -> int64 -> Cstruct.t list ->
    (unit, write_error) result Lwt.t
end
OCaml

Innovation. Community. Security.