fixed 9P issues with styx reported on the list

This commit is contained in:
Anselm R. Garbe 2006-05-17 10:36:56 +02:00
parent cd282d75c1
commit ee466c60d1
2 changed files with 45 additions and 19 deletions

View File

@ -22,6 +22,7 @@
static char E9pversion[] = "9P version not supported"; static char E9pversion[] = "9P version not supported";
static char Enoperm[] = "permission denied"; static char Enoperm[] = "permission denied";
static char Enofile[] = "file not found"; static char Enofile[] = "file not found";
static char Efidinuse[] = "fid in use";
static char Enomode[] = "mode not supported"; static char Enomode[] = "mode not supported";
static char Enofunc[] = "function not supported"; static char Enofunc[] = "function not supported";
static char Enocommand[] = "command 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); 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; return FsDroot;
if(!strncmp(name, "tags", 5)) if(!strncmp(name, "tags", 5))
return FsFtags; return FsFtags;
@ -646,13 +647,12 @@ static char *
xattach(IXPConn *c, Fcall *fcall) xattach(IXPConn *c, Fcall *fcall)
{ {
IXPMap *new = cext_emallocz(sizeof(IXPMap)); IXPMap *new = cext_emallocz(sizeof(IXPMap));
new->sel = 0; cext_vattach(ixp_vector_of_maps(&c->map), new);
new->wqid[0] = root_qid; new->wqid[0] = root_qid;
new->nwqid = 1; new->nwqid = 1;
new->fid = fcall->fid; new->fid = fcall->fid;
cext_vattach(ixp_vector_of_maps(&c->map), new);
fcall->id = RATTACH; fcall->id = RATTACH;
fcall->qid = root_qid; fcall->qid = new->wqid[new->sel];
ixp_server_respond_fcall(c, fcall); ixp_server_respond_fcall(c, fcall);
return nil; return nil;
} }
@ -661,35 +661,49 @@ static char *
xwalk(IXPConn *c, Fcall *fcall) xwalk(IXPConn *c, Fcall *fcall)
{ {
IXPMap *m; IXPMap *m;
unsigned int i, nwqid; unsigned int qsel, nwqid;
Qid wqid[IXP_MAX_WELEM]; Qid wqid[IXP_MAX_WELEM], *qid;
if(!(m = ixp_server_fid2map(c, fcall->fid))) if(!(m = ixp_server_fid2map(c, fcall->fid)))
return Enofile; return Enofile;
if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid))) if(fcall->fid != fcall->newfid && (ixp_server_fid2map(c, fcall->newfid)))
return Enofile; return Efidinuse;
for(i = 0; i < m->nwqid; i++) for(qsel = 0; qsel < m->nwqid; qsel++)
wqid[i] = m->wqid[i]; wqid[qsel] = m->wqid[qsel];
if(qsel)
qsel--;
for(nwqid = 0; nwqid < fcall->nwname; nwqid++) { for(nwqid = 0; nwqid < fcall->nwname; nwqid++) {
Qid *qid = qid_of_name(wqid, nwqid ? nwqid - 1 : 0, fcall->wname[nwqid]); if(qsel >= IXP_MAX_WELEM)
if(!qid)
break; 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) if(fcall->nwname && !nwqid)
return Enofile; return Enofile;
/* a fid will only be valid, if the walk was complete */ /* a fid will only be valid, if the walk was complete */
if(nwqid == fcall->nwname) { if(nwqid == fcall->nwname) {
unsigned int i;
if(fcall->fid != fcall->newfid) { if(fcall->fid != fcall->newfid) {
m = cext_emallocz(sizeof(IXPMap)); m = cext_emallocz(sizeof(IXPMap));
cext_vattach(ixp_vector_of_maps(&c->map), m); 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->wqid[i] = wqid[i];
m->nwqid = nwqid; m->nwqid = qsel + 1;
if(nwqid) m->sel = qsel;
m->sel = nwqid - 1;
m->fid = fcall->newfid; m->fid = fcall->newfid;
} }
fcall->id = RWALK; fcall->id = RWALK;

View File

@ -6,12 +6,24 @@
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
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 int
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
if(argc < 2) { /* command line args */
fprintf(stderr, "usage: wmiisetsid cmd [arg ...]\n", argv[0]); if(argc < 2)
exit(1); usage();
else if(argv[1][1] == 'v') {
fprintf(stdout, "%s", version);
exit(0);
} }
if(getpgrp() == getpid()) { if(getpgrp() == getpid()) {
switch(fork()){ switch(fork()){