FabricBlock

Struct FabricBlock 

Source
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

Source

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
Source

pub fn num_blocks(&self) -> u64

Returns the total number of blocks reported by the device.

Source

pub fn write_block(&self, lba: u64, data: &[u8; 512]) -> Result<()>

Write a single 512-byte block at the given LBA.

§Errors
Source

pub fn read_block(&self, lba: u64) -> Result<[u8; 512]>

Read a single 512-byte block at the given LBA.

§Errors
Source

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
Source

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

Trait Implementations§

Source§

impl Debug for FabricBlock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.