9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
From: Kin Loo <kinloo1988@gmail.com>
To: 9fans@9fans.net
Subject: [9fans] a 9P session between debian client and Plan 9 server side
Date: Tue,  3 Jan 2012 10:49:43 +0000	[thread overview]
Message-ID: <db4117e9-e216-494e-b27c-e71634a2121d@v24g2000prn.googlegroups.com> (raw)

Hi, this time I want to try a 9P session in debian. The following code
is running at Plan 9 and file operations (cat, touch, echo>, and rm)
for the Plan 9 client function as expected:

#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <auth.h>
#include <9p.h>

typedef struct	Ramfile	Ramfile;
struct Ramfile {
	char	*data;
	int	ndata;
};

void
fsread(Req *r)
{
	Ramfile	*rf;
	int	count;
	long	offset;

	count = r->ifcall.count;
	offset = r->ifcall.offset;
	rf = r->fid->file->aux;

	if(offset >= rf->ndata) {
		r->ofcall.count = 0;
		respond(r, nil);
		return;
	}
	if(offset+count >= rf->ndata)
		count = rf->ndata - offset;

	memmove(r->ofcall.data, rf->data, count);
	r->ofcall.count = count;
	respond(r, nil);
}

void
fswrite(Req *r)
{
	Ramfile	*rf;
	int	count;
	long	offset;

	rf =  r->fid->file->aux;
	count = r->ifcall.count;
	offset = r->ifcall.offset;

	void *v;
	if(offset+count >= rf->ndata) {
		v = realloc(rf->data, offset+count);
		if(v == nil) {
			respond(r, "realloc bad");
			return;
		}

		rf->ndata = offset+count;
		rf->data = v;
		r->fid->file->length = rf->ndata;
	}

	memmove(rf->data, r->ifcall.data, count);
	r->ofcall.count = count;
	respond(r, nil);
}

void
fscreate(Req *r)
{
	Ramfile	*rf;
	File	*f;

	f = createfile(r->fid->file, r->ifcall.name, r->fid->uid, r-
>ifcall.perm, nil);
	if(f) {
		rf = emalloc9p(sizeof *rf);
		f->aux = rf;
		r->fid->file = f;
		r->ofcall.qid = f->qid;
		respond(r, nil);
		return;
	}

	respond(r, "bad file creation");
}

Srv fs = {
	.read =	fsread,
	.write =	fswrite,
	.create = 	fscreate,
};


void
usage(void)
{
	fprint(2, "usage: %s [-s srvname] [-m mtpt]\n", argv0);
	exits("usage");
}

void
main(int argc, char **argv)
{
	char	*srvname;
	char	*mtpt;
	Tree	*tree;

 	srvname = "memfs";
 	mtpt = nil;
 	tree = alloctree(nil, nil, DMDIR|0777, nil);
 	fs.tree = tree;
	ARGBEGIN{
	case 'm':
		mtpt = EARGF(usage());
		break;
	case 's':
		srvname = ARGF();
		break;
	default:
		usage();
	}ARGEND;

	if(argc)
		usage();

	Ramfile	*rf;
	rf = emalloc9p(sizeof *rf);
	createfile(tree->root, "foo", nil, 0666, rf);

	if(srvname || mtpt)
		postmountsrv(&fs, srvname, mtpt, MREPL|MCREATE);

	exits(0);
}


In Plan 9, it announces an address through TCP:

   longy# aux/listen1 -tv tcp!*!1114 /bin/exportfs -S /srv/memfs &

Now I drop lines in debian console and cd to mount point:

   kin@debian:~$ sudo mount -t 9p 192.168.1.180 /tmp/memfs/ -o
port=1114
   kin@debian:~$ cd /tmp/memfs
   kin@debian:/tmp/memfs$ ls -l
   total 1
   -rw-rw-rw- 1 4294967294 4294967294 6 Jan  3 08:52 foo
   kin@debian:/tmp/memfs$ echo abcd >foo
   bash: foo: Operation not permitted
   kin@debian:/tmp/memfs$ touch junk
   touch: cannot touch `junk': Unknown error 526
   kin@debian:/tmp/memfs$

CATing and RMing files  are OK. But why I cannot create and write to
9P file in linux?

Thanks,
kin



             reply	other threads:[~2012-01-03 10:49 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-01-03 10:49 Kin Loo [this message]
2012-01-03 12:50 ` Yaroslav
2012-01-03 14:59 ` andrey mirtchovski
2012-01-05 10:07 ` Kin Loo

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=db4117e9-e216-494e-b27c-e71634a2121d@v24g2000prn.googlegroups.com \
    --to=kinloo1988@gmail.com \
    --cc=9fans@9fans.net \
    /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).