Skip to main content

CowBTree

Struct CowBTree 

Source
pub struct CowBTree {
    root_sector: u32,
    replaced: RefCell<Vec<u32>>,
}
Expand description

ディスク上のCOW B-Treeインデックスマネージャ

Fields§

§root_sector: u32§replaced: RefCell<Vec<u32>>

挿入で新しいセクタへ写した、元の節点のセクタ(COW で不要になった物)。 呼び出し側が新しい根を確定(スーパーブロックへ書く)した後で解放する(take_replaced)。

Implementations§

Source§

impl CowBTree

Source

pub fn new(root_sector: u32) -> Self

Source

pub fn take_replaced(&mut self) -> Vec<u32>

挿入で不要になった元の節点のセクタを取り出す。新しい根を確定する前に解放してはならない (確定前に電源が切れると、古い根が解放済みのセクタを指す)。

Source

pub fn get_root(&self) -> u32

Source

pub fn search<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, key: &[u8; 16], ) -> Option<u32>

指定したキーを B-Tree から検索します (O(log N) 探索) 成功すると、指し示されているファイルメタデータセクタ番号を返します。

Source

pub fn insert<B: BlockDevice>( &mut self, device: &mut MirroredBlockDevice<B>, key: &[u8; 16], val_sector: u32, alloc_sector_fn: &mut dyn FnMut() -> u32, ) -> Result<u32, &'static str>

インデックスへ新しいキーとセクタのペアを挿入します (COWによる再帰的ツリー更新) 更新された新しいルートノードのセクタ番号を返します。

Source

pub fn collect_leaf_entries<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, out: &mut Vec<([u8; 16], u32)>, )

すべての葉ノードエントリ (key, value_sector) を収集

Source

fn collect_from_node<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, sector: u32, out: &mut Vec<([u8; 16], u32)>, visited: &mut BTreeSet<u32>, depth: usize, )

【2026-11-10】打ち切りは深さで行う。以前はたどった節点の総数が 100 を超えると打ち切っていたので、 ファイルが約 1,200〜2,400 個を超えると一覧・fsck から黙って漏れた。循環は visited で検出する。 値 0 は「削除した」印なので返さない(CowBTree::search と同じ扱い)。

Source

pub fn build_sorted<B: BlockDevice>( device: &mut MirroredBlockDevice<B>, entries: &[([u8; 16], u32)], alloc_sector_fn: &mut dyn FnMut() -> u32, ) -> Result<u32, &'static str>

鍵の順に並んだ項から、下の段から一度に木を組み立てる(各節点を 1 回だけ書く。2026-11-11)。 1 項ずつ挿入すると、挿入のたびに根までの節点を写すので、数千項の作り直しで空きを使い切っていた (回収の中で索引を作り直すときに使う)。値 0 の項は捨てる。戻り値は根(項が無ければ 0)。

Source

pub fn collect_node_sectors<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, out: &mut Vec<u32>, )

木の全節点のセクタ番号を out へ集める(fsck の到達性検査用。2026-11-10)。

Source

fn insert_recursive<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, curr_sector: u32, key: &[u8; 16], val_sector: u32, alloc_sector_fn: &mut dyn FnMut() -> u32, ) -> Result<InsertResult, &'static str>

Source

fn split_node<B: BlockDevice>( &self, device: &mut MirroredBlockDevice<B>, node: &mut BTreeNode, new_sector: u32, alloc_sector_fn: &mut dyn FnMut() -> u32, ) -> Result<InsertResult, &'static str>

ノードの半分を別の新しいセクタに分割し、親への引き上げ情報を返します (COW対応)

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> 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> Same for T

Source§

type Output = T

Should always be Self
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.