Skip to content

[TASK] Phase 4.2.2: In-Memory Filesystem (tmpfs) #131

Description

@iamvirul

Overview

Implement tmpfs: a simple, heap-backed in-memory filesystem that mounts at /. This is the first concrete Filesystem implementation and validates the VFS layer. All data is lost on reboot — that is expected and correct.

Design

Storage Model

pub struct TmpfsInode {
    id: InodeId,
    kind: InodeKind,
    data: SpinLock<TmpfsData>,
}

pub enum TmpfsData {
    File { content: Vec<u8> },
    Dir  { entries: BTreeMap<String, Arc<TmpfsInode>> },
    Symlink { target: String },
}

Inode impl

  • lookup(name) -> BTreeMap lookup in Dir
  • open(flags) -> returns TmpfsFile wrapping a clone of the Arc<TmpfsInode>
  • create(name, kind) -> insert new TmpfsInode into parent Dir
  • unlink(name) -> remove from parent Dir; drop Arc (freed when last reference gone)
  • readdir() -> iterate BTreeMap keys

TmpfsFile read/write

  • read(buf, offset) -> copy content[offset..offset+buf.len()]
  • write(buf, offset) -> extend or overwrite content; update size

Acceptance Criteria

  • tmpfs mounts at / during kernel init
  • create / lookup / unlink work for files and directories
  • read / write work for files (arbitrary offset, arbitrary size)
  • readdir returns correct entries
  • Files persist across multiple open calls within the same boot
  • Smoke test: create /hello.txt, write "Hello", open again, read "Hello"
  • Smoke test: create /dir/, create /dir/file.txt, readdir("/dir/") returns ["file.txt"]
  • Serial log: "tmpfs: mounted at /", "tmpfs: created /hello.txt", "tmpfs: read 5 bytes from /hello.txt"

Files

  • kernel/src/fs/tmpfs/mod.rs
  • kernel/src/fs/tmpfs/inode.rs
  • kernel/src/fs/tmpfs/file.rs

Dependencies

  • Phase 4.2.1 (VFS layer): Filesystem + Inode + File traits

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions