Skip to content

Added P8-read-fs #6

Closed
Amber-Agarwal wants to merge 2 commits into
codenet:p4-trapsfrom
Amber-Agarwal:p8-read-fs
Closed

Added P8-read-fs #6
Amber-Agarwal wants to merge 2 commits into
codenet:p4-trapsfrom
Amber-Agarwal:p8-read-fs

Conversation

@Amber-Agarwal

@Amber-Agarwal Amber-Agarwal commented Feb 14, 2026

Copy link
Copy Markdown

IMPORTANT:- Note that in the implementation I have committed I have taken the MKFS from the C directory only so my makefile assumes MKFS to be already present in a specified folder. This was done as I didn't have the code for MKFS in rust. Once that code is added we can change the mkfs dependency in the Makefile.

This PR implements the filesystem read path for p8 (read-fs) in the Rust kernel.
The kernel now reads inode metadata and file contents from fs.img using inode cache + buffer cache flow, equivalent to the C reference behavior.

Functionality Added

  • Added filesystem/inode layer in src/fs.rs:
    • readsb(dev, sb) to read superblock from disk
    • iinit(dev) to initialize FS state using superblock
    • iget(dev, inum) to fetch inodes from in-memory inode cache (with ref counting)
    • iread(ip) to load inode fields from on-disk dinode
    • stati(ip, st) to expose inode metadata
    • readi(ip, dst, off, n) to read file/directory data block-by-block
    • internal bmap(ip, bn) to map logical block index to disk block (direct + single indirect)
  • Added required FS structs/constants:
    • superblock, inode, stat, dirent, ROOTINO, NDIRECT, NINDIRECT, DIRSIZ, etc.
  • Updated boot flow:
    • call iinit(ROOTDEV) before welcome()
  • Reworked welcome() to use FS APIs:
    • read root inode via iget + iread
    • read and print root directory entries (., .., welcome.txt)
    • load welcome.txt inode, print stats, and print file content via readi
  • Build/boot pipeline updates:
    • fs.img is now generated with mkfs (real xv6 filesystem layout)
    • QEMU launched with both disks (xv6.img as disk0 and fs.img as disk1)

On make qemu, kernel now:

  1. boots from xv6.img
  2. reads superblock from fs.img
  3. reads root inode and directory entries
  4. reads and prints welcome.txt metadata and content

Validation

  • Built and linked successfully in WSL:
    • make kernel
    • make xv6.img fs.img
    • make qemu
  • Verified runtime output includes:
    • valid superblock fields
    • correct root entries
    • correct welcome.txt stats and contents

@codenet

codenet commented May 1, 2026

Copy link
Copy Markdown
Owner

This is superceded by this PR: #18
Closing this one.

@codenet codenet closed this May 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants