summaryrefslogtreecommitdiff
path: root/src/fs.zig
diff options
context:
space:
mode:
authorGabriel Schneider <[email protected]>2026-09-28 20:43:46 -0300
committerGabriel Schneider <[email protected]>2026-09-28 20:43:46 -0300
commitf35b7ed09d0a170e4ffe55b5286c28f74c9a8760 (patch)
tree6a25cbdcf5ade1f722713791fdd3e18a205568e3 /src/fs.zig
parent09b77cf7c13c3384a53594e76f51161cab64e5dd (diff)
downloadcloud9-f35b7ed09d0a170e4ffe55b5286c28f74c9a8760.tar.gz
cloud9-f35b7ed09d0a170e4ffe55b5286c28f74c9a8760.zip
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 <[email protected]>
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig25
1 files changed, 24 insertions, 1 deletions
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")));