package mirage-types

  1. Overview
  2. Docs

A filesystem module.

type block_device_error

Abstract type representing an error from the block layer

type error = [
  1. | `Not_a_directory of string
    (*

    Cannot create a directory entry in a file

    *)
  2. | `Is_a_directory of string
    (*

    Cannot read or write the contents of a directory

    *)
  3. | `Directory_not_empty of string
    (*

    Cannot remove a non-empty directory

    *)
  4. | `No_directory_entry of string * string
    (*

    Cannot find a directory entry

    *)
  5. | `File_already_exists of string
    (*

    Cannot create a file with a duplicate name

    *)
  6. | `No_space
    (*

    No space left on the block device

    *)
  7. | `Format_not_recognised of string
    (*

    The block device appears to not be formatted

    *)
  8. | `Unknown_error of string
  9. | `Block_device of block_device_error
]
include DEVICE with type error := error
type +'a io

A potentially blocking I/O operation

type t

The type representing the internal state of the device

type id

Type defining an identifier for this device that uniquely identifies it among a device tree.

val id : t -> id

Return the identifier that was used to construct this device

val connect : id -> [ `Error of error | `Ok of t ] io

Connect to the device identified by id

val disconnect : t -> unit io

Disconnect from the device. While this might take some time to complete, it can never result in an error.

type page_aligned_buffer

Abstract type for a page-aligned memory buffer

val read : t -> string -> int -> int -> [ `Ok of page_aligned_buffer list | `Error of error ] io

read t key offset length reads up to length bytes from the value associated with key. If less data is returned than requested, this indicates the end of the value.

val size : t -> string -> [ `Error of error | `Ok of int64 ] io

Get the value size.

type stat = {
  1. filename : string;
    (*

    Filename within the enclosing directory

    *)
  2. read_only : bool;
    (*

    True means the contents are read-only

    *)
  3. directory : bool;
    (*

    True means the entity is a directory; false means a file

    *)
  4. size : int64;
    (*

    Size of the entity in bytes

    *)
}

Per-file/directory statistics

val format : t -> int64 -> [ `Ok of unit | `Error of error ] io

format t size erases the contents of t and creates an empty filesystem of size size bytes

val create : t -> string -> [ `Ok of unit | `Error of error ] io

create t path creates an empty file at path

val mkdir : t -> string -> [ `Ok of unit | `Error of error ] io

mkdir t path creates an empty directory at path

val destroy : t -> string -> [ `Ok of unit | `Error of error ] io

destroy t path removes a path (which may be a file or an empty directory) on filesystem t

val stat : t -> string -> [ `Ok of stat | `Error of error ] io

stat t path returns information about file or directory at path

val listdir : t -> string -> [ `Ok of string list | `Error of error ] io

listdir t path returns the names of files and subdirectories within the directory path

val write : t -> string -> int -> page_aligned_buffer -> [ `Ok of unit | `Error of error ] io

write t path offset data writes data at offset in file path on filesystem t

OCaml

Innovation. Community. Security.