diff options
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")); |
