michaelmelanson / michaelmelanson/panda-os

Ext2 write support

Open
#40 2 comments 0 reactions 0 assignees View on GitHub
enhancement filesystem
Dominant language
Rust
Stars
0
Forks
0
PR merge metrics
No merged PRs in 30d

Description

## Summary

Extend the ext2 filesystem driver to support write operations. Currently ext2 is read-only.

## Current state

- The ext2 driver in `panda-kernel/src/vfs/ext2/` supports read-only operations
- File reads, directory listing, and inode traversal work
- The async VFS trait infrastructure supports write operations but ext2 does not implement them
- The virtio block driver supports write operations at the block level

## Desired behaviour

Implement the following ext2 write operations:

- **File writes**: Write data to existing files (allocate new blocks as needed)
- **File creation**: Create new files in a directory (allocate inode, add directory entry)
- **File deletion**: Remove files (free inode, free data blocks, remove directory entry)
- **Directory creation/deletion**: `mkdir` and `rmdir`
- **File truncation**: Resize files (free or allocate blocks)
- **Metadata updates**: Update timestamps, permissions, file size in inodes

## Key files

- `panda-kernel/src/vfs/ext2/mod.rs` — main ext2 driver
- `panda-kernel/src/vfs/ext2/` — ext2 module files
- `panda-kernel/src/vfs/mod.rs` — VFS trait definitions (write methods)
- `panda-kernel/src/drivers/virtio_block/` — block write support (already exists)

## Implementation notes

- **Block allocation**: Read and update the block bitmap. Track free block count in superblock and group descriptors.
- **Inode allocation**: Read and update the inode bitmap. Track free inode count.
- **Directory entries**: Ext2 uses linked-list directory entries with variable-length names. Inserting requires finding space in existing blocks or allocating new ones.
- **Crash consistency**: At minimum, write metadata (inodes, bitmaps) before directory entries to prevent dangling references. A full journal (ext3-style) is out of scope for initial implementation.
- **Superblock updates**: Free block/inode counts must be updated atomically with allocations.
- Pairs well with write coalescing (#38) for efficient metadata updates.

## Testing

- Kernel test: create a file, write data, read it back, verify contents
- Kernel test: delete a file, verify space is reclaimed (free block count increases)
- Kernel test: create and remove directories
- Kernel test: write to a file that requires indirect block allocation
- Kernel test: fill the filesystem, verify ENOSPC error
- Userspace test: create file via VFS, read from another process
- Run existing ext2 read tests to verify no regressions

## Documentation

- Document the block allocation algorithm
- Document crash consistency guarantees (and limitations)
- Update any ext2 documentation with write support details

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the write methods in panda-kernel/src/vfs/mod.rs and the existing read-only implementation under panda-kernel/src/vfs/ext2/, then inspect block writes in panda-kernel/src/drivers/virtio_block/. Done means supporting file and directory creation, deletion, writes, truncation, metadata and allocation updates, with kernel and userspace tests covering reclamation, indirect blocks, ENOSPC and read regressions.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
operating-systems
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.