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:
JournalWriter<TxBegin>: Can only callJournalWriter::write_tx_begin.JournalWriter<Block>: Can only callJournalWriter::write_blocks.JournalWriter<TxEnd>: Can only callJournalWriter::write_tx_end.
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 FastFileSystemInnerReference to the filesystem’s core state.
tx_id: u64Unique identifier of the transaction.
index: usizeInternal 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>
impl<'a> JournalWriter<'a, TxBegin>
Sourcepub fn new(
tx: Vec<(LogicalBlockAddress, Box<[u8; 4096]>)>,
journal: SpinLockGuard<'a, Journal>,
io: JournalIO<'a>,
ffs: &'a FastFileSystemInner,
tx_id: u64,
) -> Self
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.
Sourcepub fn write_tx_begin(self) -> Result<JournalWriter<'a, Block>, KernelError>
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>
impl<'a> JournalWriter<'a, Block>
Sourcepub fn write_blocks(self) -> Result<JournalWriter<'a, TxEnd>, KernelError>
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>
impl<'a> JournalWriter<'a, TxEnd>
Sourcepub fn write_tx_end(
self,
) -> Result<(SpinLockGuard<'a, Journal>, JournalIO<'a>), KernelError>
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.