12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455(*
* 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.
*
*)typeerror=[`Disconnected]letpp_errorppf=function|`Disconnected->Fmt.stringppf"Device is disconnected"typewrite_error=[error|`Is_read_only]letpp_write_errorppf=function|#errorase->pp_errorppfe|`Is_read_only->Fmt.pfppf"attempted to write to a read-only disk"typeinfo={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 *)}letpp_infoppf{read_write;sector_size;size_sectors}=Format.fprintfppf"@[<2>{ \
@[Mirage_block.read_write =@ %B@];@ \
@[sector_size =@ %d@];@ \
@[size_sectors =@ %LdL@]@ \
}@]"read_writesector_sizesize_sectorsmoduletypeS=sigtypenonrecerror=private[>error]valpp_error:errorFmt.ttypenonrecwrite_error=private[>write_error]valpp_write_error:write_errorFmt.ttypetvaldisconnect:t->unitLwt.tvalget_info:t->infoLwt.tvalread:t->int64->Cstruct.tlist->(unit,error)resultLwt.tvalwrite:t->int64->Cstruct.tlist->(unit,write_error)resultLwt.tend