pub struct Journal {
pub sb: Box<JournalSb>,
}Expand description
A structure representing the journal metadata used for crash consistency.
Journaling allows the file system to recover from crashes by recording changes in a write-ahead log before committing them to the main file system. This ensures that partially written operations do not corrupt the file system state.
The Journal struct encapsulates the journaling superblock and the total
size of the journal region on disk. It is responsible for managing the
checkpointing process, which commits durable changes and clears completed
transactions.
§Fields
sb: The journal superblock, containing configuration and state of the journal.size: The total number of blocks allocated for the journal region.
Fields§
§sb: Box<JournalSb>Journal superblock.
Implementations§
Source§impl Journal
impl Journal
Sourcepub fn recovery(
&mut self,
ffs: &FastFileSystemInner,
io: &JournalIO<'_>,
) -> Result<(), KernelError>
pub fn recovery( &mut self, ffs: &FastFileSystemInner, io: &JournalIO<'_>, ) -> Result<(), KernelError>
Recovers and commited but not checkpointed transactions from the journal.
This function is invoked during file system startup to ensure metadata consistency in the event of a system crash or power failure. It scans the on-disk journal area for valid transactions and re-applies them to the file system metadata.
If no complete transaction is detected, the journal is left unchanged. If a partial or corrupt transaction is found, it is safely discarded.
§Parameters
ffs: A reference to the core file system state, used to apply recovered metadata.io: The journal I/O interface used to read journal blocks and perform recovery writes.
§Returns
Ok(())if recovery completed successfully or no action was needed.Err(KernelError)if an unrecoverable error occurred during recovery.
Sourcepub fn checkpoint(
&mut self,
ffs: &FastFileSystemInner,
io: &JournalIO<'_>,
debug_journal: bool,
) -> Result<(), KernelError>
pub fn checkpoint( &mut self, ffs: &FastFileSystemInner, io: &JournalIO<'_>, debug_journal: bool, ) -> Result<(), KernelError>
Commits completed journal transactions to the file system.
This method performs the checkpoint operation: it flushes completed transactions from the journal into the main file system, ensuring their effects are permanently recorded.
§Parameters
ffs: A reference to the file system core (FastFileSystemInner), needed to apply changes to metadata blocks.io: An object for performing I/O operations related to the journal.debug_journal: If true, enables debug logging for checkpointing.
§Returns
Ok(()): If checkpointing succeeds and all transactions are flushed.Err(KernelError): If I/O or consistency errors are encountered.