diff options
| author | Gabriel Schneider <[email protected]> | 2026-10-01 05:49:05 -0300 |
|---|---|---|
| committer | Gabriel Schneider <[email protected]> | 2026-10-01 05:50:14 -0300 |
| commit | 552584ad79448988646231c7993a36e55b0e8c05 (patch) | |
| tree | 69eb107431964519a0d9b019d4d47cad2edcd6ec /9ns/src | |
| parent | 12d78be492351e29144daa379232bbd955b47631 (diff) | |
| download | cloud9-552584ad79448988646231c7993a36e55b0e8c05.tar.gz cloud9-552584ad79448988646231c7993a36e55b0e8c05.zip | |
9ns: acme's address and argument refusals reach the caller as EINVAL, not EIO; the word rules are cloud9.fs.enameErrno, for a server's tests to ask
A server that keeps acme's spellings (pardes) refuses an address or a
ctl argument with "no match for regexp", "address out of range",
"addresses out of order", "range past end of body" and the like, as
EINVAL, but none held a word 9ns knew, so a shell through the mount
heard EIO. Each now maps to EINVAL, narrowly and after every older
rule, so nothing that maps today is remapped.
The rules move from 9ns into the cloud9 module as fs.enameErrno
(Linux's numbers), 9ns's enameToErrno a cast of it, so a server's own
tests can check that each refusal says its errno in words 9ns maps.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
Diffstat (limited to '9ns/src')
| -rw-r--r-- | 9ns/src/nine.zig | 70 |
1 files changed, 24 insertions, 46 deletions
diff --git a/9ns/src/nine.zig b/9ns/src/nine.zig index 0dc957c..1eda9e2 100644 --- a/9ns/src/nine.zig +++ b/9ns/src/nine.zig @@ -934,53 +934,10 @@ fn readSocket(fd: i32, buf: []u8) Session.Error!usize { } } -/// Rerror text → errno, per docs/DESIGN.md (first match wins). +/// Rerror text → errno, per docs/DESIGN.md (first match wins): cloud9's +/// fs.enameErrno, which a server's own tests can ask too. pub fn enameToErrno(ename: []const u8) linux.E { - const Rule = struct { needle: []const u8, err: linux.E }; - const rules = [_]Rule{ - // Plan 9's own refusals of a ctl write (kernel/misc/parse.c), first - // since they quote the message they refuse, whose words could be - // anything below: "unknown control message \"Find permission\"". - .{ .needle = "control message", .err = .INVAL }, - // A server that answers a flushed request with an error (Pardes says - // "Interrupted system call") should look like a flush to the caller. - .{ .needle = "interrupt", .err = .INTR }, - // acme's answer to a read whose window closed under it (Pardes says - // it too): the file is still named, it just has no more to give. - .{ .needle = "shut down", .err = .IO }, - .{ .needle = "not exist", .err = .NOENT }, - .{ .needle = "not found", .err = .NOENT }, - .{ .needle = "no such", .err = .NOENT }, - .{ .needle = "exists", .err = .EXIST }, - .{ .needle = "not empty", .err = .NOTEMPTY }, - .{ .needle = "not a dir", .err = .NOTDIR }, - .{ .needle = "is a dir", .err = .ISDIR }, - .{ .needle = "permission", .err = .ACCES }, - .{ .needle = "denied", .err = .ACCES }, - .{ .needle = "read-only", .err = .ROFS }, - .{ .needle = "read only", .err = .ROFS }, - .{ .needle = "readonly", .err = .ROFS }, - .{ .needle = "no space", .err = .NOSPC }, - .{ .needle = "not allowed", .err = .PERM }, - .{ .needle = "not permitted", .err = .PERM }, - .{ .needle = "cannot", .err = .PERM }, - .{ .needle = "fid", .err = .BADF }, - .{ .needle = "bad offset", .err = .INVAL }, - .{ .needle = "invalid", .err = .INVAL }, - .{ .needle = "bad ", .err = .INVAL }, - .{ .needle = "busy", .err = .BUSY }, - .{ .needle = "in use", .err = .BUSY }, - .{ .needle = "too long", .err = .NAMETOOLONG }, - // A server's open records all taken (pardes: 64): the fd table's - // word, which a shell prints as "Too many open files". - .{ .needle = "too many open files", .err = .MFILE }, - .{ .needle = "not supported", .err = .OPNOTSUPP }, - .{ .needle = "unsupported", .err = .OPNOTSUPP }, - }; - for (rules) |rule| { - if (std.ascii.findIgnoreCase(ename, rule.needle) != null) return rule.err; - } - return .IO; + return @enumFromInt(cloud9.fs.enameErrno(ename)); } // -- transport ------------------------------------------------------------------ @@ -1072,6 +1029,27 @@ test { testing.refAllDecls(@This()); } +test "acme's address and argument refusals are EINVAL, and remap nothing an older rule answers" { + for ([_][]const u8{ + "no match for regexp", + "no previous regular expression", + "address out of range", + "address out of range: a column counts from 1", + "addresses out of order", + "range past end of body", + "no address: the last one written to addr failed", + "pane not locked by this open", + "size: too small for the panes, each its tag and 2 rows \"160 57\"", + "size: a frontend is attached and owns the size \"120 40\"", + "no question asked \"answer\"", + "answer takes k j or -", + "answer takes a b or - \"answer\"", + }) |ename| try testing.expectEqual(linux.E.INVAL, enameToErrno(ename)); + // Earlier rules still win: a fid's own words stay EBADF. + try testing.expectEqual(linux.E.BADF, enameToErrno("fid unknown or out of range")); + try testing.expectEqual(linux.E.NOENT, enameToErrno("no such file: answer takes")); +} + test "ename → errno mapping" { try testing.expectEqual(linux.E.INTR, enameToErrno("Interrupted system call")); try testing.expectEqual(linux.E.INTR, enameToErrno("read interrupted")); |
