From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: <0f792b91b09d76e24a48e6763d389ed6@vitanuova.com> To: 9fans@cse.psu.edu Subject: Re: [9fans] cdrom floppy tape etc, media mount point From: rog@vitanuova.com MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="upas-jmwetthwxelpmvglmjhxuvqhiq" Date: Thu, 18 Jul 2002 12:19:48 +0100 Topicbox-Message-UUID: cfdaa3d4-eaca-11e9-9e20-41e7f4b1d025 This is a multi-part message in MIME format. --upas-jmwetthwxelpmvglmjhxuvqhiq Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit > >i recently knocked up a little filesystem as in inferno as an [...] > Care to share your code with us? sure. it won't do you much good though, as the support modules don't exist under the current version of inferno (and aren't compatible either). still, it might be of interest to some. attached. rog. --upas-jmwetthwxelpmvglmjhxuvqhiq Content-Type: multipart/mixed; boundary="upas-foowfqbqtedqsbtgjslopvgrun" Content-Disposition: inline This is a multi-part message in MIME format. --upas-foowfqbqtedqsbtgjslopvgrun Content-Disposition: inline Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit The following attachment had content that we can't prove to be harmless. To avoid possible automatic execution, we changed the content headers. The original header was: Content-Disposition: attachment; filename=autodir.b Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit --upas-foowfqbqtedqsbtgjslopvgrun Content-Type: application/octet-stream Content-Disposition: attachment; filename="autodir.b.suspect" implement Tst; include "sys.m"; sys: Sys; include "draw.m"; include "styx.m"; Rmsg: import Styx; include "styxservers.m"; styxservers: Styxservers; Ebadfid, Enotfound, Eexists, Eperm: import Styxservers; Styxserver, Filetree, readbytes: import styxservers; include "simplefs.m"; simplefs: SimpleFS; Fs: import simplefs; Tst: module { init: fn(nil: ref Draw->Context, argv: list of string); }; Qroot: con big 16rfffffff; badmodule(p: string) { sys->fprint(sys->fildes(2), "cannot load %s: %r\n", p); sys->raise("fail:bad module"); } DEBUG: con 0; refcounts := array[10] of int; init(nil: ref Draw->Context, nil: list of string) { sys = load Sys Sys->PATH; styxservers = load Styxservers Styxservers->PATH; if (styxservers == nil) badmodule(Styxservers->PATH); styxservers->init(); simplefs = load SimpleFS SimpleFS->PATH; if (simplefs == nil) badmodule(SimpleFS->PATH); simplefs->init(); (fs, fsop) := simplefs->start(); (tchan, srv) := Styxserver.new(sys->fildes(0), Filetree.new(fsop), Qroot); fs.create(Qroot, dir(".", Sys->DMDIR | 8r555, Qroot)); for (;;) { gm := <-tchan; if (gm == nil) { fs.quit(); exit; } e := handlemsg(gm, srv, fs); if (e != nil) srv.reply(ref Rmsg.Error(gm.tag, e)); } } handlemsg(gm: ref Styx->Tmsg, srv: ref Styxserver, fs: ref Fs): string { pick m := gm { Walk => # allow walk to any name from root, otherwise nothing. # if name did not already exist, we create it and refcount it. if (m.name == "..") { c := srv.getfid(m.fid); if (c != nil && c.qid != Qroot) decref(c.qid, fs); srv.walk(m); return nil; } c := srv.getfid(m.fid); if (c == nil) return Ebadfid; if (c.qid != Qroot) return Enotfound; (d, nil) := srv.t.walk(Qroot, m.name); if (d == nil) d = addentry(m.name, fs); else incref(c.qid); c.isdir = d.qid.qtype & Sys->QTDIR; c.qid = d.qid.path; srv.reply(ref Rmsg.Walk(m.tag, m.fid, d.qid)); Clone => c := srv.clone(m); if (c != nil && c.qid != Qroot) incref(c.qid); Clunk => c := srv.clunk(m); if (c != nil && c.qid != Qroot) decref(c.qid, fs); * => srv.default(gm); } return nil; } addentry(name: string, fs: ref Fs): ref Sys->Dir { for (i := 0; i < len refcounts; i++) if (refcounts[i] == 0) break; if (i == len refcounts) { refcounts = (array[len refcounts * 2] of int)[0:] = refcounts; for (j := i; j < len refcounts; j++) refcounts[j] = 0; } d := dir(name, Sys->DMDIR|8r555, big i); fs.create(Qroot, d); refcounts[i] = 1; return ref d; } incref(q: big) { id := int q; if (id >= 0 && id < len refcounts) refcounts[id]++; } decref(q: big, fs: ref Fs) { id := int q; if (id >= 0 && id < len refcounts) if (--refcounts[id] == 0) fs.remove(big id); } Blankdir: Sys->Dir; dir(name: string, perm: int, qid: big): Sys->Dir { d := Blankdir; d.name = name; d.uid = "me"; d.gid = "me"; d.qid.path = qid; if (perm & Sys->DMDIR) d.qid.qtype = Sys->QTDIR; else d.qid.qtype = Sys->QTFILE; d.mode = perm; return d; } --upas-foowfqbqtedqsbtgjslopvgrun-- --upas-jmwetthwxelpmvglmjhxuvqhiq--