JournalWriter

Struct JournalWriter 

Source
pub struct JournalWriter<'a, WriteTarget> {
    tx: Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>,
    journal: SpinLockGuard<'a, Journal>,
    io: JournalIO<'a>,
    ffs: &'a FastFileSystemInner,
    tx_id: u64,
    index: usize,
    _write_target: PhantomData<WriteTarget>,
}
Expand description

A staged writer for committing a transaction to the journal.

JournalWriter uses a type-state pattern to enforce the correct sequence of journal writes:

This staged API ensures that transactions are written in the correct order and prevents accidental misuse.

Fields§

§tx: Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>

Staged list of (LBA, data) pairs representing metadata blocks to commit.

§journal: SpinLockGuard<'a, Journal>

A lock-protected handle to the journal structure.

§io: JournalIO<'a>

I/O interface for reading/writing disk blocks.

§ffs: &'a FastFileSystemInner

Reference to the filesystem’s core state.

§tx_id: u64

Unique identifier of the transaction.

§index: usize

Internal index tracking progress through tx.

§_write_target: PhantomData<WriteTarget>

Phantom data used to track the current commit stage.

Implementations§

Source§

impl<'a> JournalWriter<'a, TxBegin>

Source

pub fn new( tx: Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>, journal: SpinLockGuard<'a, Journal>, io: JournalIO<'a>, ffs: &'a FastFileSystemInner, tx_id: u64, ) -> Self

Creates a new JournalWriter in the initial TxBegin stage.

This prepares the writer for the staged commit sequence of the given transaction.

§Parameters
  • tx: The list of metadata blocks to be written.
  • journal: A locked handle to the global journal state.
  • io: The disk I/O interface.
  • ffs: A reference to the file system.
  • tx_id: A unique ID assigned to the transaction.
§Returns

A JournalWriter instance in the TxBegin state.

Source

pub fn write_tx_begin(self) -> Result<JournalWriter<'a, Block>, KernelError>

Writes the TxBegin marker to the journal.

This signals the start of a journaled transaction. Must be called before writing the data blocks.

§Returns

A JournalWriter in the Block stage.

Source§

impl<'a> JournalWriter<'a, Block>

Source

pub fn write_blocks(self) -> Result<JournalWriter<'a, TxEnd>, KernelError>

Writes all staged metadata blocks to the journal.

Each block is written sequentially to a dedicated journal area. This must be called after write_tx_begin() and before finalizing with write_tx_end().

§Returns

A JournalWriter in the TxEnd stage.

Source§

impl<'a> JournalWriter<'a, TxEnd>

Source

pub fn write_tx_end( self, ) -> Result<(SpinLockGuard<'a, Journal>, JournalIO<'a>), KernelError>

Writes the TxEnd and completes the transaction by updating journal superblock.

This signals a successfully completed transaction and allows recovery mechanisms to apply the journal contents to the actual file system metadata.

§Returns
  • The locked journal and I/O handle, to checkpoint the journal.
  • Err(KernelError) if the final commit stage fails.

Auto Trait Implementations§

§

impl<'a, WriteTarget> Freeze for JournalWriter<'a, WriteTarget>

§

impl<'a, WriteTarget> !RefUnwindSafe for JournalWriter<'a, WriteTarget>

§

impl<'a, WriteTarget> !Send for JournalWriter<'a, WriteTarget>

§

impl<'a, WriteTarget> Sync for JournalWriter<'a, WriteTarget>
where WriteTarget: Sync,

§

impl<'a, WriteTarget> Unpin for JournalWriter<'a, WriteTarget>
where WriteTarget: Unpin,

§

impl<'a, WriteTarget> !UnwindSafe for JournalWriter<'a, WriteTarget>

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

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

§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

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

§

type Error = <U as TryFrom<T>>::Error

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

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.