~foura/midifs

efc223ad0bb630e20e074b16c7ef2b1e686f6382 — james palmer 2 months ago 684eb94
implement raw reads and writes to the device.
1 files changed, 30 insertions(+), 2 deletions(-)

M main.c
M main.c => main.c +30 -2
@@ 10,6 10,7 @@ enum {
	Qroot,
		Qctl,
		Qmidi,
		Qraw,
};

typedef struct Dirtab Dirtab;


@@ 21,8 22,9 @@ struct Dirtab {

Dirtab root = { "/", {Qroot, 0, QTDIR}, 0555|DMDIR };
Dirtab roottab[] = {
	"ctl",  {Qctl, 0, QTFILE},  0444,
	"ctl",  {Qctl,  0, QTFILE}, 0444,
	"midi", {Qmidi, 0, QTFILE}, 0444,
	"raw",  {Qraw,  0, QTFILE}, 0444,
};

Dirtab*


@@ 79,13 81,26 @@ fsattach(Req *r)
void
fsread(Req *r)
{
	Midi *dev = r->srv->aux;
	uvlong path = r->fid->qid.path;
	long count;
	
	switch(path) {
	case Qroot:
		dirread9p(r, rootgen, r);
		respond(r, nil);
		return;
		break;
	case Qraw:
		/* FIXME: this may block the srv loop */
		count = read(dev->fd, r->ofcall.data, r->ifcall.count);
		if(count < 0) {
			respond(r, "couldn't read from device");
			break;
		}

		r->ofcall.count = count;
		respond(r, nil);
		break;
	default:
		respond(r, "no.");
	}


@@ 94,9 109,22 @@ fsread(Req *r)
void
fswrite(Req *r)
{
	Midi *dev = r->srv->aux;
	uvlong path = r->fid->qid.path;
	long count;

	switch(path) {
	case Qraw:
		/* FIXME: this may block the srv loop */
		count = write(dev->fd, r->ifcall.data, r->ifcall.count);
		if(count < 0) {
			respond(r, "couldn't write to device");
			break;
		}

		r->ofcall.count = count;
		respond(r, nil);
		break;
	default:
		respond(r, "no.");
	}