From f35b7ed09d0a170e4ffe55b5286c28f74c9a8760 Mon Sep 17 00:00:00 2001 From: Gabriel Schneider Date: Mon, 28 Sep 2026 20:43:46 -0300 Subject: fs: a stat of an open fid names its open to the backend acme's fsysstat answers from the fid's own window, so a file whose window went while it was open still stats. The backend's getattr for an open fid now carries its handle, so an editor can do the same: pardes keeps a run's answer after its pane closes, and a reader's fstat (cat's) must find it. Co-Authored-By: Claude Opus 5.5 --- src/fs.zig | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src/fs.zig') diff --git a/src/fs.zig b/src/fs.zig index 9e7a25a..82e8b40 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -1179,7 +1179,10 @@ pub fn Server(comptime Backend: type, comptime opts: Options) type { }, .stat => { const f = s.jobFid() orelse return null; - return s.ask(.{ .tag = s.tick(), .op = .getattr, .node = f.node }); + // An open fid's stat names its open, as acme's fsysstat + // answers from the fid's own window: a file that went + // while open (a closed window's) can still say what it is. + return s.ask(.{ .tag = s.tick(), .op = .getattr, .node = f.node, .handle = if (f.open) f.handle else 0 }); }, .wstat => { const f = s.jobFid() orelse return null; @@ -1951,6 +1954,26 @@ test "fs server: a walk failing on the first element is Rerror, on the second a try testing.expectEqualStrings(e_fid_in_use, got.msg.rerror.ename); } +test "fs server: a stat of an open fid names its open to the backend" { + const Native = Server(StubFs, .{ .fid_capacity = 2 }); + var in: [1024]u8 = undefined; + var out: [2048]u8 = undefined; + var encoded: [1024]u8 = undefined; + var server = Native.init(.{ .in = &in, .out = &out, .root = 1 }); + server.protocol.msize = 1024; + server.fids[0] = .{ .used = true, .fid = 0, .node = 2, .perm = 0o600, .open = true, .handle = 9 }; + server.fids[1] = .{ .used = true, .fid = 1, .node = 2, .perm = 0o600 }; + for ([_]struct { fid: u32, handle: u32 }{ .{ .fid = 0, .handle = 9 }, .{ .fid = 1, .handle = 0 } }, 1..) |c, tag| { + const stat = try encode(.{ .tstat = .{ .fid = c.fid } }, @intCast(tag), &encoded); + try testing.expectEqual(stat.len, server.push(stat)); + const getattr = server.next() orelse return error.MissingGetattr; + try testing.expectEqual(.getattr, getattr.op); + try testing.expectEqual(c.handle, getattr.handle); + server.reply(&.{ .tag = getattr.tag, .attr = .{ .node = 2, .name = "run" } }, ""); + server.wrote(server.output().len); + } +} + test "fs server: backend-sized filenames survive walk and stat within negotiated msize" { const Native = Server(StubFs, .{ .fid_capacity = 2, .name_capacity = 255 }); try testing.expectEqual(@as(usize, 28), @sizeOf(@FieldType(Srv.Fid, "name"))); -- cgit v1.3