Skip to content

Rust: IMFS Grate#49

Merged
rennergade merged 8 commits intomainfrom
imfs-rust
Mar 27, 2026
Merged

Rust: IMFS Grate#49
rennergade merged 8 commits intomainfrom
imfs-rust

Conversation

@rennergade
Copy link
Copy Markdown
Contributor

Summary

  • Full Rust rewrite of the IMFS (In-Memory Filesystem) grate, replacing the C implementation
  • Uses fdtables from lind-wasm/src/fdtables for all fd management instead of the C version's static g_fdtable[MAX_PROCS][MAX_FDS] arrays
  • Uses grate-rs GrateBuilder for the grate lifecycle (fork/exec/wait/semaphore)
  • Includes a C test binary with 11 test cases

How it works

fdtables integration:

  • underfd = node index (which IMFS node this fd points to)
  • perfdinfo = open flags (O_RDONLY, O_WRONLY, etc.)
  • Only custom state: a HashMap<(cage_id, fd), offset> for per-fd read/write position — everything else is fdtables
  • copy_fdtable_for_cage on fork, empty_fds_for_exec on exec, close_virtualfd on close

Filesystem:

  • Arena-style node storage in a Vec with free list (no raw pointers)
  • File data in linked chains of 1024-byte Chunks
  • Directory tree with . and .. link nodes
  • Path resolution walks the tree, following symlinks

Registered syscalls: open, close, read, write, lseek, fcntl, unlink, pread, pwrite, fork, exec

Files

examples/imfs-grate-rs/
Cargo.toml
src/
main.rs - GrateBuilder setup, preload support
handlers.rs - 11 extern "C" syscall handlers
imfs/
mod.rs - ImfsState, fs operations, chunk read/write, path resolution
node.rs - Node, NodeType, Chunk, DirEntry types
test/
imfs_test.c - C test binary (11 tests)

@rennergade rennergade changed the title R Rust: IMFS Grate Mar 19, 2026
Comment thread examples/imfs-grate-rs/Cargo.lock Outdated
@@ -0,0 +1,201 @@
# This file is automatically @generated by Cargo.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary file

Comment thread examples/imfs-grate-rs/Cargo.toml Outdated
Comment thread examples/imfs-grate-rs/test/imfs_test.c Outdated
static void test_mkdir(void) {
printf("\n[test_mkdir]\n");

int ret = mkdir("/mydir", 0755);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

header file sys/stat.h is required for mkdir() call

Copy link
Copy Markdown
Contributor

@stupendoussuperpowers stupendoussuperpowers left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested this, added comments here but also opened a PR which merges into this branch with the fixes for the issues I stated.

Take a look at that PR here: #50

  • Additional work is needed for fork/exec as I've mentioned in these comments, specially vis-a-vis fdtables usage.
  • There are bugs in the fork/exec handlers
  • We need some PRs to go into Lind for other behaviours (Lind-Project/lind-wasm#967 & Lind-Project/lind-wasm#970)
  • There were some minor error handling and quality of life changes for imfs/
  • Looks like these files aren't properly linted? A lot of the diff on the new PR is just cargo fmt fixes.

Comment thread examples/imfs-grate-rs/Cargo.toml Outdated
Comment thread examples/imfs-grate-rs/src/main.rs Outdated
Comment thread examples/imfs-grate-rs/src/imfs/mod.rs Outdated
Comment thread examples/imfs-grate-rs/src/imfs/mod.rs Outdated
Comment thread examples/imfs-grate-rs/src/imfs/mod.rs
Comment thread examples/imfs-grate-rs/src/handlers.rs
Comment thread examples/imfs-grate-rs/src/handlers.rs
Comment thread examples/imfs-grate-rs/test/imfs_test.c Outdated
Comment thread examples/imfs-grate-rs/src/imfs/mod.rs
Comment thread examples/imfs-grate-rs/src/imfs/mod.rs Outdated
@stupendoussuperpowers
Copy link
Copy Markdown
Contributor

Fixed behaviour around fork and updated the tests.

Re-requesting reviews.

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.

4 participants