summaryrefslogtreecommitdiff
path: root/src/fuse.zig
diff options
context:
space:
mode:
Diffstat (limited to 'src/fuse.zig')
-rw-r--r--src/fuse.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/fuse.zig b/src/fuse.zig
index 311d887b..3a903e8b 100644
--- a/src/fuse.zig
+++ b/src/fuse.zig
@@ -58,6 +58,10 @@ const builtin = @import("builtin");
const libc = std.c;
const linux = std.os.linux;
const acmefs = @import("acmefs.zig");
+/// Only for `Transport`, the three-function shape this mount presents to the
+/// host loop. No cycle: `fs_service` names no type from here any more, which
+/// is the point of the seam.
+const fs_service = @import("fs_service.zig");
/// Everything below the mount is Linux kernel ABI. Off Linux the module still
/// compiles (it is imported by the shared native shell) and does nothing.
@@ -1059,6 +1063,39 @@ pub const Fs = struct {
gpa.destroy(fs);
}
+ /// This mount as the three functions `fs_service` actually calls. The
+ /// adapter exists so that file needs no `@import("fuse.zig")` to drive a
+ /// filesystem: `retry`, `next` and `reply` were always its whole use of an
+ /// `Fs`, and naming them lets a second transport answer the same calls.
+ ///
+ /// The thunks are three lines each because a `*Fs` is not an `*anyopaque`
+ /// and a vtable cannot hold the typed function directly. That is the entire
+ /// cost of the seam.
+ pub fn transport(fs: *Fs) fs_service.Transport {
+ return .{ .ctx = fs, .vtable = &transport_vtable };
+ }
+
+ const transport_vtable: fs_service.Transport.VTable = .{
+ .retry = transportRetry,
+ .next = transportNext,
+ .reply = transportReply,
+ };
+
+ fn transportRetry(ctx: *anyopaque) ?acmefs.Req {
+ const fs: *Fs = @ptrCast(@alignCast(ctx));
+ return fs.retry();
+ }
+
+ fn transportNext(ctx: *anyopaque) ?acmefs.Req {
+ const fs: *Fs = @ptrCast(@alignCast(ctx));
+ return fs.next();
+ }
+
+ fn transportReply(ctx: *anyopaque, r: *const acmefs.Reply, bytes: []const u8) void {
+ const fs: *Fs = @ptrCast(@alignCast(ctx));
+ fs.reply(r, bytes);
+ }
+
// -- request pump -------------------------------------------------------
/// Parse the next pending kernel request, or null when the descriptor is