pub struct FabricBlock { /* private fields */ }Expand description
Safe handle to fabric block storage via FBBU host functions.
Created by FabricBlock::hello, which performs the FBBU HELLO
handshake and queries the device capacity. Once created, the handle
can read and write fixed-size 512-byte blocks by LBA.
§Examples
use grafos_std::block::{FabricBlock, BLOCK_SIZE};
let blk = FabricBlock::hello()?;
// Single block I/O
let data = [0xAB; BLOCK_SIZE];
blk.write_block(0, &data)?;
let readback = blk.read_block(0)?;
assert_eq!(readback, data);
// Multi-block I/O
let multi = vec![0xCD; BLOCK_SIZE * 3];
blk.write_blocks(1, &multi)?;
let multi_read = blk.read_blocks(1, 3)?;
assert_eq!(multi_read, multi);Implementations§
Source§impl FabricBlock
impl FabricBlock
Sourcepub fn hello() -> Result<FabricBlock>
pub fn hello() -> Result<FabricBlock>
Perform the FBBU HELLO handshake and return a block handle.
Queries the device for its total block count after the handshake succeeds.
§Errors
FabricError::Disconnectedif the host connection is unavailable.- Other
FabricErrorvariants based on the host status code.
Sourcepub fn num_blocks(&self) -> u64
pub fn num_blocks(&self) -> u64
Returns the total number of blocks reported by the device.
Sourcepub fn write_block(&self, lba: u64, data: &[u8; 512]) -> Result<()>
pub fn write_block(&self, lba: u64, data: &[u8; 512]) -> Result<()>
Write a single 512-byte block at the given LBA.
§Errors
FabricError::CapacityExceedediflbais beyond the device’s block count.
Sourcepub fn read_block(&self, lba: u64) -> Result<[u8; 512]>
pub fn read_block(&self, lba: u64) -> Result<[u8; 512]>
Read a single 512-byte block at the given LBA.
§Errors
FabricError::CapacityExceedediflbais beyond the device’s block count.
Sourcepub fn write_blocks(&self, lba: u64, data: &[u8]) -> Result<()>
pub fn write_blocks(&self, lba: u64, data: &[u8]) -> Result<()>
Write multiple contiguous blocks starting at lba.
data.len() must be a multiple of BLOCK_SIZE (512). Each
512-byte chunk is written as a separate block at consecutive LBAs.
§Errors
FabricError::IoErrorifdata.len()is not a multiple ofBLOCK_SIZE.FabricError::CapacityExceededif any LBA is beyond the device’s block count.
Sourcepub fn read_blocks(&self, lba: u64, count: u32) -> Result<Vec<u8>>
pub fn read_blocks(&self, lba: u64, count: u32) -> Result<Vec<u8>>
Read count contiguous blocks starting at lba.
Returns a Vec<u8> of length count * BLOCK_SIZE.
§Errors
FabricError::CapacityExceededif any LBA is beyond the device’s block count.