libixp

git clone git://oldgit.suckless.org/libixp/
Log | Files | Refs | LICENSE

commit 2b043c8fb3bfd8cab913c376919db0ae8fcf7b61
parent 699b4f8cc0d0451e87c381140cd5685949e5347a
Author: Kris Maglione <jg@suckless.org>
Date:   Sun, 25 May 2008 17:14:46 -0400

Make IxpFcall c99 friendly (but, maintain backward compatibility, for now).

Diffstat:
include/ixp.h | 122+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
libixp/Makefile | 6++++--
libixp/client.c | 117+++++++++++++++++++++++++++++++++++++++++--------------------------------------
libixp/message.c | 106++++++++++++++++++++++++++++++++++++++++----------------------------------------
libixp/request.c | 123+++++++++++++++++++++++++++++++++++++++++++------------------------------------
libixp/rpc.c | 6+++---
mk/dir.mk | 29++++++++++++++++-------------
mk/gcc.mk | 1-
mk/hdr.mk | 4++--
9 files changed, 325 insertions(+), 189 deletions(-)

diff --git a/include/ixp.h b/include/ixp.h @@ -7,7 +7,7 @@ #include <sys/types.h> #include <sys/select.h> -#define IXP_API 89 +#define IXP_API 90 /* Gunk */ #if defined(IXP_NEEDAPI) && IXP_API < IXP_NEEDAPI @@ -33,10 +33,11 @@ #ifdef KENC # define STRUCT(x) struct {x}; # define UNION(x) union {x}; -#elif defined(__GNUC__) && !defined(IXPlint) +#elif defined(__GNUC__) # define STRUCT(x) __extension__ struct {x}; # define UNION(x) __extension__ union {x}; #else +# define IXP_NEEDAPI 89 # define STRUCT(x) x # define UNION(x) x #endif @@ -222,7 +223,6 @@ typedef struct Ixp9Srv Ixp9Srv; typedef struct IxpCFid IxpCFid; typedef struct IxpClient IxpClient; typedef struct IxpConn IxpConn; -typedef struct IxpFcall IxpFcall; typedef struct IxpFid IxpFid; typedef struct IxpMsg IxpMsg; typedef struct IxpQid IxpQid; @@ -271,7 +271,94 @@ struct IxpQid { uchar dir_type; }; +typedef struct IxpFHdr IxpFHdr; +typedef struct IxpFError IxpFError; +typedef struct IxpFROpen IxpFRAttach; +typedef struct IxpFRAuth IxpFRAuth; +typedef struct IxpFROpen IxpFRCreate; +typedef struct IxpFROpen IxpFROpen; +typedef struct IxpFIO IxpFRRead; +typedef struct IxpFRStat IxpFRStat; +typedef struct IxpFVersion IxpFRVersion; +typedef struct IxpFRWalk IxpFRWalk; +typedef struct IxpFAttach IxpFTAttach; +typedef struct IxpFAttach IxpFTAuth; +typedef struct IxpFTCreate IxpFTCreate; +typedef struct IxpFTFlush IxpFTFlush; +typedef struct IxpFTCreate IxpFTOpen; +typedef struct IxpFIO IxpFTRead; +typedef struct IxpFVersion IxpFTVersion; +typedef struct IxpFTWalk IxpFTWalk; +typedef struct IxpFIO IxpFTWrite; +typedef struct IxpFRStat IxpFTWstat; +typedef struct IxpFAttach IxpFAttach; +typedef struct IxpFIO IxpFIO; +typedef struct IxpFVersion IxpFVersion; + +struct IxpFHdr { + uchar type; + ushort tag; + ulong fid; +}; +struct IxpFVersion { + IxpFHdr hdr; + ulong msize; + char* version; +}; +struct IxpFTFlush { + IxpFHdr hdr; + ushort oldtag; +}; +struct IxpFError { + IxpFHdr hdr; + char* ename; +}; +struct IxpFROpen { + IxpFHdr hdr; + IxpQid qid; /* +Rattach */ + ulong iounit; +}; +struct IxpFRAuth { + IxpFHdr hdr; + IxpQid aqid; +}; +struct IxpFAttach { + IxpFHdr hdr; + ulong afid; + char* uname; + char* aname; +}; +struct IxpFTCreate { + IxpFHdr hdr; + ulong perm; + char* name; + uchar mode; /* +Topen */ +}; +struct IxpFTWalk { + IxpFHdr hdr; + ulong newfid; + ushort nwname; + char* wname[IXP_MAX_WELEM]; +}; +struct IxpFRWalk { + IxpFHdr hdr; + ushort nwqid; + IxpQid wqid[IXP_MAX_WELEM]; +}; +struct IxpFIO { + IxpFHdr hdr; + uvlong offset; /* Tread, Twrite */ + ulong count; /* Tread, Twrite, Rread */ + char* data; /* Twrite, Rread */ +}; +struct IxpFRStat { + IxpFHdr hdr; + ushort nstat; + uchar* stat; +}; +#if defined(IXP_NEEDAPI) && IXP_NEEDAPI <= 89 /* from fcall(3) in plan9port */ +typedef struct IxpFcall IxpFcall; struct IxpFcall { uchar type; ushort tag; @@ -325,6 +412,34 @@ struct IxpFcall { ) ) }; +#else +typedef union IxpFcall IxpFcall; +union IxpFcall { + IxpFHdr hdr; + IxpFVersion version; + IxpFVersion tversion; + IxpFVersion rversion; + IxpFTFlush tflush; + IxpFROpen ropen; + IxpFROpen rcreate; + IxpFROpen rattach; + IxpFError error; + IxpFRAuth rauth; + IxpFAttach tattach; + IxpFAttach tauth; + IxpFTCreate tcreate; + IxpFTCreate topen; + IxpFTWalk twalk; + IxpFRWalk rwalk; + IxpFRStat twstat; + IxpFRStat rstat; + IxpFIO twrite; + IxpFIO rwrite; + IxpFIO tread; + IxpFIO rread; + IxpFIO io; +}; +#endif /* stat structure */ struct IxpStat { @@ -484,6 +599,7 @@ struct IxpThread { extern IxpThread *ixp_thread; extern int (*ixp_vsnprint)(char*, int, const char*, va_list); extern char* (*ixp_vsmprint)(const char*, va_list); +extern void (*ixp_printfcall)(Fcall*); /* thread_*.c */ int ixp_taskinit(void); diff --git a/libixp/Makefile b/libixp/Makefile @@ -1,14 +1,16 @@ ROOT= .. -include ${ROOT}/mk/hdr.mk -include ${ROOT}/mk/ixp.mk +include $(ROOT)/mk/hdr.mk +include $(ROOT)/mk/ixp.mk TARG = libixp +CFLAGS += -I $(ROOT)/../wmii/include OBJ = client \ convert \ error \ intmap \ message \ + print \ request \ rpc \ server \ diff --git a/libixp/client.c b/libixp/client.c @@ -69,11 +69,11 @@ dofcall(IxpClient *c, Fcall *fcall) { ret = muxrpc(c, fcall); if(ret == nil) return 0; - if(ret->type == RError) { - werrstr("%s", ret->ename); + if(ret->hdr.type == RError) { + werrstr("%s", ret->error.ename); goto fail; } - if(ret->type != (fcall->type^1)) { + if(ret->hdr.type != (fcall->hdr.type^1)) { werrstr("received mismatched fcall"); goto fail; } @@ -155,16 +155,17 @@ ixp_mountfd(int fd) { c->mintag = IXP_NOTAG; c->maxtag = IXP_NOTAG+1; - fcall.type = TVersion; - fcall.msize = IXP_MAX_MSG; - fcall.version = IXP_VERSION; + fcall.hdr.type = TVersion; + fcall.version.msize = IXP_MAX_MSG; + fcall.version.version = IXP_VERSION; if(dofcall(c, &fcall) == 0) { ixp_unmount(c); return nil; } - if(strcmp(fcall.version, IXP_VERSION) || fcall.msize > IXP_MAX_MSG) { + if(strcmp(fcall.version.version, IXP_VERSION) + || fcall.version.msize > IXP_MAX_MSG) { werrstr("bad 9P version response"); ixp_unmount(c); return nil; @@ -172,16 +173,16 @@ ixp_mountfd(int fd) { c->mintag = 0; c->maxtag = 255; - c->msize = fcall.msize; + c->msize = fcall.version.msize; - allocmsg(c, fcall.msize); + allocmsg(c, fcall.version.msize); ixp_freefcall(&fcall); - fcall.type = TAttach; - fcall.fid = RootFid; - fcall.afid = IXP_NOFID; - fcall.uname = getenv("USER"); - fcall.aname = ""; + fcall.hdr.type = TAttach; + fcall.hdr.fid = RootFid; + fcall.tattach.afid = IXP_NOFID; + fcall.tattach.uname = getenv("USER"); + fcall.tattach.aname = ""; if(dofcall(c, &fcall) == 0) { ixp_unmount(c); return nil; @@ -223,19 +224,23 @@ walk(IxpClient *c, const char *path) { int n; p = estrdup(path); - n = tokenize(fcall.wname, nelem(fcall.wname), p, '/'); + n = tokenize(fcall.twalk.wname, nelem(fcall.twalk.wname), p, '/'); f = getfid(c); - fcall.type = TWalk; - fcall.fid = RootFid; - fcall.nwname = n; - fcall.newfid = f->fid; + fcall.hdr.type = TWalk; + fcall.hdr.fid = RootFid; + fcall.twalk.nwname = n; + fcall.twalk.newfid = f->fid; if(dofcall(c, &fcall) == 0) goto fail; - if(fcall.nwqid < n) + if(fcall.rwalk.nwqid < n) { + werrstr("File does not exist"); + if(fcall.rwalk.nwqid == 0) + werrstr("Protocol botch"); goto fail; + } - f->qid = fcall.wqid[n-1]; + f->qid = fcall.rwalk.wqid[n-1]; ixp_freefcall(&fcall); free(p); @@ -274,8 +279,8 @@ clunk(IxpCFid *f) { c = f->client; - fcall.type = TClunk; - fcall.fid = f->fid; + fcall.hdr.type = TClunk; + fcall.hdr.fid = f->fid; ret = dofcall(c, &fcall); if(ret) putfid(f); @@ -304,8 +309,8 @@ ixp_remove(IxpClient *c, const char *path) { if((f = walk(c, path)) == nil) return 0; - fcall.type = TRemove; - fcall.fid = f->fid;; + fcall.hdr.type = TRemove; + fcall.hdr.fid = f->fid;; ret = dofcall(c, &fcall); ixp_freefcall(&fcall); putfid(f); @@ -317,10 +322,10 @@ static void initfid(IxpCFid *f, Fcall *fcall) { f->open = 1; f->offset = 0; - f->iounit = fcall->iounit; - if(f->iounit == 0 || fcall->iounit > f->client->msize-24) + f->iounit = fcall->ropen.iounit; + if(f->iounit == 0 || fcall->ropen.iounit > f->client->msize-24) f->iounit = f->client->msize-24; - f->qid = fcall->qid; + f->qid = fcall->ropen.qid; } /** @@ -357,11 +362,11 @@ ixp_create(IxpClient *c, const char *path, uint perm, uchar mode) { if(f == nil) goto done; - fcall.type = TCreate; - fcall.fid = f->fid; - fcall.name = (char*)(uintptr_t)path; - fcall.perm = perm; - fcall.mode = mode; + fcall.hdr.type = TCreate; + fcall.hdr.fid = f->fid; + fcall.tcreate.name = (char*)(uintptr_t)path; + fcall.tcreate.perm = perm; + fcall.tcreate.mode = mode; if(dofcall(c, &fcall) == 0) { clunk(f); @@ -388,9 +393,9 @@ ixp_open(IxpClient *c, const char *path, uchar mode) { if(f == nil) return nil; - fcall.type = TOpen; - fcall.fid = f->fid; - fcall.mode = mode; + fcall.hdr.type = TOpen; + fcall.hdr.fid = f->fid; + fcall.topen.mode = mode; if(dofcall(c, &fcall) == 0) { clunk(f); @@ -425,12 +430,12 @@ _stat(IxpClient *c, ulong fid) { Fcall fcall; Stat *stat; - fcall.type = TStat; - fcall.fid = fid; + fcall.hdr.type = TStat; + fcall.hdr.fid = fid; if(dofcall(c, &fcall) == 0) return nil; - msg = ixp_message((char*)fcall.stat, fcall.nstat, MsgUnpack); + msg = ixp_message((char*)fcall.rstat.stat, fcall.rstat.nstat, MsgUnpack); stat = emalloc(sizeof *stat); ixp_pstat(&msg, stat); @@ -487,21 +492,21 @@ _pread(IxpCFid *f, char *buf, long count, vlong offset) { while(len < count) { n = min(count-len, f->iounit); - fcall.type = TRead; - fcall.fid = f->fid; - fcall.offset = offset; - fcall.count = n; + fcall.hdr.type = TRead; + fcall.hdr.fid = f->fid; + fcall.tread.offset = offset; + fcall.tread.count = n; if(dofcall(f->client, &fcall) == 0) return -1; - if(fcall.count > n) + if(fcall.rread.count > n) return -1; - memcpy(buf+len, fcall.data, fcall.count); - offset += fcall.count; - len += fcall.count; + memcpy(buf+len, fcall.rread.data, fcall.rread.count); + offset += fcall.rread.count; + len += fcall.rread.count; ixp_freefcall(&fcall); - if(fcall.count < n) + if(fcall.rread.count < n) break; } return len; @@ -557,19 +562,19 @@ _pwrite(IxpCFid *f, const void *buf, long count, vlong offset) { len = 0; do { n = min(count-len, f->iounit); - fcall.type = TWrite; - fcall.fid = f->fid; - fcall.offset = offset; - fcall.data = (char*)buf + len; - fcall.count = n; + fcall.hdr.type = TWrite; + fcall.hdr.fid = f->fid; + fcall.twrite.offset = offset; + fcall.twrite.data = (char*)buf + len; + fcall.twrite.count = n; if(dofcall(f->client, &fcall) == 0) return -1; - offset += fcall.count; - len += fcall.count; + offset += fcall.rwrite.count; + len += fcall.rwrite.count; ixp_freefcall(&fcall); - if(fcall.count < n) + if(fcall.rwrite.count < n) break; } while(len < count); return len; diff --git a/libixp/message.c b/libixp/message.c @@ -41,22 +41,22 @@ ixp_freestat(Stat *s) { void ixp_freefcall(Fcall *fcall) { - switch(fcall->type) { + switch(fcall->hdr.type) { case RStat: - free(fcall->stat); - fcall->stat = nil; + free(fcall->rstat.stat); + fcall->rstat.stat = nil; break; case RRead: - free(fcall->data); - fcall->data = nil; + free(fcall->rread.data); + fcall->rread.data = nil; break; case RVersion: - free(fcall->version); - fcall->version = nil; + free(fcall->version.version); + fcall->version.version = nil; break; case RError: - free(fcall->ename); - fcall->ename = nil; + free(fcall->error.ename); + fcall->error.ename = nil; break; } } @@ -77,92 +77,92 @@ ixp_sizeof_stat(Stat * stat) { void ixp_pfcall(IxpMsg *msg, Fcall *fcall) { - ixp_pu8(msg, &fcall->type); - ixp_pu16(msg, &fcall->tag); + ixp_pu8(msg, &fcall->hdr.type); + ixp_pu16(msg, &fcall->hdr.tag); - switch (fcall->type) { + switch (fcall->hdr.type) { case TVersion: case RVersion: - ixp_pu32(msg, &fcall->msize); - ixp_pstring(msg, &fcall->version); + ixp_pu32(msg, &fcall->version.msize); + ixp_pstring(msg, &fcall->version.version); break; case TAuth: - ixp_pu32(msg, &fcall->afid); - ixp_pstring(msg, &fcall->uname); - ixp_pstring(msg, &fcall->aname); + ixp_pu32(msg, &fcall->tauth.afid); + ixp_pstring(msg, &fcall->tauth.uname); + ixp_pstring(msg, &fcall->tauth.aname); break; case RAuth: - ixp_pqid(msg, &fcall->aqid); + ixp_pqid(msg, &fcall->rauth.aqid); break; case RAttach: - ixp_pqid(msg, &fcall->qid); + ixp_pqid(msg, &fcall->rattach.qid); break; case TAttach: - ixp_pu32(msg, &fcall->fid); - ixp_pu32(msg, &fcall->afid); - ixp_pstring(msg, &fcall->uname); - ixp_pstring(msg, &fcall->aname); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu32(msg, &fcall->tattach.afid); + ixp_pstring(msg, &fcall->tattach.uname); + ixp_pstring(msg, &fcall->tattach.aname); break; case RError: - ixp_pstring(msg, &fcall->ename); + ixp_pstring(msg, &fcall->error.ename); break; case TFlush: - ixp_pu16(msg, &fcall->oldtag); + ixp_pu16(msg, &fcall->tflush.oldtag); break; case TWalk: - ixp_pu32(msg, &fcall->fid); - ixp_pu32(msg, &fcall->newfid); - ixp_pstrings(msg, &fcall->nwname, fcall->wname); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu32(msg, &fcall->twalk.newfid); + ixp_pstrings(msg, &fcall->twalk.nwname, fcall->twalk.wname); break; case RWalk: - ixp_pqids(msg, &fcall->nwqid, fcall->wqid); + ixp_pqids(msg, &fcall->rwalk.nwqid, fcall->rwalk.wqid); break; case TOpen: - ixp_pu32(msg, &fcall->fid); - ixp_pu8(msg, &fcall->mode); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu8(msg, &fcall->topen.mode); break; case ROpen: case RCreate: - ixp_pqid(msg, &fcall->qid); - ixp_pu32(msg, &fcall->iounit); + ixp_pqid(msg, &fcall->ropen.qid); + ixp_pu32(msg, &fcall->ropen.iounit); break; case TCreate: - ixp_pu32(msg, &fcall->fid); - ixp_pstring(msg, &fcall->name); - ixp_pu32(msg, &fcall->perm); - ixp_pu8(msg, &fcall->mode); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pstring(msg, &fcall->tcreate.name); + ixp_pu32(msg, &fcall->tcreate.perm); + ixp_pu8(msg, &fcall->tcreate.mode); break; case TRead: - ixp_pu32(msg, &fcall->fid); - ixp_pu64(msg, &fcall->offset); - ixp_pu32(msg, &fcall->count); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu64(msg, &fcall->tread.offset); + ixp_pu32(msg, &fcall->tread.count); break; case RRead: - ixp_pu32(msg, &fcall->count); - ixp_pdata(msg, &fcall->data, fcall->count); + ixp_pu32(msg, &fcall->rread.count); + ixp_pdata(msg, &fcall->rread.data, fcall->rread.count); break; case TWrite: - ixp_pu32(msg, &fcall->fid); - ixp_pu64(msg, &fcall->offset); - ixp_pu32(msg, &fcall->count); - ixp_pdata(msg, &fcall->data, fcall->count); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu64(msg, &fcall->twrite.offset); + ixp_pu32(msg, &fcall->twrite.count); + ixp_pdata(msg, &fcall->twrite.data, fcall->twrite.count); break; case RWrite: - ixp_pu32(msg, &fcall->count); + ixp_pu32(msg, &fcall->rwrite.count); break; case TClunk: case TRemove: case TStat: - ixp_pu32(msg, &fcall->fid); + ixp_pu32(msg, &fcall->hdr.fid); break; case RStat: - ixp_pu16(msg, &fcall->nstat); - ixp_pdata(msg, (char**)&fcall->stat, fcall->nstat); + ixp_pu16(msg, &fcall->rstat.nstat); + ixp_pdata(msg, (char**)&fcall->rstat.stat, fcall->rstat.nstat); break; case TWStat: - ixp_pu32(msg, &fcall->fid); - ixp_pu16(msg, &fcall->nstat); - ixp_pdata(msg, (char**)&fcall->stat, fcall->nstat); + ixp_pu32(msg, &fcall->hdr.fid); + ixp_pu16(msg, &fcall->twstat.nstat); + ixp_pdata(msg, (char**)&fcall->twstat.stat, fcall->twstat.nstat); break; } } diff --git a/libixp/request.c b/libixp/request.c @@ -10,6 +10,12 @@ static void handlereq(Ixp9Req *r); +static void +_printfcall(Fcall *f) { + USED(f); +} +void (*ixp_printfcall)(Fcall*) = _printfcall; + static int min(int a, int b) { if(a < b) @@ -123,7 +129,7 @@ handlefcall(IxpConn *c) { req->ifcall = fcall; pc->conn = c; - if(caninsertkey(&pc->tagmap, fcall.tag, req) == 0) { + if(caninsertkey(&pc->tagmap, fcall.hdr.tag, req) == 0) { respond(req, Eduptag); return; } @@ -137,6 +143,9 @@ Fail: return; } +#include <fmt.h> +int Ffmt(Fmt*); +int Gfmt(Fmt*); static void handlereq(Ixp9Req *r) { Ixp9Conn *pc; @@ -145,22 +154,24 @@ handlereq(Ixp9Req *r) { pc = r->conn; srv = pc->srv; - switch(r->ifcall.type) { + ixp_printfcall(&r->ifcall); + + switch(r->ifcall.hdr.type) { default: respond(r, Enofunc); break; case TVersion: - if(!strcmp(r->ifcall.version, "9P")) - r->ofcall.version = "9P"; - else if(!strcmp(r->ifcall.version, "9P2000")) - r->ofcall.version = "9P2000"; + if(!strcmp(r->ifcall.version.version, "9P")) + r->ofcall.version.version = "9P"; + else if(!strcmp(r->ifcall.version.version, "9P2000")) + r->ofcall.version.version = "9P2000"; else - r->ofcall.version = "unknown"; - r->ofcall.msize = r->ifcall.msize; + r->ofcall.version.version = "unknown"; + r->ofcall.version.msize = r->ifcall.version.msize; respond(r, nil); break; case TAttach: - if(!(r->fid = createfid(&pc->fidmap, r->ifcall.fid, pc))) { + if(!(r->fid = createfid(&pc->fidmap, r->ifcall.hdr.fid, pc))) { respond(r, Edupfid); return; } @@ -168,7 +179,7 @@ handlereq(Ixp9Req *r) { srv->attach(r); break; case TClunk: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -179,7 +190,7 @@ handlereq(Ixp9Req *r) { srv->clunk(r); break; case TFlush: - if(!(r->oldreq = lookupkey(&pc->tagmap, r->ifcall.oldtag))) { + if(!(r->oldreq = lookupkey(&pc->tagmap, r->ifcall.tflush.oldtag))) { respond(r, Enotag); return; } @@ -190,7 +201,7 @@ handlereq(Ixp9Req *r) { srv->flush(r); break; case TCreate: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -209,15 +220,15 @@ handlereq(Ixp9Req *r) { pc->srv->create(r); break; case TOpen: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } - if((r->fid->qid.type&QTDIR) && (r->ifcall.mode|P9_ORCLOSE) != (P9_OREAD|P9_ORCLOSE)) { + if((r->fid->qid.type&QTDIR) && (r->ifcall.topen.mode|P9_ORCLOSE) != (P9_OREAD|P9_ORCLOSE)) { respond(r, Eisdir); return; } - r->ofcall.qid = r->fid->qid; + r->ofcall.ropen.qid = r->fid->qid; if(!pc->srv->open) { respond(r, Enofunc); return; @@ -225,7 +236,7 @@ handlereq(Ixp9Req *r) { pc->srv->open(r); break; case TRead: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -240,7 +251,7 @@ handlereq(Ixp9Req *r) { pc->srv->read(r); break; case TRemove: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -251,7 +262,7 @@ handlereq(Ixp9Req *r) { pc->srv->remove(r); break; case TStat: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -262,7 +273,7 @@ handlereq(Ixp9Req *r) { pc->srv->stat(r); break; case TWalk: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -270,12 +281,12 @@ handlereq(Ixp9Req *r) { respond(r, "cannot walk from an open fid"); return; } - if(r->ifcall.nwname && !(r->fid->qid.type&QTDIR)) { + if(r->ifcall.twalk.nwname && !(r->fid->qid.type&QTDIR)) { respond(r, Enotdir); return; } - if((r->ifcall.fid != r->ifcall.newfid)) { - if(!(r->newfid = createfid(&pc->fidmap, r->ifcall.newfid, pc))) { + if((r->ifcall.hdr.fid != r->ifcall.twalk.newfid)) { + if(!(r->newfid = createfid(&pc->fidmap, r->ifcall.twalk.newfid, pc))) { respond(r, Edupfid); return; } @@ -288,7 +299,7 @@ handlereq(Ixp9Req *r) { pc->srv->walk(r); break; case TWrite: - if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.fid))) { + if(!(r->fid = lookupkey(&pc->fidmap, r->ifcall.hdr.fid))) { respond(r, Enofid); return; } @@ -313,58 +324,58 @@ respond(Ixp9Req *r, const char *error) { pc = r->conn; - switch(r->ifcall.type) { + switch(r->ifcall.hdr.type) { default: if(!error) assert(!"Respond called on unsupported fcall type"); break; case TVersion: assert(error == nil); - free(r->ifcall.version); + free(r->ifcall.version.version); thread->lock(&pc->rlock); thread->lock(&pc->wlock); - msize = min(r->ofcall.msize, IXP_MAX_MSG); + msize = min(r->ofcall.version.msize, IXP_MAX_MSG); pc->rmsg.data = erealloc(pc->rmsg.data, msize); pc->wmsg.data = erealloc(pc->wmsg.data, msize); pc->rmsg.size = msize; pc->wmsg.size = msize; thread->unlock(&pc->wlock); thread->unlock(&pc->rlock); - r->ofcall.msize = msize; + r->ofcall.version.msize = msize; break; case TAttach: if(error) destroyfid(pc, r->fid->fid); - free(r->ifcall.uname); - free(r->ifcall.aname); + free(r->ifcall.tattach.uname); + free(r->ifcall.tattach.aname); break; case TOpen: case TCreate: if(!error) { - r->ofcall.iounit = pc->rmsg.size - 24; - r->fid->iounit = r->ofcall.iounit; - r->fid->omode = r->ifcall.mode; - r->fid->qid = r->ofcall.qid; + r->ofcall.ropen.iounit = pc->rmsg.size - 24; + r->fid->iounit = r->ofcall.ropen.iounit; + r->fid->omode = r->ifcall.topen.mode; + r->fid->qid = r->ofcall.ropen.qid; } - free(r->ifcall.name); + free(r->ifcall.tcreate.name); break; case TWalk: - if(error || r->ofcall.nwqid < r->ifcall.nwname) { - if(r->ifcall.fid != r->ifcall.newfid && r->newfid) + if(error || r->ofcall.rwalk.nwqid < r->ifcall.twalk.nwname) { + if(r->ifcall.hdr.fid != r->ifcall.twalk.newfid && r->newfid) destroyfid(pc, r->newfid->fid); - if(!error && r->ofcall.nwqid == 0) + if(!error && r->ofcall.rwalk.nwqid == 0) error = Enofile; }else{ - if(r->ofcall.nwqid == 0) + if(r->ofcall.rwalk.nwqid == 0) r->newfid->qid = r->fid->qid; else - r->newfid->qid = r->ofcall.wqid[r->ofcall.nwqid-1]; + r->newfid->qid = r->ofcall.rwalk.wqid[r->ofcall.rwalk.nwqid-1]; } - free(*r->ifcall.wname); + free(*r->ifcall.twalk.wname); break; case TWrite: - free(r->ifcall.data); + free(r->ifcall.twrite.data); break; case TRemove: if(r->fid) @@ -375,7 +386,7 @@ respond(Ixp9Req *r, const char *error) { destroyfid(pc, r->fid->fid); break; case TFlush: - if((r->oldreq = lookupkey(&pc->tagmap, r->ifcall.oldtag))) + if((r->oldreq = lookupkey(&pc->tagmap, r->ifcall.tflush.oldtag))) respond(r->oldreq, Eintr); break; case TRead: @@ -384,16 +395,16 @@ respond(Ixp9Req *r, const char *error) { /* Still to be implemented: wstat, auth */ } - r->ofcall.tag = r->ifcall.tag; + r->ofcall.hdr.tag = r->ifcall.hdr.tag; if(error == nil) - r->ofcall.type = r->ifcall.type + 1; + r->ofcall.hdr.type = r->ifcall.hdr.type + 1; else { - r->ofcall.type = RError; - r->ofcall.ename = (char*)error; + r->ofcall.hdr.type = RError; + r->ofcall.error.ename = (char*)error; } - deletekey(&pc->tagmap, r->ifcall.tag);; + deletekey(&pc->tagmap, r->ifcall.hdr.tag);; if(pc->conn) { thread->lock(&pc->wlock); @@ -403,12 +414,12 @@ respond(Ixp9Req *r, const char *error) { thread->unlock(&pc->wlock); } - switch(r->ofcall.type) { + switch(r->ofcall.hdr.type) { case RStat: - free(r->ofcall.stat); + free(r->ofcall.rstat.stat); break; case RRead: - free(r->ofcall.data); + free(r->ofcall.rread.data); break; } free(r); @@ -426,9 +437,9 @@ voidrequest(void *t) { pc->ref++; tr = emallocz(sizeof *tr); - tr->ifcall.type = TFlush; - tr->ifcall.tag = IXP_NOTAG; - tr->ifcall.oldtag = r->ifcall.tag; + tr->ifcall.hdr.type = TFlush; + tr->ifcall.hdr.tag = IXP_NOTAG; + tr->ifcall.tflush.oldtag = r->ifcall.hdr.tag; tr->conn = pc; handlereq(tr); } @@ -445,9 +456,9 @@ voidfid(void *t) { pc->ref++; tr = emallocz(sizeof *tr); - tr->ifcall.type = TClunk; - tr->ifcall.tag = IXP_NOTAG; - tr->ifcall.fid = f->fid; + tr->ifcall.hdr.type = TClunk; + tr->ifcall.hdr.tag = IXP_NOTAG; + tr->ifcall.hdr.fid = f->fid; tr->fid = f; tr->conn = pc; handlereq(tr); diff --git a/libixp/rpc.c b/libixp/rpc.c @@ -62,7 +62,7 @@ sendrpc(IxpRpc *r, Fcall *f) /* assign the tag, add selves to response queue */ thread->lock(&mux->lk); r->tag = gettag(mux, r); - f->tag = r->tag; + f->hdr.tag = r->tag; enqueue(mux, r); thread->unlock(&mux->lk); @@ -104,11 +104,11 @@ dispatchandqlock(IxpClient *mux, Fcall *f) int tag; IxpRpc *r2; - tag = f->tag - mux->mintag; + tag = f->hdr.tag - mux->mintag; thread->lock(&mux->lk); /* hand packet to correct sleeper */ if(tag < 0 || tag >= mux->mwait) { - fprintf(stderr, "libixp: recieved unfeasible tag: %d (min: %d, max: %d)\n", f->tag, mux->mintag, mux->mintag+mux->mwait); + fprintf(stderr, "libixp: recieved unfeasible tag: %d (min: %d, max: %d)\n", f->hdr.tag, mux->mintag, mux->mintag+mux->mwait); goto fail; } r2 = mux->wait[tag]; diff --git a/mk/dir.mk b/mk/dir.mk @@ -1,23 +1,26 @@ -MKSUBDIR = targ=$@; targ=$${targ\#d}; \ - for i in $$dirs; do \ - if [ ! -d $$i ]; then \ - echo Skipping nonexistent directory: $$i 1>&2; \ - else \ - echo MAKE $$targ $(BASE)$$i/; \ - (cd $$i && $(MAKE) BASE="$(BASE)$$i/" $$targ) || exit $?; \ - fi; \ +MKSUBDIR = \ + set -e; \ + targ=$@; targ=$${targ\#d}; \ + for i in $$dirs; do \ + export BASE=$(BASE)$$i/; \ + if [ ! -d $$i ]; then \ + echo Skipping nonexistent directory: $$i 1>&2; \ + else \ + echo MAKE $$targ $$BASE; \ + (cd $$i && $(MAKE) $$targ) || exit $?; \ + fi; \ done dall: - dirs="$(DIRS)"; $(MKSUBDIR) + +dirs="$(DIRS)"; $(MKSUBDIR) dclean: - dirs="$(DIRS)"; $(MKSUBDIR) + +dirs="$(DIRS)"; $(MKSUBDIR) dinstall: - dirs="$(INSTDIRS)"; $(MKSUBDIR) + +dirs="$(INSTDIRS)"; $(MKSUBDIR) duninstall: - dirs="$(INSTDIRS)"; $(MKSUBDIR) + +dirs="$(INSTDIRS)"; $(MKSUBDIR) ddepend: - dirs="$(DIRS)"; $(MKSUBDIR) + +dirs="$(DIRS)"; $(MKSUBDIR) all: dall clean: dclean diff --git a/mk/gcc.mk b/mk/gcc.mk @@ -26,5 +26,4 @@ CFLAGS += \ -Wtrigraphs MKDEP = cpp -M SOCFLAGS += -fPIC -SOLDFLAGS += -shared -Wl,-soname=$(SONAME) diff --git a/mk/hdr.mk b/mk/hdr.mk @@ -36,8 +36,8 @@ all: $(LINK) $@ $< .c.O: - ${COMPILE} ${<:.c=.o} $< - ${LINK} $@ ${<:.c=.o} + $(COMPILE) ${<:.c=.o} $< + $(LINK) $@ ${<:.c=.o} .sh.O: echo FILTER $(BASE)$<