Skip to main content

Store

Struct Store 

Source
pub struct Store {
    pub reader: String,
    pub object_size: usize,
    pub object_count: u8,
    pub store_key_slot: u8,
    pub objects: Vec<Object>,
    pub store_age: u32,
    pub missing: Vec<u8>,
}
Expand description

The full set of PIV objects that make up one yb store.

Fields§

§reader: String§object_size: usize§object_count: u8§store_key_slot: u8§objects: Vec<Object>§store_age: u32

Highest age seen across all objects; new objects get age = store_age + 1.

§missing: Vec<u8>

Objects the card reported absent when the store was read, read as empty and to be rewritten (spec 0038).

Implementations§

Source§

impl Store

Source

pub fn from_device(reader: &str, piv: &dyn PivBackend) -> Result<Self>

Read all objects from the device and construct a Store, discarding leftovers of interrupted writes in memory (spec 0031). Nothing is written: the next sync writes the reset objects.

Source

pub fn from_device_raw(reader: &str, piv: &dyn PivBackend) -> Result<Self>

Read all objects from the device as they are, leftovers included: for yb fsck, which reports them.

Source

pub fn format( reader: &str, piv: &dyn PivBackend, object_count: u8, store_key_slot: u8, management_key: &str, ) -> Result<Self>

Write a fresh empty store to the device (yb format).

Each slot is initialised with a compact 9-byte empty-slot sentinel (spec 0010). No object_size parameter — size is determined dynamically at write time.

Source

pub fn chain_is_complete(&self, head_index: u8) -> bool

Whether the head at head_index starts a complete chain (spec 0031): every object reached is non-empty, the continuation at position p has chunk_pos == p and age == head age + p (a blob’s objects get consecutive ages when it is written), and the walk ends on a self-reference without a cycle.

Source

pub fn sanitize(&mut self) -> usize

Discard leftovers of interrupted writes and corrupt objects (spec 0031): keep, per name, the newest head with a complete chain; reset every other head and every object not reachable from a kept head. Returns the number of objects reset.

Source

pub fn sync(&mut self, piv: &dyn PivBackend, management_key: &str) -> Result<()>

Write all dirty objects back to the device. If a write fails after others succeeded, the error says the store may be partially updated (spec 0025 §3).

Source

pub fn sync_ordered( &mut self, piv: &dyn PivBackend, management_key: &str, order: &[u8], ) -> Result<()>

Like sync, but writes the dirty objects listed in order first, in that order, then any other dirty objects in index order (spec 0031: a new blob’s head is written after its chunks).

Source

pub fn alloc_free(&self) -> Option<u8>

Allocate the next free object index, or None if the store is full.

Source

pub fn free_count(&self) -> usize

Number of free (empty) slots.

Source

pub fn find_head(&self, name: &str) -> Option<&Object>

Find the head object for a blob by name.

Source

pub fn chunk_chain(&self, head_index: u8) -> Vec<u8> ⓘ

Follow the chunk chain from a head, collecting all chunk indices in order.

Includes a cycle guard: if a next_chunk pointer revisits an already- seen index (corrupt store), the walk stops early so the function always terminates.

Source

pub fn now_unix() -> u32

Current Unix timestamp (seconds), for use as blob_mtime.

Source

pub fn ensure_age_room(&self, count: usize) -> Result<()>

Fail, before anything is written, if writing count more objects would push an age beyond the 24 bits of the age field, where it would wrap to 0, “empty” (spec 0034 G6).

Source

pub fn next_age(&mut self) -> u32

Bump the store age and return the new value for a new chunk.

Source

pub fn make_object(&self, p: ObjectParams) -> Object

Construct a new occupied Object for this store, filling all common header fields from the store’s own metadata. Blob-specific fields (blob_mtime, blob_size, blob_key_slot, blob_plain_size, is_compressed, blob_name, payload) are left at their zero values for the caller to set.

Auto Trait Implementations§

§

impl Freeze for Store

§

impl RefUnwindSafe for Store

§

impl Send for Store

§

impl Sync for Store

§

impl Unpin for Store

§

impl UnsafeUnpin for Store

§

impl UnwindSafe for Store

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> Same for T

Source§

type Output = T

Should always be Self
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V