Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blocks/Pages read/write #88

Open
palainp opened this issue Oct 6, 2021 · 2 comments
Open

Blocks/Pages read/write #88

palainp opened this issue Oct 6, 2021 · 2 comments

Comments

@palainp
Copy link
Member

palainp commented Oct 6, 2021

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?

@dinosaure
Copy link
Member

I think you are mostly right because ocaml-fat is very old, we currently on some others stuffs but we will come back to you with a solution 👍.

@reynir
Copy link
Member

reynir commented Feb 15, 2023

FWIW since mirage-block-solo5.0.8.1 it is possible to write multiple sectors in one write mirage/mirage-block-solo5#28. Solo5 still only supports writing one sector, but mirage-block-solo5 now hides that fact. It's still the case that mirage-block-xen can only write a single 4096 byte page.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants