pub struct BlockStg { /* private fields */ }Expand description
Manages allocation and deallocation of numbered relocatable fixed size blocks from underlying Storage.
Blocks are numbered. A map of the physical location of each block is kept at the start of the storage (after the header).
Physical blocks can be relocated by adjusting the map entry to point to the new location.
On save, the map of free block numbers is processed and any associated physical blocks are freed.
When a physical block is freed, the last physical block is relocated to fill it.
Implementations§
source§impl BlockStg
impl BlockStg
sourcepub fn new(stg: Box<dyn Storage>, blk_cap: u64) -> Self
pub fn new(stg: Box<dyn Storage>, blk_cap: u64) -> Self
Construct BlockStg with specified underlying Storage and block capacity. For existing file, block capacity will be read from file header.
sourcepub fn drop_block(&mut self, bn: u64)
pub fn drop_block(&mut self, bn: u64)
Release a block number ( no longer valid ).
sourcepub fn write(&mut self, bn: u64, offset: u64, data: &[u8])
pub fn write(&mut self, bn: u64, offset: u64, data: &[u8])
Write data to specified numbered block at specified offset.
sourcepub fn write_data(
&mut self,
bn: u64,
offset: u64,
data: Data,
s: usize,
n: usize
)
pub fn write_data( &mut self, bn: u64, offset: u64, data: Data, s: usize, n: usize )
Write slice of Data to specified numbered block at specified offset.
sourcepub fn read(&self, bn: u64, offset: u64, data: &mut [u8])
pub fn read(&self, bn: u64, offset: u64, data: &mut [u8])
Read data from specified numbered block and offset.
sourcepub fn wait_complete(&self)
pub fn wait_complete(&self)
Wait for save to complete.