Skip to main content

SylFS

Struct SylFS 

Source
pub struct SylFS {
    pub device: MirroredBlockDevice<BackendDevice>,
    pub superblock: Superblock,
    next_bitmap_hint: u32,
}

Fields§

§device: MirroredBlockDevice<BackendDevice>§superblock: Superblock§next_bitmap_hint: u32

次に空きを探し始めるビットマップセクタ(allocate_sector 用)。

【2026-08-05】以前は毎回先頭から走査していた。 5.3MB のフォントを保存すると 1 万回以上 allocate_sector を呼ぶが、 前の方はもう埋まっているので、埋まるほど走査が長くなる。O(n²)

実測: cache書=3636tick/14回(1 回 260 tick=2.6 秒)。

前回見つけた位置から再開すれば、連続確保が O(1) 近くになる。 見つからなければ 0 へ戻して一巡するので取りこぼしは無い。

Implementations§

Source§

impl SylFS

Source

pub fn from_parts( device: MirroredBlockDevice<BackendDevice>, superblock: Superblock, ) -> Self

フォーマット済みのデバイスから SylFS を組み立てる。

内部状態(next_bitmap_hint)を持つようになったので、 構造体リテラルではなくこれを使う。 試験からも同じ経路で作れる(tests/src/test_fs_error_propagation.rs)。

Source§

impl SylFS

Source

pub fn allocate_sector(&mut self) -> u32

空きセクタをビットマップから探索・確保します (COWトランザクション用)

Source

pub fn deallocate_sector(&mut self, sector: u32)

指定したセクタをビットマップで解放します

Source

pub fn save_file( &mut self, filename: &str, content: &[u8], labels: &str, ) -> Result<(), &'static str>

ファイルを新しく保存(または上書き)します (COWによる完全保護)

Source

pub fn read_file(&mut self, filename: &str) -> Option<(FileMetadata, Vec<u8>)>

指定した名前のファイルの内容をロードして返します (チェックサム自動検証 & 自己修復付き、Overlay ROM フォールバック対応)。

§【2026-07-28】互換用のラッパーであること

戻り値が Option のため、「本当に存在しない」と「存在するが読めない」を 区別できない。とくに設定ファイルの読み出しでこれを「存在しない」と 解釈すると既定値で上書きしてしまい、読めなかっただけのファイルを 破棄することになる(実際に config.rs がその経路を持っていた)。 新規のコードは区別できる SylFS::read_file_checked を使うこと。 ここでは少なくとも失敗を無言にしないため、エラーをログへ出す。

Source

pub fn read_file_checked( &mut self, filename: &str, ) -> Result<Option<(FileMetadata, Vec<u8>)>, &'static str>

ファイルを読み出す。「存在しない」と「読めない」を区別する版。

  • Ok(None) … ファイルが存在しない(正常な結果)
  • Ok(Some(..)) … 正常に読めた
  • Err(e) … 存在するはずなのに読めない(デバイス異常・両系破損・ ハッシュ衝突・実体セクタの欠落)。呼び出し側はこれを「無い」と 扱ってはならない(上書きするとデータを失う)。
Source

fn write_overflow_extents( &mut self, rest: &[Extent], ) -> Result<u64, &'static str>

インラインに収まらないエクステント群を、セクタのチェーンへ書き出す。 各セクタは先頭 8 バイトが「次のセクタ番号(0 で終端)」、以降が Extent の並び。戻り値はチェーン先頭のセクタ番号(不要なら 0)。

Source

fn collect_extents(&mut self, meta: &FileMetadata) -> Option<Vec<Extent>>

メタデータから全エクステントを論理順に集める(インライン+溢れチェーン)。

Source

fn extents_to_sectors(extents: &[Extent]) -> Vec<u64>

エクステント列を、論理順のセクタ番号列へ展開する。

Source

pub fn find_by_label(&mut self, label: &str) -> Vec<FileMetadata>

特定のラベルが割り当てられているファイルをすべて列挙して検索します (メタデータ走査)

Source

pub fn list_files(&mut self) -> Vec<FileMetadata>

すべての通常ファイルを列挙します

Source

pub fn delete_file(&mut self, filename: &str) -> Result<(), &'static str>

指定した名前のファイルを削除します (メタデータとデータセクタの安全な解放)

Source

pub fn list_dir(&mut self, prefix: &str) -> Vec<FileMetadata>

プレフィックス(ディレクトリパス等)で始まるファイルを一覧取得します

Auto Trait Implementations§

§

impl Freeze for SylFS

§

impl RefUnwindSafe for SylFS

§

impl Send for SylFS

§

impl Sync for SylFS

§

impl Unpin for SylFS

§

impl UnsafeUnpin for SylFS

§

impl UnwindSafe for SylFS

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.