9fans - fans of the OS Plan 9 from Bell Labs
 help / color / mirror / Atom feed
* [9fans] srv to stdin, stdout
@ 2005-05-28 14:12 Sergey Reva
  2005-05-28 16:34 ` Russ Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Sergey Reva @ 2005-05-28 14:12 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs

Hello Fans,

Is that enough to start serving with 'listen'?
mysrv.infd=0;
mysrv.outfd=1;
srv(&mysrv);

I already try this, and can see files, but can't write to them.
Same code started by 'postmountsrv' work fine.

Sergey
-- 
http://rs-rlab.narod.ru                          mailto:rs_rlab@mail.ru



^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] srv to stdin, stdout
  2005-05-28 14:12 [9fans] srv to stdin, stdout Sergey Reva
@ 2005-05-28 16:34 ` Russ Cox
  2005-05-28 17:55   ` Sergey Reva
  0 siblings, 1 reply; 4+ messages in thread
From: Russ Cox @ 2005-05-28 16:34 UTC (permalink / raw)
  To: Sergey Reva, Fans of the OS Plan 9 from Bell Labs

> Is that enough to start serving with 'listen'?
> mysrv.infd=0;
> mysrv.outfd=1;
> srv(&mysrv);
> 
> I already try this, and can see files, but can't write to them.
> Same code started by 'postmountsrv' work fine.

If you can do anything at all, then messages are
flowing in both directions.  I don't understand how
using standard input and output could break 
Twrite transactions.

Russ


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] srv to stdin, stdout
  2005-05-28 16:34 ` Russ Cox
@ 2005-05-28 17:55   ` Sergey Reva
  2005-05-28 18:24     ` Russ Cox
  0 siblings, 1 reply; 4+ messages in thread
From: Sergey Reva @ 2005-05-28 17:55 UTC (permalink / raw)
  To: Fans of the OS Plan 9 from Bell Labs, Russ Cox

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

Hello Russ,

Saturday, May 28, 2005, 7:34:42 PM, you wrote:
RC> I don't understand how
RC> using standard input and output could break 
RC> Twrite transactions.
That's only begining...
Get out initialization of infd and outfd, so both should be 0... result the same!

in one window:
cpu% aux/listen1 tcp!*!33 /usr/rlab/encsrv/xorfs -s

in another:
cpu% 9fs tcp!myfs!33
post...
cpu% cd /n/myfs!33
cpu% lc
ctl             data    enc             key
cpu% echo test >data
echo: write error: mount rpc error
cpu%

and this on 'black screen'
mnt: proc rc 193: mistmatch from /net/tcp/8/data /n/myfs!33/data rep 0x80bfd6f0 tag 8 fid 453 T120 R119

source is attached...

Sergey
-- 
http://rs-rlab.narod.ru                            mailto:rs_rlab@mail.ru

[-- Attachment #2: xorfs.c --]
[-- Type: APPLICATION/OCTET-STREAM, Size: 3867 bytes --]

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

char* srvname={"xorfs"};
char* mntpt=nil;

void myopen(Req *r);
void mywrite(Req *r);
void myread(Req *r);
void mycreate(Req *r);

enum {
	DataFile,
	CtlFile,
	KeyFile,
	EncFile,

	MAX_WORD=24,
};

char *Data=nil, *EncData=nil, *EncKey=nil;
vlong dlen, elen, klen;
int isdecoded=0, remote=0;

#define DBG print

Srv mysrv={
	.open=myopen,
	.read=myread,
	.write=mywrite,
	.create=mycreate,
};

void Crypto(char* dst, char* src, ulong dlen, char* key, ulong keylen)
{
	ulong i,n;

	for (i=0, n=0;i<dlen;i++,n++)
	{
		if (n>=keylen)
			n=0;

		dst[i]=src[i]^key[n];
	}
}

int isvalid(char* src, ulong srclen)
{
  	ulong i,j;

	for(i=0, j=0; i < srclen; i++, j++)
	{ 
		if(j>MAX_WORD)
			return 0;
		if( src[i]>' ' && src[i]<='~')
			continue;
		if( src[i] == ' ' || src[i] == '\n' || src[i] == '\t' || src[i] == '\r' )
		{
			j=0;
			continue;
		}
		return 0;
	}

	return 1;
}

void mywrite(Req *r)
{
	// r->ifcall.offset
	// r->ifcall.count
	// r->ifcall.data

	switch((ulong)r->fid->file->aux)
	{
	case CtlFile:
		break;
	case DataFile:
		isdecoded=0;
		if (Data!=nil)
			free(Data);
		Data=emalloc9p(r->ifcall.count);

		if (EncData!=nil)
			free(EncData);
		EncData=emalloc9p(r->ifcall.count);

		dlen=r->ifcall.count;
		memcpy(Data, r->ifcall.data, r->ifcall.count);

		DBG("Encsrv: write %d bytes to Data\n",r->ifcall.count);
		break;
	case EncFile:
		respond(r,"permission denied");
		return;
	case KeyFile:
		isdecoded=0;
		if (EncKey!=nil)
			free(EncKey);
		EncKey=emalloc9p(r->ifcall.count);
		klen=r->ifcall.count;
		memcpy(EncKey, r->ifcall.data, r->ifcall.count);
		DBG("Encsrv: write %d bytes to KeyFile\n",r->ifcall.count);
		break;
	default:
		respond(r,"unbelievable write");
		return;
	}

	respond(r,nil);
}

void myread(Req *r)
{
	ulong n;

	switch((ulong)r->fid->file->aux)
	{
	case CtlFile:
		if (!isdecoded)
		{
			DBG("Encsrv: decoding...");			
			Crypto(EncData, Data, dlen, EncKey, klen);
			isdecoded=1;
			DBG("done\n");
		}

		if (isvalid(EncData, dlen))
			readbuf(r,"valid",5);
		else
			readbuf(r,nil,0);
		break;
	case DataFile:
		n=dlen-r->ifcall.offset;
		if (n>0)
		{
			if (n>r->ifcall.count)
				n=r->ifcall.count;
			readbuf(r,Data,n);
		}
		else
			readbuf(r,Data,0);
		break;
	case EncFile:
		if (!isdecoded)
		{
			DBG("Encsrv: decoding...");			
			Crypto(EncData, Data, dlen, EncKey, klen);
			isdecoded=1;
			DBG("done\n");
		}

		n=dlen-r->ifcall.offset;
		if (n>0)
		{
			if (n>r->ifcall.count)
				n=r->ifcall.count;
			readbuf(r,EncData,n);
		}
		else
			readbuf(r,EncData,0);
		break;
	case KeyFile:
		n=klen-r->ifcall.offset;
		if (n>0)
		{
			if (n>r->ifcall.count)
				n=r->ifcall.count;
			readbuf(r,EncKey,n);
		}
		else
			readbuf(r,EncKey,0);
		break;
	default:
		respond(r,"unbelievable read");
		return;
	}

	respond(r,nil);
}

void myopen(Req *r)
{
	respond(r,nil);
}

void mycreate(Req *r)
{
	respond(r,"permission denied");
}

void main(int argc, char *argv[])
{

	ARGBEGIN {
	case 'm':
		mntpt=ARGF();
		break;
	case 'D':
		chatty9p++;
		break;
	case 's':
		remote++;
		break;
	default:
		print("usage %s -m mntpnt -s\n",argv[0]);
		exits(0);
		break;
	} ARGEND

	mysrv.tree=alloctree(nil,nil,DMDIR|0777,nil);
	createfile(mysrv.tree->root,"data",nil,0666,(void*)DataFile);
	createfile(mysrv.tree->root,"ctl",nil,0666,(void*)CtlFile);
	createfile(mysrv.tree->root,"key",nil,0666,(void*)KeyFile);
	createfile(mysrv.tree->root,"enc",nil,0666,(void*)EncFile);

	if (remote)
	{
		srv(&mysrv);
	}
	else
	{
		postmountsrv(&mysrv,srvname,mntpt,MREPL|MCREATE);
	}

	exits(0);
}

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [9fans] srv to stdin, stdout
  2005-05-28 17:55   ` Sergey Reva
@ 2005-05-28 18:24     ` Russ Cox
  0 siblings, 0 replies; 4+ messages in thread
From: Russ Cox @ 2005-05-28 18:24 UTC (permalink / raw)
  To: Sergey Reva; +Cc: Fans of the OS Plan 9 from Bell Labs

Oh, of course.  If you're using stdin and stdout for
9P conversations, then you can't also print
debugging messages to standard out.  The
kernel will think they are 9P messages and get all
confused.

Russ


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2005-05-28 18:24 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-05-28 14:12 [9fans] srv to stdin, stdout Sergey Reva
2005-05-28 16:34 ` Russ Cox
2005-05-28 17:55   ` Sergey Reva
2005-05-28 18:24     ` Russ Cox

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