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 location of each block is kept at the start of the storage (after the header).
Blocks can be relocated by adjusting the map entry to point to the new location.
On save, the set of free block numbers is processed and any associated blocks are freed.
When a block is freed, the last 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.
sourcepub fn set(&mut self, bn: u64, offset: u64, data: &[u8])
pub fn set(&mut self, bn: u64, offset: u64, data: &[u8])
Set numbered block/offset to specified data.
sourcepub fn set_data(&mut self, bn: u64, offset: u64, data: Data, s: usize, n: usize)
pub fn set_data(&mut self, bn: u64, offset: u64, data: Data, s: usize, n: usize)
Set numbered block/offset to specified slice of Data.
sourcepub fn get(&self, bn: u64, offset: u64, data: &mut [u8])
pub fn get(&self, bn: u64, offset: u64, data: &mut [u8])
Get data from specified numbered block and offset.
sourcepub fn wait_complete(&self)
pub fn wait_complete(&self)
Wait for save to complete.