pub struct Transaction {
pub sequence: u32,
pub block_size: u32,
pub uses_64bit: bool,
pub uses_csum_v3: bool,
pub writes: Vec<JournaledBlock>,
pub revokes: Vec<u64>,
}Expand description
Transaction builder. Call Transaction::add_write to buffer a mutated
fs block; call Transaction::add_revoke to mark an older block’s
contents as unreachable; call Transaction::commit to serialise.
Fields§
§sequence: u32§block_size: u32§uses_64bit: bool§uses_csum_v3: bool§writes: Vec<JournaledBlock>§revokes: Vec<u64>Implementations§
Source§impl Transaction
impl Transaction
Sourcepub fn begin(
sequence: u32,
block_size: u32,
uses_64bit: bool,
uses_csum_v3: bool,
) -> Self
pub fn begin( sequence: u32, block_size: u32, uses_64bit: bool, uses_csum_v3: bool, ) -> Self
Begin a new transaction with the given sequence number (next value from the JBD2 superblock).
Sourcepub fn add_write(&mut self, fs_block: u64, bytes: Vec<u8>) -> Result<()>
pub fn add_write(&mut self, fs_block: u64, bytes: Vec<u8>) -> Result<()>
Buffer a dirty fs block. Panics in debug if bytes.len() != block_size.
Sourcepub fn add_revoke(&mut self, fs_block: u64)
pub fn add_revoke(&mut self, fs_block: u64)
Record a revoke — tell replay to ignore earlier writes to this fs block.
Sourcepub fn commit(&self) -> Result<Vec<Vec<u8>>>
pub fn commit(&self) -> Result<Vec<Vec<u8>>>
Serialize the transaction into journal blocks. Returns a single flat
Vec<Vec<u8>> where each inner Vec is one block_size byte journal
block, in the order they should be written to the journal log:
[descriptor, data…, descriptor, data…, revoke…, commit]
A descriptor block tags at most tags_per_descriptor() data blocks, so
a write set larger than that is split across several descriptor blocks,
each immediately followed by the data blocks it tags and each ending in
a tag with TAG_LAST set. Revoke records are chunked the same way, at
revokes_per_block() per block. A small transaction therefore still
produces the familiar [descriptor, data_0 ..= data_N, revoke, commit].
Empty transactions (no writes, no revokes) return a single commit block — matches kernel’s “empty transaction” handling.
The checksum fields are left zero; a journal that declares checksums
needs Self::commit_for.
Sourcepub fn commit_for(&self, jsb: &JournalSuperblock) -> Result<Vec<Vec<u8>>>
pub fn commit_for(&self, jsb: &JournalSuperblock) -> Result<Vec<Vec<u8>>>
Serialize for jsb’s journal, with every checksum it declares
filled in (#80). Refuses a journal whose incompat bits this driver
does not handle, and a transaction begun for a different block size
or tag width than jsb declares.