implement Jacopo; # mount {./jacopo.dis} /mnt/dave
include "sys.m";
sys: Sys;
include "draw.m";
include "styx.m";
styx: Styx;
Tmsg, Rmsg: import styx;
include "styxservers.m";
styxservers: Styxservers;
Styxserver, Navigator, readstr: import styxservers;
nametree: Nametree;
Tree: import nametree;
Jacopo: module
{
init: fn(nil: ref Draw->Context, argv: list of string);
};
Qroot, Qctl, Qdata: con big iota; # paths
init(nil: ref Draw->Context, args: list of string)
{
sys = load Sys Sys->PATH;
styx = load Styx Styx->PATH;
styx->init();
styxservers = load Styxservers Styxservers->PATH;
styxservers->init(styx);
nametree = load Nametree Nametree->PATH;
nametree->init();
sys->pctl(Sys->FORKNS, nil);
(tree, treeop) := nametree->start();
tree.create(Qroot, dir(".", 8r555|Sys->DMDIR, Qroot));
tree.create(Qroot, dir("ctl", 8r666, Qctl));
tree.create(Qroot, dir("data", 8r444, Qdata));
(tchan, srv) := Styxserver.new(sys->fildes(0), Navigator.new(treeop), Qroot);
while((gm := <-tchan) != nil) {
pick m := gm {
Write =>
(c, err) := srv.canwrite(m);
if(c == nil) {
srv.reply(ref Rmsg.Error(m.tag, err));
} else if (c.path == Qctl) {
srv.reply(ref Rmsg.Write(m.tag, len m.data));
}
Read =>
(c, err) := srv.canread(m);
if(c == nil) {
srv.reply(ref Rmsg.Error(m.tag, err));
} else if(c.path == Qdata) {
srv.reply(readstr(m, "hello"));
}
* =>
srv.default(gm);
}
}
tree.quit();
}
dir(name: string, perm: int, qid: big): Sys->Dir
{
d := sys->zerodir;
d.name = name;
d.uid = "maht";
d.gid = "maht";
d.qid.path = qid;
if (perm & Sys->DMDIR)
d.qid.qtype = Sys->QTDIR;
else
d.qid.qtype = Sys->QTFILE;
d.mode = perm;
return d;
}
|