wmii

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

commit 874228cf1aaea0a1ac60ea0166df6b3dea94b166
parent 6b835653185e4b025d6a63a6dd2e71844f89d3f4
Author: Anselm R. Garbe <garbeam@wmii.de>
Date:   Tue, 11 Jul 2006 14:06:21 +0200

applied 20h's patches with small minor changes (made wmiir compile against his changes)


Diffstat:
cmd/wmiir.c | 8++++----
libixp/client.c | 136+++++++++++++++++++++++++++++++++++++++++++++----------------------------------
libixp/ixp.h | 3++-
3 files changed, 83 insertions(+), 64 deletions(-)

diff --git a/cmd/wmiir.c b/cmd/wmiir.c @@ -27,11 +27,11 @@ usage() static void write_data(unsigned int fid) { - void *data = cext_emallocz(c.fcall.iounit); + void *data = cext_emallocz(c.ofcall.iounit); unsigned long long offset = 0; unsigned int len = 0; - while((len = read(0, data, c.fcall.iounit)) > 0) { + while((len = read(0, data, c.ofcall.iounit)) > 0) { if(ixp_client_write(&c, fid, offset, len, data) != len) { fprintf(stderr, "wmiir: cannot write file: %s\n", c.errstr); break; @@ -65,7 +65,7 @@ xcreate(char *file) fprintf(stderr, "wmiir: cannot create file '%s': %s\n", p, c.errstr); return -1; } - if(!(c.fcall.qid.type&P9DMDIR)) + if(!(c.ofcall.qid.type&P9DMDIR)) write_data(fid); return ixp_client_close(&c, fid); } @@ -193,7 +193,7 @@ xdir(char *file, int details) fprintf(stderr, "wmiir: cannot stat file '%s': %s\n", file, c.errstr); return -1; } - buf = c.fcall.stat; + buf = c.ofcall.stat; ixp_unpack_stat(&buf, nil, s); if(!(s->mode & IXP_DMDIR)) { print_stat(s, details); diff --git a/libixp/client.c b/libixp/client.c @@ -16,70 +16,78 @@ int ixp_client_do_fcall(IXPClient *c) { static unsigned char msg[IXP_MAX_MSG]; - unsigned int msize = ixp_fcall2msg(msg, &c->fcall, IXP_MAX_MSG); + unsigned int msize = ixp_fcall2msg(msg, &c->ifcall, IXP_MAX_MSG); + c->errstr = 0; if(ixp_send_message(c->fd, msg, msize, &c->errstr) != msize) return -1; if(!ixp_recv_message(c->fd, msg, IXP_MAX_MSG, &c->errstr)) return -1; - if(!(msize = ixp_msg2fcall(&c->fcall, msg, IXP_MAX_MSG))) { + if(!(msize = ixp_msg2fcall(&c->ofcall, msg, IXP_MAX_MSG))) { c->errstr = "received bad message"; return -1; } - if(c->fcall.type == RERROR) { - c->errstr = c->fcall.ename; + if(c->ofcall.type == RERROR) { + c->errstr = c->ofcall.ename; return -1; } + return 0; } int ixp_client_dial(IXPClient *c, char *sockfile, unsigned int rootfid) { + if((c->fd = ixp_connect_sock(sockfile)) < 0) { c->errstr = "cannot connect server"; return -1; } - c->fcall.type = TVERSION; - c->fcall.tag = IXP_NOTAG; - c->fcall.msize = IXP_MAX_MSG; - c->fcall.version = cext_estrdup(IXP_VERSION); + + c->ifcall.type = TVERSION; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.msize = IXP_MAX_MSG; + c->ifcall.version = IXP_VERSION; if(ixp_client_do_fcall(c) == -1) { fprintf(stderr, "error: %s\n", c->errstr); ixp_client_hangup(c); return -1; } - if(strncmp(c->fcall.version, IXP_VERSION, strlen(IXP_VERSION))) { + if(strncmp(c->ofcall.version, IXP_VERSION, strlen(IXP_VERSION))) { fprintf(stderr, "error: %s\n", c->errstr); c->errstr = "9P versions differ"; ixp_client_hangup(c); return -1; /* we cannot handle this version */ } + free(c->ofcall.version); c->root_fid = rootfid; - c->fcall.type = TATTACH; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = c->root_fid; - c->fcall.afid = IXP_NOFID; - c->fcall.uname = cext_estrdup(getenv("USER")); - c->fcall.aname = cext_estrdup(""); + c->ifcall.type = TATTACH; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = c->root_fid; + c->ifcall.afid = IXP_NOFID; + c->ifcall.uname = getenv("USER"); + c->ifcall.aname = ""; if(ixp_client_do_fcall(c) == -1) { fprintf(stderr, "error: %s\n", c->errstr); ixp_client_hangup(c); return -1; } - c->root_qid = c->fcall.qid; + c->root_qid = c->ofcall.qid; + return 0; } int ixp_client_remove(IXPClient *c, unsigned int newfid, char *filepath) { + if(ixp_client_walk(c, newfid, filepath) == -1) return -1; - c->fcall.type = TREMOVE; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = newfid; + c->ifcall.type = TREMOVE; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = newfid; + return ixp_client_do_fcall(c); } @@ -87,12 +95,12 @@ int ixp_client_create(IXPClient *c, unsigned int dirfid, char *name, unsigned int perm, unsigned char mode) { - c->fcall.type = TCREATE; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = dirfid; - c->fcall.name = cext_estrdup(name); - c->fcall.perm = perm; - c->fcall.mode = mode; + c->ifcall.type = TCREATE; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = dirfid; + c->ifcall.name = name; + c->ifcall.perm = perm; + c->ifcall.mode = mode; return ixp_client_do_fcall(c); } @@ -101,15 +109,16 @@ ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath) { unsigned int i; char *wname[IXP_MAX_WELEM]; - c->fcall.type = TWALK; - c->fcall.fid = c->root_fid; - c->fcall.newfid = newfid; + + c->ifcall.type = TWALK; + c->ifcall.fid = c->root_fid; + c->ifcall.newfid = newfid; if(filepath) { - c->fcall.name = cext_estrdup(filepath); - c->fcall.nwname = - cext_tokenize(wname, IXP_MAX_WELEM, c->fcall.name, '/'); - for(i = 0; i < c->fcall.nwname; i++) - c->fcall.wname[i] = cext_estrdup(wname[i]); + c->ifcall.name = filepath; + c->ifcall.nwname = + cext_tokenize(wname, IXP_MAX_WELEM, c->ifcall.name, '/'); + for(i = 0; i < c->ifcall.nwname; i++) + c->ifcall.wname[i] = wname[i]; } return ixp_client_do_fcall(c); } @@ -117,22 +126,24 @@ ixp_client_walk(IXPClient *c, unsigned int newfid, char *filepath) int ixp_client_stat(IXPClient *c, unsigned int newfid, char *filepath) { + if(ixp_client_walk(c, newfid, filepath) == -1) return -1; - c->fcall.type = TSTAT; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = newfid; + c->ifcall.type = TSTAT; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = newfid; return ixp_client_do_fcall(c); } int ixp_client_open(IXPClient *c, unsigned int newfid, unsigned char mode) { - c->fcall.type = TOPEN; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = newfid; - c->fcall.mode = mode; + + c->ifcall.type = TOPEN; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = newfid; + c->ifcall.mode = mode; return ixp_client_do_fcall(c); } @@ -140,6 +151,7 @@ int ixp_client_walkopen(IXPClient *c, unsigned int newfid, char *filepath, unsigned char mode) { + if(ixp_client_walk(c, newfid, filepath) == -1) return -1; return ixp_client_open(c, newfid, mode); @@ -149,17 +161,19 @@ int ixp_client_read(IXPClient *c, unsigned int fid, unsigned long long offset, void *result, unsigned int res_len) { - unsigned int bytes = c->fcall.iounit; + unsigned int bytes = c->ofcall.iounit; - c->fcall.type = TREAD; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = fid; - c->fcall.offset = offset; - c->fcall.count = res_len < bytes ? res_len : bytes; + c->ifcall.type = TREAD; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = fid; + c->ifcall.offset = offset; + c->ifcall.count = res_len < bytes ? res_len : bytes; if(ixp_client_do_fcall(c) == -1) return -1; - memcpy(result, c->fcall.data, c->fcall.count); - return c->fcall.count; + memcpy(result, c->ofcall.data, c->ofcall.count); + free(c->ofcall.data); + + return c->ofcall.count; } int @@ -167,27 +181,31 @@ ixp_client_write(IXPClient *c, unsigned int fid, unsigned long long offset, unsigned int count, unsigned char *data) { - if(count > c->fcall.iounit) { + + if(count > c->ofcall.iounit) { c->errstr = "iounit exceeded"; return -1; } - c->fcall.type = TWRITE; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = fid; - c->fcall.offset = offset; - c->fcall.count = count; - c->fcall.data = (void *)data; + + c->ifcall.type = TWRITE; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = fid; + c->ifcall.offset = offset; + c->ifcall.count = count; + c->ifcall.data = (void *)data; if(ixp_client_do_fcall(c) == -1) return -1; - return c->fcall.count; + + return c->ofcall.count; } int ixp_client_close(IXPClient *c, unsigned int fid) { - c->fcall.type = TCLUNK; - c->fcall.tag = IXP_NOTAG; - c->fcall.fid = fid; + + c->ifcall.type = TCLUNK; + c->ifcall.tag = IXP_NOTAG; + c->ifcall.fid = fid; return ixp_client_do_fcall(c); } diff --git a/libixp/ixp.h b/libixp/ixp.h @@ -244,7 +244,8 @@ typedef struct IXPClient { int fd; unsigned int root_fid; Qid root_qid; - Fcall fcall; + Fcall ifcall; + Fcall ofcall; char *errstr; } IXPClient;