pub(super) struct RefBlock {
cluster: Option<HostCluster>,
raw_data: IoBuffer,
refcount_order: u32,
cluster_bits: u32,
modified: AtomicBool,
writer_lock: Mutex<()>,
writeback_lock: Mutex<()>,
}Expand description
Refcount block.
Fields§
§cluster: Option<HostCluster>Cluster in the image file.
raw_data: IoBufferRaw table data (big endian).
refcount_order: u32log2 of the refcount bits.
cluster_bits: u32log2 of the cluster size.
modified: AtomicBoolWhether this block has been modified since it was last written.
writer_lock: Mutex<()>Lock for creating RefBlockWriteGuard.
writeback_lock: Mutex<()>Serializes writing this block back to disk (see RefBlock::write_if_modified()).
Implementations§
Source§impl RefBlock
impl RefBlock
Sourcepub fn new_cleared<S: Storage>(for_image: &S, header: &Header) -> Result<Self>
pub fn new_cleared<S: Storage>(for_image: &S, header: &Header) -> Result<Self>
Create a new zeroed refcount block.
Sourcepub async fn load<S: Storage>(
image: &S,
header: &Header,
cluster: HostCluster,
) -> Result<Self>
pub async fn load<S: Storage>( image: &S, header: &Header, cluster: HostCluster, ) -> Result<Self>
Load a refcount block from disk.
Sourcefn copy_raw_data<T: Copy + Sized, F: Fn(*const T) -> T>(
&self,
mem_align: usize,
get: F,
) -> Result<IoBuffer>
fn copy_raw_data<T: Copy + Sized, F: Fn(*const T) -> T>( &self, mem_align: usize, get: F, ) -> Result<IoBuffer>
Copy data from self.raw_data using the get function.
mem_align is the minimum memory alignment for the returned buffer.
Sourcepub fn get_cluster(&self) -> Option<HostCluster>
pub fn get_cluster(&self) -> Option<HostCluster>
Get the block’s cluster in the image file.
Sourcepub fn get_offset(&self) -> Option<HostOffset>
pub fn get_offset(&self) -> Option<HostOffset>
Get the block’s offset in the image file.
Sourcepub fn set_cluster(&mut self, cluster: HostCluster)
pub fn set_cluster(&mut self, cluster: HostCluster)
Change the block’s cluster in the image file (for writing).
Sourcefn sub_byte_refcount_access(&self, index: usize) -> (usize, u8, usize)
fn sub_byte_refcount_access(&self, index: usize) -> (usize, u8, usize)
Calculate sub-byte refcount access parameters.
For a given refcount index, return its:
- byte index,
- access mask,
- in-byte shift.
Sourcepub async fn lock_write(&self) -> RefBlockWriteGuard<'_>
pub async fn lock_write(&self) -> RefBlockWriteGuard<'_>
Allow modifying this refcount block.
Note that readers are allowed to exist while modifications are happening.
Sourcepub async fn write_if_modified<S: Storage>(
&self,
image: &S,
cluster: HostCluster,
) -> Result<()>
pub async fn write_if_modified<S: Storage>( &self, image: &S, cluster: HostCluster, ) -> Result<()>
Write this block to disk if it has been modified since it was last written.
This is the entry point for writing back a block that is part of the refblock cache; it
serializes such write-backs against each other via writeback_lock. Writing the block
clears the modified flag before copying the data, so without that lock, two concurrent
write-backs could race such that the one with the older copy writes last, leaving that
older copy on disk while the block no longer appears modified. Holding the lock across the
modified check means that a write-back which has to wait only writes again if something
changed after the preceding write-back’s copy.
cluster is the cluster this block is expected to belong to; an assert!() verifies that
it really is the block’s cluster.
Sourcepub fn is_modified(&self) -> bool
pub fn is_modified(&self) -> bool
Check whether this block has been modified since it was last written.
Sourcepub fn clear_modified(&self)
pub fn clear_modified(&self)
Clear the modified flag.
Sourcepub fn set_modified(&self)
pub fn set_modified(&self)
Set the modified flag.