9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: rog@vitanuova.com
To: 9fans@cse.psu.edu
Subject: Re: [9fans] cdrom floppy tape etc, media mount point
Date: Thu, 18 Jul 2002 12:19:48 +0100	[thread overview]
Message-ID: <0f792b91b09d76e24a48e6763d389ed6@vitanuova.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 324 bytes --]

> >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.

[-- Attachment #2.1: Type: text/plain, Size: 309 bytes --]

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

[-- Attachment #2.2: autodir.b.suspect --]
[-- Type: application/octet-stream, Size: 3169 bytes --]

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;
}

             reply	other threads:[~2002-07-18 11:19 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-07-18 11:19 rog [this message]
  -- strict thread matches above, loose matches on Subject: below --
2002-07-30 11:45 Russ Cox
2002-07-16 16:09 rog
2002-07-16 15:35 rog
2002-07-16 14:42 ` Sam
2002-07-16 15:39 ` Scott Schwartz
2002-07-16 13:34 rog
2002-07-16 15:19 ` Scott Schwartz
2002-07-18  9:50 ` Ben
2002-07-18 16:06   ` Jack Johnson
2002-07-16  7:39 Fco.J.Ballesteros
2002-07-15 16:45 rog
2002-07-15 16:02 ` Sam
2002-07-15 16:52 ` Lucio De Re
2002-07-15 19:21 ` Scott Schwartz
2002-07-16 12:26 ` Martin C.Atkins
2002-07-15 16:33 okamoto
2002-07-12 16:16 anothy
2002-07-12 10:44 okamoto
2002-07-12 10:37 Fco.J.Ballesteros
2002-07-12 10:32 okamoto
2002-07-12 10:20 Fco.J.Ballesteros
2002-07-15  9:30 ` Ben
2002-07-12 10:15 okamoto
2002-07-12  7:40 Fco.J.Ballesteros
2002-07-12  2:47 okamoto
2002-07-12  2:17 anothy
2002-07-12  2:07 okamoto
2002-07-12  9:03 ` Don

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=0f792b91b09d76e24a48e6763d389ed6@vitanuova.com \
    --to=rog@vitanuova.com \
    --cc=9fans@cse.psu.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).