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 /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 'src')
| -rw-r--r-- | src/fs.zig | 73 |
1 files changed, 73 insertions, 0 deletions
@@ -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; |
