diff options
Diffstat (limited to 'src/fs.zig')
| -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; |
