michaelmelanson / michaelmelanson/panda-os
Ext2 write step 6: Truncation, metadata updates, and crash consistency
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 0
- Forks
- 0
- PR merge metrics
- No merged PRs in 30d
Description
Summary
Implement file truncation, metadata timestamp updates, crash consistency ordering, and the RO_COMPAT feature check. This is the final step for ext2 write support.
This is step 6 of ext2 write support (#40). Depends on step 5 (#55).
Changes
1. Implement Filesystem::truncate
- Shrinking: Free blocks beyond the new size. Zero the partial last block if the new size is not block-aligned. Walk and free indirect blocks that are no longer needed.
- Growing: Allocate new blocks (or leave sparse holes with zero block pointers).
- Update inode
size,blocks, andmtime. Write inode back to disk.
2. Metadata timestamp updates
- Update
mtimeon write and truncate - Update
ctimeon metadata changes (chmod, link count changes) atimeon read is optional — can be deferred or skipped (most modern systems usenoatimeorrelatime)- Timestamp writes can be batched and written lazily (pairs well with write coalescing #38)
3. Crash consistency ordering
Enforce a write ordering discipline to minimize corruption on crash:
- Allocate in bitmaps and write bitmap blocks
- Write data blocks
- Write/update inode
- Update directory entry
This ensures:
- Crash after bitmap update but before inode update → leaked blocks (fixable by fsck, no dangling references)
- Crash after inode update but before directory entry → orphaned inode (also fixable by fsck)
4. Implement Filesystem::sync
Flush all pending metadata writes to disk. Ensures all superblock, group descriptor, and inode updates are persisted.
5. RO_COMPAT feature check
When mounting read-write, check feature_ro_compat in the superblock. If any unsupported RO_COMPAT features are set, refuse to mount read-write (fall back to read-only). This prevents corrupting filesystems that use features the driver does not understand.
Key files
panda-kernel/src/vfs/ext2/mod.rs—truncate,sync, RO_COMPAT check, timestamp updatespanda-kernel/src/vfs/ext2/bitmap.rs— block freeing during truncation
Testing
- Truncate a file to 0, verify reads return empty and blocks are freed
- Truncate a file to a smaller size, verify data beyond new size is gone
- Truncate a file to a larger size, verify reads beyond old size return zeros (sparse)
- Verify
statreflects updated size and timestamps after truncate - Verify
syncdoes not error on a clean filesystem - Verify RO_COMPAT check: create an ext2 image with an unsupported feature flag, verify write operations are refused
- Run all existing ext2 tests (read and write) to verify no regressions
Documentation
- Document the truncation algorithm (block freeing walk)
- Document the crash consistency guarantees and their limitations (no journal — fsck required after crash)
- Document the write ordering discipline with a diagram or numbered steps
- Document which RO_COMPAT features are recognized and which cause read-only fallback
- Update
docs/if any ext2 documentation exists
Part of #40
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading panda-kernel/src/vfs/ext2/mod.rs and panda-kernel/src/vfs/ext2/bitmap.rs, then run the existing ext2 tests. Done means truncation, timestamps, sync, crash-ordering behavior, and the RO_COMPAT check meet the listed cases, with ext2 documentation updated and no regressions in read or write tests.
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