Skip to main content

Transaction

Struct Transaction 

Source
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

Source

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).

Source

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.

Source

pub fn add_revoke(&mut self, fs_block: u64)

Record a revoke — tell replay to ignore earlier writes to this fs block.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Transaction

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Transaction

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.