diff options
| -rw-r--r-- | 9ns/src/nine.zig | 70 | ||||
| -rw-r--r-- | src/fs.zig | 73 |
2 files changed, 97 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")); @@ -204,6 +204,79 @@ pub const E = struct { pub const NOTEMPTY: u16 = 39; }; +/// What a Rerror's words say its errno is (Linux's numbers), as 9ns gives +/// it to a mount's caller: the first rule whose words the string holds, +/// ignoring case, else EIO. A server whose refusals should reach a shell +/// as EINVAL or ENOENT says so in these words, and its tests can ask here. +pub fn enameErrno(ename: []const u8) u16 { + const INTR: u16 = 4; + const BADF: u16 = 9; + const ACCES: u16 = 13; + const MFILE: u16 = 24; + const ROFS: u16 = 30; + const NAMETOOLONG: u16 = 36; + const OPNOTSUPP: u16 = 95; + const Rule = struct { needle: []const u8, err: u16 }; + 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 = E.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 = E.IO }, + .{ .needle = "not exist", .err = E.NOENT }, + .{ .needle = "not found", .err = E.NOENT }, + .{ .needle = "no such", .err = E.NOENT }, + .{ .needle = "exists", .err = E.EXIST }, + .{ .needle = "not empty", .err = E.NOTEMPTY }, + .{ .needle = "not a dir", .err = E.NOTDIR }, + .{ .needle = "is a dir", .err = E.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 = E.NOSPC }, + .{ .needle = "not allowed", .err = E.PERM }, + .{ .needle = "not permitted", .err = E.PERM }, + .{ .needle = "cannot", .err = E.PERM }, + .{ .needle = "fid", .err = BADF }, + .{ .needle = "bad offset", .err = E.INVAL }, + .{ .needle = "invalid", .err = E.INVAL }, + .{ .needle = "bad ", .err = E.INVAL }, + .{ .needle = "busy", .err = E.BUSY }, + .{ .needle = "in use", .err = E.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 }, + // acme's refusals of an address or a ctl argument (editors/acme, + // kept by pardes in its words), last so that none remaps a string + // an older rule already answers: each is EINVAL. + .{ .needle = "no match for regexp", .err = E.INVAL }, + .{ .needle = "no previous regular expression", .err = E.INVAL }, + .{ .needle = "address out of range", .err = E.INVAL }, + .{ .needle = "addresses out of order", .err = E.INVAL }, + .{ .needle = "past end of body", .err = E.INVAL }, + .{ .needle = "written to addr failed", .err = E.INVAL }, + .{ .needle = "not locked by this open", .err = E.INVAL }, + .{ .needle = "too small for the panes", .err = E.INVAL }, + .{ .needle = "owns the size", .err = E.INVAL }, + .{ .needle = "no question asked", .err = E.INVAL }, + .{ .needle = "answer takes", .err = E.INVAL }, + }; + for (rules) |rule| { + if (std.ascii.findIgnoreCase(ename, rule.needle) != null) return rule.err; + } + return E.IO; +} + /// Longest Rerror string the engine emits. pub const errmax: usize = 128; |
