From ee466c60d16ac406c33b71815b907648c7d842ce Mon Sep 17 00:00:00 2001 From: "Anselm R. Garbe" Date: Wed, 17 May 2006 10:36:56 +0200 Subject: [PATCH] fixed 9P issues with styx reported on the list --- cmd/wm/fs.c | 46 ++++++++++++++++++++++++++++++---------------- cmd/wmiisetsid.c | 18 +++++++++++++++--- 2 files changed, 45 insertions(+), 19 deletions(-) diff --git a/cmd/wm/fs.c b/cmd/wm/fs.c index a65ffd8e..7866c5e8 100644 --- a/cmd/wm/fs.c +++ b/cmd/wm/fs.c @@ -22,6 +22,7 @@ static char E9pversion[] = "9P version not supported"; static char Enoperm[] = "permission denied"; static char Enofile[] = "file not found"; +static char Efidinuse[] = "fid in use"; static char Enomode[] = "mode not supported"; static char Enofunc[] = "function not supported"; static char Enocommand[] = "command not supported"; @@ -268,7 +269,7 @@ type_of_name(Qid wqid[IXP_MAX_WELEM], unsigned short qsel, char *name) unpack_qpath(wqid, qsel, &dir_type, &i1, &i2, &i3); - if(!name || !name[0] || !strncmp(name, "/", 2) || !strncmp(name, "..", 3)) + if(!name || !name[0] || !strncmp(name, "/", 2)) return FsDroot; if(!strncmp(name, "tags", 5)) return FsFtags; @@ -646,13 +647,12 @@ static char * xattach(IXPConn *c, Fcall *fcall) { IXPMap *new = cext_emallocz(sizeof(IXPMap)); - new->sel = 0; + cext_vattach(ixp_vector_of_maps(&c->map), new); new->wqid[0] = root_qid; new->nwqid = 1; new->fid = fcall->fid; - cext_vattach(ixp_vector_of_maps(&c->map), new); fcall->id = RATTACH; - fcall->qid = root_qid; + fcall->qid = new->wqid[new->sel]; ixp_server_respond_fcall(c, fcall); return nil; } @@ -661,35 +661,49 @@ static char * xwalk(IXPConn *c, Fcall *fcall) { IXPMap *m; - unsigned int i, nwqid; - Qid wqid[IXP_MAX_WELEM]; + unsigned int qsel, nwqid; + Qid wqid[IXP_MAX_WELEM], *qid; if(!(m = ixp_server_fid2map(c, fcall->fid))) return Enofile; if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid))) - return Enofile; + return Efidinuse; - for(i = 0; i < m->nwqid; i++) - wqid[i] = m->wqid[i]; + for(qsel = 0; qsel < m->nwqid; qsel++) + wqid[qsel] = m->wqid[qsel]; + if(qsel) + qsel--; for(nwqid = 0; nwqid < fcall->nwname; nwqid++) { - Qid *qid = qid_of_name(wqid, nwqid ? nwqid - 1 : 0, fcall->wname[nwqid]); - if(!qid) + if(qsel >= IXP_MAX_WELEM) break; - fcall->wqid[nwqid] = wqid[nwqid] = *qid; + if(!strncmp(fcall->wname[nwqid], "..", 3)) { + if(qsel) + qsel--; + qid = &wqid[qsel]; + } + else { + qid = qid_of_name(wqid, qsel, fcall->wname[nwqid]); + if(!qid) + break; + qsel++; + } + fcall->wqid[nwqid] = wqid[qsel] = *qid; } + if(fcall->nwname && !nwqid) return Enofile; + /* a fid will only be valid, if the walk was complete */ if(nwqid == fcall->nwname) { + unsigned int i; if(fcall->fid != fcall->newfid) { m = cext_emallocz(sizeof(IXPMap)); cext_vattach(ixp_vector_of_maps(&c->map), m); } - for(i = 0; i < nwqid; i++) + for(i = 0; i <= qsel; i++) m->wqid[i] = wqid[i]; - m->nwqid = nwqid; - if(nwqid) - m->sel = nwqid - 1; + m->nwqid = qsel + 1; + m->sel = qsel; m->fid = fcall->newfid; } fcall->id = RWALK; diff --git a/cmd/wmiisetsid.c b/cmd/wmiisetsid.c index 97cf79ff..dd3fed87 100644 --- a/cmd/wmiisetsid.c +++ b/cmd/wmiisetsid.c @@ -6,12 +6,24 @@ #include #include +static char version[] = "wmiisetsid - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; + +static void +usage() +{ + fprintf(stderr, "%s", "usage: wmiisetsid cmd [arg ...] [-v]\n"); + exit(1); +} + int main(int argc, char *argv[]) { - if(argc < 2) { - fprintf(stderr, "usage: wmiisetsid cmd [arg ...]\n", argv[0]); - exit(1); + /* command line args */ + if(argc < 2) + usage(); + else if(argv[1][1] == 'v') { + fprintf(stdout, "%s", version); + exit(0); } if(getpgrp() == getpid()) { switch(fork()){