146439007SCharles.ForsythStyxservers: module 246439007SCharles.Forsyth{ 346439007SCharles.Forsyth PATH: con "/dis/lib/styxservers.dis"; 446439007SCharles.Forsyth 546439007SCharles.Forsyth Fid: adt { 646439007SCharles.Forsyth fid: int; # client's fid 746439007SCharles.Forsyth path: big; # file's 64-bit unique path 846439007SCharles.Forsyth qtype: int; # file's qid type (eg, Sys->QTDIR if directory) 946439007SCharles.Forsyth isopen: int; # non-zero if file is open 1046439007SCharles.Forsyth mode: int; # if open, the open mode 1146439007SCharles.Forsyth doffset: (int, int); # (internal) cache of directory offset 1246439007SCharles.Forsyth uname: string; # user name from original attach 1346439007SCharles.Forsyth param: string; # attach aname from original attach 1446439007SCharles.Forsyth data: array of byte; # application data 1546439007SCharles.Forsyth 1646439007SCharles.Forsyth clone: fn(f: self ref Fid, nf: ref Fid): ref Fid; 1746439007SCharles.Forsyth open: fn(f: self ref Fid, mode: int, qid: Sys->Qid); 1846439007SCharles.Forsyth walk: fn(f: self ref Fid, qid: Sys->Qid); 1946439007SCharles.Forsyth }; 2046439007SCharles.Forsyth 2146439007SCharles.Forsyth Navigator: adt { 2246439007SCharles.Forsyth c: chan of ref Navop; 2346439007SCharles.Forsyth reply: chan of (ref Sys->Dir, string); 2446439007SCharles.Forsyth 2546439007SCharles.Forsyth new: fn(c: chan of ref Navop): ref Navigator; 2646439007SCharles.Forsyth stat: fn(t: self ref Navigator, q: big): (ref Sys->Dir, string); 2746439007SCharles.Forsyth walk: fn(t: self ref Navigator, parentq: big, name: string): (ref Sys->Dir, string); 2846439007SCharles.Forsyth readdir: fn(t: self ref Navigator, q: big, offset, count: int): array of ref Sys->Dir; 2946439007SCharles.Forsyth }; 3046439007SCharles.Forsyth 3146439007SCharles.Forsyth Navop: adt { 3246439007SCharles.Forsyth reply: chan of (ref Sys->Dir, string); # channel for reply 3346439007SCharles.Forsyth path: big; # file or directory path 3446439007SCharles.Forsyth pick { 3546439007SCharles.Forsyth Stat => 3646439007SCharles.Forsyth Walk => 3746439007SCharles.Forsyth name: string; 3846439007SCharles.Forsyth Readdir => 3946439007SCharles.Forsyth offset: int; # index (origin 0) of first directory entry to return 4046439007SCharles.Forsyth count: int; # number of directory entries requested 4146439007SCharles.Forsyth } 4246439007SCharles.Forsyth }; 4346439007SCharles.Forsyth 4446439007SCharles.Forsyth Styxserver: adt { 4546439007SCharles.Forsyth fd: ref Sys->FD; # file server end of connection 4646439007SCharles.Forsyth fids: array of list of ref Fid; # hash table of fids 4746439007SCharles.Forsyth fidlock: chan of int; 4846439007SCharles.Forsyth t: ref Navigator; # name space navigator for this server 4946439007SCharles.Forsyth rootpath: big; # Qid.path of root of its name space 5046439007SCharles.Forsyth msize: int; # negotiated Styx message size 5146439007SCharles.Forsyth replychan: chan of ref Styx->Rmsg; 5246439007SCharles.Forsyth 5346439007SCharles.Forsyth new: fn(fd: ref Sys->FD, t: ref Navigator, rootpath: big): (chan of ref Styx->Tmsg, ref Styxserver); 5446439007SCharles.Forsyth reply: fn(srv: self ref Styxserver, m: ref Styx->Rmsg): int; 5546439007SCharles.Forsyth replydirect: fn(srv: self ref Styxserver, m: ref Styx->Rmsg): int; 56*ad4c862fSforsyth error: fn(srv: self ref Styxserver, m: ref Styx->Tmsg, msg: string); 5746439007SCharles.Forsyth 5846439007SCharles.Forsyth # protocol operations 5946439007SCharles.Forsyth attach: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Attach): ref Fid; 6046439007SCharles.Forsyth clunk: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Clunk): ref Fid; 6146439007SCharles.Forsyth walk: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Walk): ref Fid; 6246439007SCharles.Forsyth open: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Open): ref Fid; 6346439007SCharles.Forsyth read: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Read): ref Fid; 6446439007SCharles.Forsyth remove: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Remove): ref Fid; 6546439007SCharles.Forsyth stat: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Stat); 6646439007SCharles.Forsyth 6746439007SCharles.Forsyth default: fn(srv: self ref Styxserver, gm: ref Styx->Tmsg); 6846439007SCharles.Forsyth 6946439007SCharles.Forsyth # check validity but don't reply 7046439007SCharles.Forsyth cancreate: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Create): (ref Fid, int, ref Sys->Dir, string); 7146439007SCharles.Forsyth canopen: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Open): (ref Fid, int, ref Sys->Dir, string); 7246439007SCharles.Forsyth canremove: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Remove): (ref Fid, big, string); 7346439007SCharles.Forsyth canread: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Read): (ref Fid, string); 7446439007SCharles.Forsyth canwrite: fn(srv: self ref Styxserver, m: ref Styx->Tmsg.Write): (ref Fid, string); 7546439007SCharles.Forsyth 7646439007SCharles.Forsyth # fid management 7746439007SCharles.Forsyth getfid: fn(srv: self ref Styxserver, fid: int): ref Fid; 7846439007SCharles.Forsyth newfid: fn(srv: self ref Styxserver, fid: int): ref Fid; 7946439007SCharles.Forsyth delfid: fn(srv: self ref Styxserver, c: ref Fid); 8046439007SCharles.Forsyth allfids: fn(srv: self ref Styxserver): list of ref Fid; 8146439007SCharles.Forsyth 8246439007SCharles.Forsyth iounit: fn(srv: self ref Styxserver): int; 8346439007SCharles.Forsyth }; 8446439007SCharles.Forsyth 8546439007SCharles.Forsyth init: fn(styx: Styx); 8646439007SCharles.Forsyth traceset: fn(on: int); 8746439007SCharles.Forsyth 8846439007SCharles.Forsyth readbytes: fn(m: ref Styx->Tmsg.Read, d: array of byte): ref Styx->Rmsg.Read; 8946439007SCharles.Forsyth readstr: fn(m: ref Styx->Tmsg.Read, s: string): ref Styx->Rmsg.Read; 9046439007SCharles.Forsyth 9146439007SCharles.Forsyth openok: fn(uname: string, omode, perm: int, fuid, fgid: string): int; 9246439007SCharles.Forsyth openmode: fn(o: int): int; 9346439007SCharles.Forsyth 9446439007SCharles.Forsyth Einuse: con "fid already in use"; 9546439007SCharles.Forsyth Ebadfid: con "bad fid"; 9646439007SCharles.Forsyth Eopen: con "fid already opened"; 9746439007SCharles.Forsyth Enotfound: con "file does not exist"; 9846439007SCharles.Forsyth Enotdir: con "not a directory"; 9946439007SCharles.Forsyth Eperm: con "permission denied"; 10046439007SCharles.Forsyth Ebadarg: con "bad argument"; 10146439007SCharles.Forsyth Eexists: con "file already exists"; 10246439007SCharles.Forsyth Emode: con "open/create -- unknown mode"; 10346439007SCharles.Forsyth Eoffset: con "read/write -- bad offset"; 10446439007SCharles.Forsyth Ecount: con "read/write -- count negative or exceeds msgsize"; 10546439007SCharles.Forsyth Enotopen: con "read/write -- on non open fid"; 10646439007SCharles.Forsyth Eaccess: con "read/write -- not open in suitable mode"; 10746439007SCharles.Forsyth Ename: con "bad character in file name"; 10846439007SCharles.Forsyth Edot: con ". and .. are illegal names"; 10946439007SCharles.Forsyth}; 11046439007SCharles.Forsyth 11146439007SCharles.ForsythNametree: module { 11246439007SCharles.Forsyth PATH: con "/dis/lib/nametree.dis"; 11346439007SCharles.Forsyth Tree: adt { 11446439007SCharles.Forsyth c: chan of ref Treeop; 11546439007SCharles.Forsyth reply: chan of string; 11646439007SCharles.Forsyth 11746439007SCharles.Forsyth quit: fn(t: self ref Tree); 11846439007SCharles.Forsyth create: fn(t: self ref Tree, parent: big, d: Sys->Dir): string; 11946439007SCharles.Forsyth wstat: fn(t: self ref Tree, path: big, d: Sys->Dir): string; 12046439007SCharles.Forsyth remove: fn(t: self ref Tree, path: big): string; 12146439007SCharles.Forsyth getpath: fn(t: self ref Tree, path: big): string; 12246439007SCharles.Forsyth }; 12346439007SCharles.Forsyth Treeop: adt { 12446439007SCharles.Forsyth reply: chan of string; 12546439007SCharles.Forsyth q: big; 12646439007SCharles.Forsyth pick { 12746439007SCharles.Forsyth Create or 12846439007SCharles.Forsyth Wstat => 12946439007SCharles.Forsyth d: Sys->Dir; 13046439007SCharles.Forsyth Remove => 13146439007SCharles.Forsyth Getpath => 13246439007SCharles.Forsyth } 13346439007SCharles.Forsyth }; 13446439007SCharles.Forsyth init: fn(); 13546439007SCharles.Forsyth start: fn(): (ref Tree, chan of ref Styxservers->Navop); 13646439007SCharles.Forsyth}; 137