12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758(* unfortunately, "block" is a really overloaded term in this codebase :/ *)(* the module providing Mirage_block.S expects operations to be specified in
* terms of *sectors*, which is not the level on which littlefs wants to
* operate natively - we want to address blocks.
* Provide an intermediate interface that implements block operations on top of
* the sector-based API provided by a Mirage_block.S implementor. *)moduleMake(Sectors:Mirage_block.S):sigincludeMirage_block.Svalconnect:block_size:int->Sectors.t->tLwt.tvalblock_count:t->intend=structtypet={sectors:Sectors.t;sector_size:int;(* how big is each sector? *)size_sectors:int64;(* how many sectors is the device? *)block_size:int;(* how big is each block? *)}typeerror=Sectors.errortypewrite_error=Sectors.write_errorletpp_error=Sectors.pp_errorletpp_write_error=Sectors.pp_write_errorletlog_src=Logs.Src.create"chamelon-shim"~doc:"chamelon block-to-sector shim"moduleLog=(valLogs.src_loglog_src:Logs.LOG)letsector_of_blocktn=letbyte_of_n=Int64.(muln@@of_intt.block_size)inInt64.(divbyte_of_n@@of_intt.sector_size)letblock_countt=(Int64.to_intt.size_sectors)*t.sector_size/t.block_sizeletconnect~block_sizesectors=letopenLwt.InfixinSectors.get_infosectors>>=funinfo->letsector_size=info.sector_sizeinletsize_sectors=info.size_sectorsinLogs.debug(funf->f"got info from a device with sector size %d (0x%x) and %Ld (0x%Lx) sectors available"info.sector_sizeinfo.sector_sizeinfo.size_sectorsinfo.size_sectors);Lwt.return@@{block_size;sector_size;size_sectors;sectors;}letdisconnectt=Sectors.disconnectt.sectorsletget_infot=Sectors.get_infot.sectorsletwritetblock_number=Sectors.writet.sectors(sector_of_blocktblock_number)letreadtblock_number=Sectors.readt.sectors(sector_of_blocktblock_number)end