vmgs

Struct Vmgs

Source
pub struct Vmgs { /* private fields */ }
Expand description

Implementation of the VMGS file format, backed by a generic Disk device.

Implementations§

Source§

impl Vmgs

Source

pub fn open_from_saved(disk: Disk, state: SavedVmgsState) -> Self

Construct a Vmgs instance, re-using existing saved-state from an earlier instance.

§Safety

open_from_saved does NOT perform ANY validation on the provided state, and will blindly assume that it matches the underlying storage instance!

Callers MUST ensure that the provided state matches the provided storage, and that no external entities have modified storage between the call to save and open_from_saved.

Failing to do so may result in data corruption/loss, read/write failures, encryption errors, etc… (though, notably: it will not result in any memory-unsafety, hence why the function isn’t marked unsafe).

Source

pub fn save(&self) -> SavedVmgsState

Save the in-memory Vmgs file metadata.

This saved state can be used alongside open_from_saved to obtain a new Vmgs instance without needing to invoke any IOs on the underlying storage.

Source§

impl Vmgs

Source

pub async fn format_new(disk: Disk) -> Result<Self, Error>

Format and open a new VMGS file.

Source

pub async fn open(disk: Disk) -> Result<Self, Error>

Open the VMGS file.

Source

pub fn get_file_info(&self, file_id: FileId) -> Result<VmgsFileInfo, Error>

Get allocated and valid bytes from File Control Block for file_id.

When reading data from a file, the buffer must be at least valid_bytes long.

Source

pub async fn read_file(&mut self, file_id: FileId) -> Result<Vec<u8>, Error>

Reads the specified file_id, decrypting its contents.

Source

pub async fn read_file_raw(&mut self, file_id: FileId) -> Result<Vec<u8>, Error>

Reads the specified file_id, but does not decrypt the contents.

Source

pub async fn write_file( &mut self, file_id: FileId, buf: &[u8], ) -> Result<(), Error>

Writes buf to a file_id without encrypting it.

If the file is already encrypted, this will return a failure. Use Self::write_file_allow_overwrite_encrypted if you want to allow this.

To write encrypted data, use write_file_encrypted instead.

Source

pub async fn write_file_allow_overwrite_encrypted( &mut self, file_id: FileId, buf: &[u8], ) -> Result<(), Error>

Writes buf to a file_id without encrypting it, allowing overrites of an already-encrypted file.

Source

pub async fn write_file_encrypted( &mut self, file_id: FileId, buf: &[u8], ) -> Result<(), Error>

Encrypts buf and writes the encrypted payload to a file_id if the VMGS file has encryption configured. If the VMGS doesn’t have encryption configured, will do a plaintext write instead.

Source

pub async fn unlock_with_encryption_key( &mut self, encryption_key: &[u8], ) -> Result<usize, Error>

Decrypts the extended file table by the encryption_key and updates the related metadata in memory.

Source

pub async fn add_new_encryption_key( &mut self, encryption_key: &[u8], encryption_algorithm: EncryptionAlgorithm, ) -> Result<usize, Error>

Associates a new root key with the data store. Returns the index of the newly associated key.

Source

pub async fn remove_encryption_key( &mut self, key_index: usize, ) -> Result<(), Error>

Disassociates the root key at the specified index from the data store.

Source

pub fn get_encryption_algorithm(&self) -> EncryptionAlgorithm

Gets the encryption algorithm of the VMGS

Source

pub fn is_encrypted(&self) -> bool

Whether the VMGS file is encrypted

Source

pub fn get_active_datastore_key_index(&self) -> Option<usize>

Get the active datastore key index

Trait Implementations§

Source§

impl Inspect for Vmgs

Source§

fn inspect(&self, req: Request<'_>)

Inspects the object.

Auto Trait Implementations§

§

impl Freeze for Vmgs

§

impl !RefUnwindSafe for Vmgs

§

impl Send for Vmgs

§

impl Sync for Vmgs

§

impl Unpin for Vmgs

§

impl !UnwindSafe for Vmgs

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