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: u32Highest 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
impl Store
Sourcepub fn from_device(reader: &str, piv: &dyn PivBackend) -> Result<Self>
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.
Sourcepub fn from_device_raw(reader: &str, piv: &dyn PivBackend) -> Result<Self>
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.
Sourcepub fn format(
reader: &str,
piv: &dyn PivBackend,
object_count: u8,
store_key_slot: u8,
management_key: &str,
) -> Result<Self>
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.
Sourcepub fn chain_is_complete(&self, head_index: u8) -> bool
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.
Sourcepub fn sanitize(&mut self) -> usize
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.
Sourcepub fn sync(&mut self, piv: &dyn PivBackend, management_key: &str) -> Result<()>
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).
Sourcepub fn sync_ordered(
&mut self,
piv: &dyn PivBackend,
management_key: &str,
order: &[u8],
) -> Result<()>
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).
Sourcepub fn alloc_free(&self) -> Option<u8>
pub fn alloc_free(&self) -> Option<u8>
Allocate the next free object index, or None if the store is full.
Sourcepub fn free_count(&self) -> usize
pub fn free_count(&self) -> usize
Number of free (empty) slots.
Sourcepub fn find_head(&self, name: &str) -> Option<&Object>
pub fn find_head(&self, name: &str) -> Option<&Object>
Find the head object for a blob by name.
Sourcepub fn chunk_chain(&self, head_index: u8) -> Vec<u8> ⓘ
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.
Sourcepub fn ensure_age_room(&self, count: usize) -> Result<()>
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).
Sourcepub fn make_object(&self, p: ObjectParams) -> Object
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.