Skip to content

regz: Move VirtualFilesystem into /modules#983

Merged
mattnite merged 25 commits into
ZigEmbeddedGroup:mainfrom
piotrfila:move-into-modules
Jul 17, 2026
Merged

regz: Move VirtualFilesystem into /modules#983
mattnite merged 25 commits into
ZigEmbeddedGroup:mainfrom
piotrfila:move-into-modules

Conversation

@piotrfila

Copy link
Copy Markdown
Contributor

I originally intended for this to just be a simple PR moving the files but the VirtualFilesystem code was offensive enough that I decided to rewrite most of it, adding more error checking along the way.

I also found and fixed a bug where Dir.openFile() only matched on the file name, but not on directory names, so if both
foo/bar/main.zig
and
alice/bob/main.zig
existed, handle to any of them could be returned.

@Grazfather Grazfather left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Assuming that root.zig is basically an unchanged VirtualFilesystem.zig, it looks good to me.

Why virtual-io instead virtual fs?

@mattnite mattnite left a comment

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.

I don't see us needing this to become a full virtual IO system, it's just an in-memory filesystem for easy testing, so I'd keep the VirtualFilesystem name for both the module directory name and the file name.

const builtin = @import("builtin");

const Allocator = std.mem.Allocator;
const assert = std.debug.assert;

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.

This is unused according to our check

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Only assert is unused, fixed

@piotrfila

Copy link
Copy Markdown
Contributor Author

I figured the name was picked before the introduction of the Io interface, so if it was created now it would be called VirtualIo.

But I don't have a strong opinion on this, I'll just revert this change.

@Grazfather

Copy link
Copy Markdown
Collaborator

I do not mind the naming, I was only curious. I will actually review the changes now. Good work on the bug fixes!

pub const kind: Node.Kind = empty;

pub const ID = enum(Node.ID) {
// Reserve first 256 file handles for os-specific values, such as sitdin/out/err

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Suggested change
// Reserve first 256 file handles for os-specific values, such as sitdin/out/err
// Reserve first 256 file handles for os-specific values, such as stdin/out/err

}
};

pub fn from_handle(T: type, handle: std.posix.fd_t) !T {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Shouldn't these return std.Io.Operation.FileWriteStreaming.Error? Since we try in write_streaming which returns that error type.

@piotrfila piotrfila Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

from_handle is used in a few places and FileWriteStreaming.Error set just does not contain the FileNotFound error. I guess the closest would be NotOpenForWriting?
I didn't spend too much time picking these error names, in case they are encountered the trace should point to the exact error location anyway.

}

pub fn to_handle(id: anytype) std.posix.fd_t {
// const ID = @TypeOf(id);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

xxx

@mattnite
mattnite merged commit 6177582 into ZigEmbeddedGroup:main Jul 17, 2026
32 of 33 checks passed
@piotrfila

piotrfila commented Jul 17, 2026

Copy link
Copy Markdown
Contributor Author

Was this merge intentional? There were still issues to be resolved 😅
I can just add them to my next PR though

@piotrfila
piotrfila deleted the move-into-modules branch July 17, 2026 16:19
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.

3 participants