Skip to content

Blocks/Pages read/write #88

@palainp

Description

@palainp

The mirage-block-solo5 only accepts reading and writing one block at a time in https://github.com/Solo5/solo5/blob/0eb8cb8f57943e7872a94e19695911a1e0b8aef6/bindings/hvt/block.c#L39-L42. In

ocaml-fat/src/fat.ml

Lines 134 to 136 in 9171848

let page = alloc 4096 in
let block_number = Int64.(div sector_number (of_int sectors_per_block)) in
B.read device block_number [ page ] >>= function
, we ask to read 8 blocks of 512 bytes which fail when running with hvt as target.

The mirage-block-xen only accepts to read and write 1 page at a time in https://github.com/mirage/mirage-block-xen/blob/cf6d97c1f48a73baeedc57136028191db36d892f/lib/front/blkfront.ml#L461. In

ocaml-fat/src/fat.ml

Lines 96 to 104 in 9171848

let page = alloc bps in
B.get_info device >>= fun {sector_size; _} ->
let rec loop = function
| [] -> Lwt.return (Ok ())
| (sector, buffer) :: xs ->
let offset = sector * bps in
let sector' = offset / sector_size in
Cstruct.memset page 0;
B.read device (Int64.of_int sector') [ page ] >>= function
, it reads a bytes_per_sector bytes (with a default value of 512 bytes) which raises the Buffer_not_exactly_one_page exception.

I tested changing the page allocation from 4096 to 512 and from bps to 4096 respectively in https://github.com/palainp/ocaml-fat. Now this works with my small tests, I have a "Test Successful" when I run the dune test bench, but, as I don't have a clear vision of what could be impacted, it may trigger new bugs elsewhere. Does anyone have any idea what these changes may entail?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions