~amavect/makeu

b9d0d464e44aed76ed6af4337482b7ad00b94796 — amavect 1 year, 6 months ago 3be6d56
delete the file server
3 files changed, 2 insertions(+), 221 deletions(-)

D fs.c
M makeu.c
M mkfile
D fs.c => fs.c +0 -196
@@ 1,196 0,0 @@
/* Amavect! */
/* file interface to makeu */
#include <u.h>
#include <libc.h>
#include <fcall.h>
#include <thread.h>
#include <9p.h>
#include <draw.h>
#include "com.h"

enum {
	Qroot,
	Qcolor,
};

typedef struct F {
	char *name;
	Qid qid;
	ulong perm;
} F;

char *user;
Channel *colorc;
extern ulong color;

F rootf = {"/", {Qroot, 0, QTDIR}, 0555|DMDIR};
F colorf = {"color", {Qcolor, 0, QTFILE}, 0666};

F *
filebypath(uvlong path)
{
	if(path == Qroot)
		return &rootf;
	else
		return &colorf;
}

void 
fsattach(Req *r)
{
	r->fid->qid = filebypath(Qroot)->qid;
	r->ofcall.qid = r->fid->qid;
	respond(r, nil);
}

char *
fswalk1(Fid *fid, char *name, Qid *qid)
{
	if(fid->qid.path == Qroot){
		if(strcmp(name, colorf.name) == 0){
			*qid = colorf.qid;
			fid->qid = *qid;
			return nil;
		}else if(strcmp(name, "..") == 0){
			*qid = rootf.qid;
			fid->qid = *qid;
			return nil;
		}	
	}
	return "not found";
}

void
fillstat(Dir *d, uvlong path)
{
	F *f;
	
	f = filebypath(path);
	d->qid = f->qid;	/* unique id from server */
	d->mode = f->perm;	/* permissions */
	d->atime = time(0);	/* last read time */
	d->mtime = time(0);	/* last write time */
	d->length = 0;	/* file length */
	d->name = estrdup9p(f->name);	/* last element of path */
	d->uid = estrdup9p(user);	/* owner name */
	d->gid = estrdup9p(user);	/* group name */
	d->muid = estrdup9p(user);	/* last modifier name */
}

void
fsstat(Req *r)
{
	fillstat(&r->d, r->fid->qid.path);
	respond(r, nil);
}

int
rootgen(int n, Dir *d, void *)
{
	if(n >= 1)
		return -1;
	fillstat(d, colorf.qid.path);
	return 0;
}

void
fsopen(Req *r)
{
	uchar *hasread;
	
	if(r->fid->qid.path == Qcolor){
		hasread = emalloc9p(sizeof(uchar));
		*hasread = 0;
		r->fid->aux = hasread;
	}
	respond(r, nil);
}

void
fsread(Req *r)
{
	uvlong path;
	uchar *hasread;
	char buf[12];
	
	path = r->fid->qid.path;
	if(path == Qroot){
		dirread9p(r, rootgen, nil);
		respond(r, nil);
		return;
	}else if(path == Qcolor){
		hasread = r->fid->aux;
		if(*hasread == 1){
			r->ofcall.count = 0;
			respond(r, nil);
			return;
		}
		if(r->ifcall.count < 11){
			respond(r, "read buffer too small");
			return;
		}
		snprint(buf, r->ifcall.count, "0x%08ulX\n", color);
		r->ofcall.count = 11;
		memcpy(r->ofcall.data, buf, 11);
		*hasread += 1;
		respond(r,nil);
	}else{
		respond(r, "what");
	}
}

void
fswrite(Req *r)
{
	char buf[11];
	ulong incolor, n;
	
	if(r->fid->qid.path == Qroot)
		respond(r, "Cannot write to there!");
	if(r->ifcall.count < 10){
		r->ofcall.count = 0;
		respond(r, "color rejected, write buffer too small");
		return;
	}
	r->ofcall.count = r->ifcall.count; /* ignore further bytes */
	n = r->ifcall.count < sizeof(buf) ? r->ifcall.count : sizeof(buf);
	memcpy(buf, r->ifcall.data, n);
	buf[10] = '\0';
	incolor = strtocolor(buf);
	if(incolor == DNotacolor){
		respond(r, "color rejected, not a color");
		return;
	}
	sendul(colorc, incolor);
	respond(r, nil);
}

void
fsdestroyfid(Fid *fid)
{
	free(fid->aux);
}

Srv fs = {
	.attach = fsattach,
	.walk1 = fswalk1,
	.stat = fsstat,
	.open = fsopen,
	.read = fsread,
	.write = fswrite,
	.destroyfid = fsdestroyfid,
};

Channel *
init9pfs(char *mtpt, char *srv, int c9p)
{
	chatty9p = c9p;
	colorc = chancreate(sizeof(ulong), 1);
	user = getuser();
	if(mtpt == nil)
		mtpt = "/mnt/makeu";
	if(srv == nil)
		srv = smprint("makeu.%s.%d", user, getpid());
	threadpostmountsrv(&fs, srv, mtpt, MREPL);
	return colorc;
}

M makeu.c => makeu.c +1 -24
@@ 302,13 302,7 @@ threadmain(int argc, char **argv)
	Mousectl *mctl;
	Mouse m;
	ulong incolor;
	Channel *fsc;
	char *mtpt, *srv;
	int c9p;
	
	mtpt = nil;
	srv = nil;
	c9p = 0;
	incolor = 0xFFFFFFFF;
	ARGBEGIN{
	case 'p':


@@ 319,15 313,6 @@ threadmain(int argc, char **argv)
		if(incolor == DNotacolor)
			incolor = 0xFFFFFFFF;
		break;
	case 'm':
		mtpt = EARGF(usage());
		break;
	case 's':
		srv = EARGF(usage());
		break;
	case 'D':
		c9p++;
		break;
	default:
		usage();
	}ARGEND;


@@ 340,7 325,6 @@ threadmain(int argc, char **argv)
		sysfatal("%r");
	if((kctl = initkeyboard(nil)) == nil)
		sysfatal("%r");
	fsc = init9pfs(mtpt, srv, c9p);
	spa.mctl = mctl;
	hsva.mctl = mctl;
	


@@ 366,12 350,11 @@ threadmain(int argc, char **argv)
	root->resize(root, screenbuf->r);
	show();
	
	enum { MOUSE, RESIZE, KEYS, FS, NONE };
	enum { MOUSE, RESIZE, KEYS, NONE };
	Alt alts[] = {
		[MOUSE] =  {mctl->c, &m, CHANRCV},
		[RESIZE] =  {mctl->resizec, nil, CHANRCV},
		[KEYS] = {kctl->c, &r, CHANRCV},
		[FS] = {fsc, &incolor, CHANRCV},
		[NONE] =  {nil, nil, CHANEND}
	};
	


@@ 420,12 403,6 @@ threadmain(int argc, char **argv)
			if(r == Kdel)
				threadexitsall(nil);
			break;
		case FS:
			if(incolor == color)
				break;
			allevent(incolor);
			show();
			break;
		case NONE:
			print("I'm a woodchuck, not a woodchucker! (thanks for playing)\n");
			break;

M mkfile => mkfile +1 -1
@@ 3,7 3,7 @@
MAN=/sys/man
BIN=/$objtype/bin
HFILES=com.h components.h elementile.h
OFILES=com.$O guipart.$O makeu.$O hsvmap.$O screenpick.$O slider.$O fs.$O
OFILES=com.$O guipart.$O makeu.$O hsvmap.$O screenpick.$O slider.$O
TARG=$BIN/makeu
MANFILES=$MAN/1/makeu