michaelmelanson / michaelmelanson/panda-os

Ext2 write step 6: Truncation, metadata updates, and crash consistency

Open
#56 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

enhancement filesystem kernel
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, and mtime. Write inode back to disk.
2. Metadata timestamp updates
  • Update mtime on write and truncate
  • Update ctime on metadata changes (chmod, link count changes)
  • atime on read is optional — can be deferred or skipped (most modern systems use noatime or relatime)
  • 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:

  1. Allocate in bitmaps and write bitmap blocks
  2. Write data blocks
  3. Write/update inode
  4. 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.rstruncate, sync, RO_COMPAT check, timestamp updates
  • panda-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 stat reflects updated size and timestamps after truncate
  • Verify sync does 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.