# block Block device abstraction for OCaml 5 with Eio direct-style I/O and Bytesrw integration. ## Overview This library provides a minimal block device interface inspired by MirageOS [mirage-block](https://github.com/mirage/mirage-block) but using Eio's effects-based concurrency instead of Lwt. ## Features - Eio direct-style I/O (no monads) - Bytesrw integration for streaming access - Memory, file, and flow backends - CRC32C integrity checking wrapper - Sub-device views for partitioning - Read-only wrapper ## Installation ``` opam install block ``` ## Usage ```ocaml Eio_main.run @@ fun env -> Eio.Switch.run @@ fun sw -> (* Create a file-backed block device *) let blk = Block.of_file ~sw env#fs "disk.img" ~sector_size:512 ~create:1000L () in let info = Block.info blk in Printf.printf "Sectors: %Ld\n" info.sectors; (* Write a sector *) let data = String.make 512 'A' in Block.write blk 0L data |> Result.get_ok; (* Read it back *) let read = Block.read blk 0L |> Result.get_ok in assert (data = read); (* Add CRC32C integrity checking *) let safe_blk = Block.with_crc32c blk in (* Now reads verify checksums, writes compute them *) ``` ## API ### Core Operations - `Block.info` - Get device info (sector size, count, read/write) - `Block.read` - Read a single sector - `Block.write` - Write a single sector - `Block.read_many` - Read multiple consecutive sectors - `Block.write_many` - Write multiple consecutive sectors - `Block.sync` - Flush pending writes - `Block.close` - Release resources ### Backends - `Block.of_memory` - In-memory device (for testing) - `Block.of_string` - Read-only device from string - `Block.of_file` - File-backed device - `Block.of_flow` - Eio flow-backed device - `Block.of_bigarray` - Bigarray-backed device ### Wrappers - `Block.read_only` - Read-only view - `Block.sub` - Sub-device view (for partitions) - `Block.with_crc32c` - CRC32C integrity checking ### Bytesrw Integration - `Block.to_reader` - Create sequential reader from offset - `Block.to_writer` - Create sequential writer from offset ## Related Work - [mirage-block](https://github.com/mirage/mirage-block) - MirageOS block interface (Lwt-based) - [mirage-block-unix](https://github.com/mirage/mirage-block-unix) - Unix backend for mirage-block ## Licence ISC License. See [LICENSE.md](LICENSE.md) for details.