Skip to main content

RefBlock

Struct RefBlock 

Source
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: IoBuffer

Raw table data (big endian).

§refcount_order: u32

log2 of the refcount bits.

§cluster_bits: u32

log2 of the cluster size.

§modified: AtomicBool

Whether 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

Source

pub fn new_cleared<S: Storage>(for_image: &S, header: &Header) -> Result<Self>

Create a new zeroed refcount block.

Source

pub async fn load<S: Storage>( image: &S, header: &Header, cluster: HostCluster, ) -> Result<Self>

Load a refcount block from disk.

Source

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.

Source

pub async fn write<S: Storage>(&self, image: &S) -> Result<()>

Write a refcount block to disk.

Source

pub fn get_cluster(&self) -> Option<HostCluster>

Get the block’s cluster in the image file.

Source

pub fn get_offset(&self) -> Option<HostOffset>

Get the block’s offset in the image file.

Source

pub fn set_cluster(&mut self, cluster: HostCluster)

Change the block’s cluster in the image file (for writing).

Source

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.
Source

pub fn get(&self, index: usize) -> u64

Get the given cluster’s refcount.

Source

pub async fn lock_write(&self) -> RefBlockWriteGuard<'_>

Allow modifying this refcount block.

Note that readers are allowed to exist while modifications are happening.

Source

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.

Source

pub fn is_modified(&self) -> bool

Check whether this block has been modified since it was last written.

Source

pub fn clear_modified(&self)

Clear the modified flag.

Source

pub fn set_modified(&self)

Set the modified flag.

Source

pub fn is_zero(&self, index: usize) -> bool

Check whether the given cluster’s refcount is 0.

Trait Implementations§

Source§

impl Drop for RefBlock

Source§

fn drop(&mut self)

Executes the destructor for this type. 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.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more