static void fdirconv(char *buf, char *e, Dir *d) { char tmp[16]; seprint(buf, e, "'%s' '%s' '%s' '%s' " "q " QIDFMT " m %#luo " "at %ld mt %ld l %lld " "t %d d %d", d->name, d->uid, d->gid, d->muid, d->qid.path, d->qid.vers, qidtype(tmp, d->qid.type), d->mode, d->atime, d->mtime, d->length, d->type, d->dev); }
int fcallfmt(Fmt *fmt) { Fcall *f; int fid, type, tag, i; char buf[512], tmp[200]; char *p, *e; Dir *d; Qid *q; e = buf+sizeof(buf); f = va_arg(fmt->args, Fcall*); type = f->type; fid = f->fid; tag = f->tag; switch(type){ case Tversion: /* 100 */ seprint(buf, e, "Tversion tag %ud msize %ud version '%s'", tag, f->msize, f->version); break; case Rversion: seprint(buf, e, "Rversion tag %ud msize %ud version '%s'", tag, f->msize, f->version); break; case Tauth: /* 102 */ seprint(buf, e, "Tauth tag %ud afid %d uname %s aname %s", tag, f->afid, f->uname, f->aname); break; case Rauth: seprint(buf, e, "Rauth tag %ud qid " QIDFMT, tag, f->aqid.path, f->aqid.vers, qidtype(tmp, f->aqid.type)); break; case Tattach: /* 104 */ seprint(buf, e, "Tattach tag %ud fid %d afid %d uname %s aname %s", tag, fid, f->afid, f->uname, f->aname); break; case Rattach: seprint(buf, e, "Rattach tag %ud qid " QIDFMT, tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type)); break; case Rerror: /* 107; 106 (Terror) illegal */ seprint(buf, e, "Rerror tag %ud ename %s", tag, f->ename); break; case Tflush: /* 108 */ seprint(buf, e, "Tflush tag %ud oldtag %ud", tag, f->oldtag); break; case Rflush: seprint(buf, e, "Rflush tag %ud", tag); break; case Twalk: /* 110 */ p = seprint(buf, e, "Twalk tag %ud fid %d newfid %d nwname %d ", tag, fid, f->newfid, f->nwname); if(f->nwname <= MAXWELEM) for(i=0; i<f->nwname; i++) p = seprint(p, e, "%d:%s ", i, f->wname[i]); break; case Rwalk: p = seprint(buf, e, "Rwalk tag %ud nwqid %ud ", tag, f->nwqid); if(f->nwqid <= MAXWELEM) for(i=0; i<f->nwqid; i++){ q = &f->wqid[i]; p = seprint(p, e, "%d:" QIDFMT " ", i, q->path, q->vers, qidtype(tmp, q->type)); } break; case Topen: /* 112 */ seprint(buf, e, "Topen tag %ud fid %ud mode %d", tag, fid, f->mode); break; case Ropen: seprint(buf, e, "Ropen tag %ud qid " QIDFMT " iounit %ud ", tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type), f->iounit); break; case Tcreate: /* 114 */ seprint(buf, e, "Tcreate tag %ud fid %ud name %s perm %M mode %d", tag, fid, f->name, (uint32_t)f->perm, f->mode); break; case Rcreate: seprint(buf, e, "Rcreate tag %ud qid " QIDFMT " iounit %ud ", tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type), f->iounit); break; case Tread: /* 116 */ seprint(buf, e, "Tread tag %ud fid %d offset %lld count %ud", tag, fid, f->offset, f->count); break; case Rread: p = seprint(buf, e, "Rread tag %ud count %ud ", tag, f->count); dumpsome(p, e, f->data, f->count); break; case Twrite: /* 118 */ p = seprint(buf, e, "Twrite tag %ud fid %d offset %lld count %ud ", tag, fid, f->offset, f->count); dumpsome(p, e, f->data, f->count); break; case Rwrite: seprint(buf, e, "Rwrite tag %ud count %ud", tag, f->count); break; case Tclunk: /* 120 */ seprint(buf, e, "Tclunk tag %ud fid %ud", tag, fid); break; case Rclunk: seprint(buf, e, "Rclunk tag %ud", tag); break; case Tremove: /* 122 */ seprint(buf, e, "Tremove tag %ud fid %ud", tag, fid); break; case Rremove: seprint(buf, e, "Rremove tag %ud", tag); break; case Tstat: /* 124 */ seprint(buf, e, "Tstat tag %ud fid %ud", tag, fid); break; case Rstat: p = seprint(buf, e, "Rstat tag %ud ", tag); if(f->nstat > sizeof tmp) seprint(p, e, " stat(%d bytes)", f->nstat); else{ d = (Dir*)tmp; convM2D(f->stat, f->nstat, d, (char*)(d+1)); seprint(p, e, " stat "); fdirconv(p+6, e, d); } break; case Twstat: /* 126 */ p = seprint(buf, e, "Twstat tag %ud fid %ud", tag, fid); if(f->nstat > sizeof tmp) seprint(p, e, " stat(%d bytes)", f->nstat); else{ d = (Dir*)tmp; convM2D(f->stat, f->nstat, d, (char*)(d+1)); seprint(p, e, " stat "); fdirconv(p+6, e, d); } break; case Rwstat: seprint(buf, e, "Rwstat tag %ud", tag); break; default: seprint(buf, e, "unknown type %d", type); } return fmtstrcpy(fmt, buf); }
static char* fswalk1(Fid *fid, char *name, Qid *qid) { char *q; int i, isdotdot, n, t; uvlong path; Aux *a; Whist *wh; String *s; isdotdot = strcmp(name, "..")==0; n = strtoul(name, &q, 10); path = fid->qid.path; a = fid->aux; switch(qidtype(path)){ case 0: return "wikifs: bad path in server (bug)"; case Droot: if(isdotdot){ *qid = fid->qid; return nil; } if(strcmp(name, "new")==0){ *qid = (Qid){mkqid(Fnew, 0, 0, 0), 0, 0}; return nil; } if(strcmp(name, "map")==0){ *qid = (Qid){mkqid(Fmap, 0, 0, 0), 0, 0}; return nil; } if((*q!='\0' || (wh=getcurrent(n))==nil) && (wh=getcurrentbyname(name))==nil) return "file does not exist"; *qid = (Qid){mkqid(D1st, wh->n, 0, 0), wh->doc->time, QTDIR}; a->w = wh; return nil; case D1st: if(isdotdot){ *qid = (Qid){mkqid(Droot, 0, 0, 0), 0, QTDIR}; return nil; } /* handle history directories */ if(*q == '\0'){ if((wh = gethistory(qidnum(path))) == nil) return "file does not exist"; for(i=0; i<wh->ndoc; i++) if(wh->doc[i].time == n) break; if(i==wh->ndoc){ closewhist(wh); return "file does not exist"; } closewhist(a->w); a->w = wh; a->n = i; *qid = (Qid){mkqid(D2nd, qidnum(path), i, 0), wh->doc[i].time, QTDIR}; return nil; } /* handle files other than index */ for(i=0; i<nelem(filelist); i++){ if(strcmp(name, filelist[i])==0){ if(needhist[i]){ if((wh = gethistory(qidnum(path))) == nil) return "file does not exist"; closewhist(a->w); a->w = wh; } *qid = (Qid){mkqid(F1st, qidnum(path), 0, i), a->w->doc->time, 0}; goto Gotfile; } } return "file does not exist"; case D2nd: if(isdotdot){ /* * Can't use a->w[a->ndoc-1] because that * might be a failed write rather than the real one. */ *qid = (Qid){mkqid(D1st, qidnum(path), 0, 0), 0, QTDIR}; if((wh = getcurrent(qidnum(path))) == nil) return "file does not exist"; closewhist(a->w); a->w = wh; a->n = 0; return nil; } for(i=0; i<=Qraw; i++){ if(strcmp(name, filelist[i])==0){ *qid = (Qid){mkqid(F2nd, qidnum(path), qidvers(path), i), a->w->doc->time, 0}; goto Gotfile; } } return "file does not exist"; default: return "bad programming"; } /* not reached */ Gotfile: t = qidtype(qid->path); switch(qidfile(qid->path)){ case Qindexhtml: s = tohtml(a->w, a->w->doc+a->n, t==F1st? Tpage : Toldpage); break; case Qindextxt: s = totext(a->w, a->w->doc+a->n, t==F1st? Tpage : Toldpage); break; case Qraw: s = s_copy(a->w->title); s = s_append(s, "\n"); s = doctext(s, &a->w->doc[a->n]); break; case Qhistoryhtml: s = tohtml(a->w, a->w->doc+a->n, Thistory); break; case Qhistorytxt: s = totext(a->w, a->w->doc+a->n, Thistory); break; case Qdiffhtml: s = tohtml(a->w, a->w->doc+a->n, Tdiff); break; case Qedithtml: s = tohtml(a->w, a->w->doc+a->n, Tedit); break; case Qwerrorhtml: s = tohtml(a->w, a->w->doc+a->n, Twerror); break; case Qwerrortxt: s = totext(a->w, a->w->doc+a->n, Twerror); break; case Qhttplogin: s = httplogin(); break; default: return "internal error"; } a->s = s; return nil; }
static void fsopen(Req *r) { int t; uvlong path; Aux *a; Fid *fid; Whist *wh; fid = r->fid; path = fid->qid.path; t = qidtype(fid->qid.path); if((r->ifcall.mode != OREAD && t != Fnew && t != Fmap) || (r->ifcall.mode&ORCLOSE)){ respond(r, "permission denied"); return; } a = fid->aux; switch(t){ case Droot: currentmap(0); rlock(&maplock); a->map = map; incref(map); runlock(&maplock); respond(r, nil); break; case D1st: if((wh = gethistory(qidnum(path))) == nil){ respond(r, "file does not exist"); return; } closewhist(a->w); a->w = wh; a->n = a->w->ndoc-1; r->ofcall.qid.vers = wh->doc[a->n].time; r->fid->qid = r->ofcall.qid; respond(r, nil); break; case D2nd: respond(r, nil); break; case Fnew: a->s = s_copy(""); respond(r, nil); break; case Fmap: case F1st: case F2nd: respond(r, nil); break; default: respond(r, "programmer error"); break; } }
int fcallconv(va_list *arg, Fconv *f1) { Fcall *f; int fid, type, tag, n, i; char buf[512], tmp[200]; Dir *d; Qid *q; f = va_arg(*arg, Fcall*); type = f->type; fid = f->fid; tag = f->tag; switch(type){ case Tversion: /* 100 */ sprint(buf, "Tversion tag %ud msize %ud version '%s'", tag, f->msize, f->version); break; case Rversion: sprint(buf, "Rversion tag %ud msize %ud version '%s'", tag, f->msize, f->version); break; case Tauth: /* 102 */ sprint(buf, "Tauth tag %ud afid %d uname %s aname %s", tag, f->afid, f->uname, f->aname); break; case Rauth: sprint(buf, "Rauth tag %ud qid " QIDFMT, tag, f->aqid.path, f->aqid.vers, qidtype(tmp, f->aqid.type)); break; case Tattach: /* 104 */ sprint(buf, "Tattach tag %ud fid %d afid %d uname %s aname %s", tag, fid, f->afid, f->uname, f->aname); break; case Rattach: sprint(buf, "Rattach tag %ud qid " QIDFMT, tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type)); break; case Rerror: /* 107; 106 (Terror) illegal */ sprint(buf, "Rerror tag %ud ename %s", tag, f->ename); break; case Tflush: /* 108 */ sprint(buf, "Tflush tag %ud oldtag %ud", tag, f->oldtag); break; case Rflush: sprint(buf, "Rflush tag %ud", tag); break; case Twalk: /* 110 */ n = sprint(buf, "Twalk tag %ud fid %d newfid %d nwname %d ", tag, fid, f->newfid, f->nwname); for(i=0; i<f->nwname; i++) n += sprint(buf+n, "%d:%s ", i, f->wname[i]); break; case Rwalk: n = sprint(buf, "Rwalk tag %ud nwqid %ud ", tag, f->nwqid); for(i=0; i<f->nwqid; i++){ q = &f->wqid[i]; n += sprint(buf+n, "%d:" QIDFMT " ", i, q->path, q->vers, qidtype(tmp, q->type)); } break; case Topen: /* 112 */ sprint(buf, "Topen tag %ud fid %ud mode %d", tag, fid, f->mode); break; case Ropen: sprint(buf, "Ropen tag %ud qid " QIDFMT " iounit %ud ", tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type), f->iounit); break; case Tcreate: /* 114 */ sprint(buf, "Tcreate tag %ud fid %ud name %s perm %M mode %d", tag, fid, f->name, (ulong)f->perm, f->mode); break; case Rcreate: sprint(buf, "Rcreate tag %ud qid " QIDFMT " iounit %ud ", tag, f->qid.path, f->qid.vers, qidtype(tmp, f->qid.type), f->iounit); break; case Tread: /* 116 */ sprint(buf, "Tread tag %ud fid %d offset %lld count %ud", tag, fid, f->offset, f->count); break; case Rread: n = sprint(buf, "Rread tag %ud count %ud ", tag, f->count); dumpsome(buf+n, f->data, f->count); break; case Twrite: /* 118 */ n = sprint(buf, "Twrite tag %ud fid %d offset %lld count %ud ", tag, fid, f->offset, f->count); dumpsome(buf+n, f->data, f->count); break; case Rwrite: sprint(buf, "Rwrite tag %ud count %ud", tag, f->count); break; case Tclunk: /* 120 */ sprint(buf, "Tclunk tag %ud fid %ud", tag, fid); break; case Rclunk: sprint(buf, "Rclunk tag %ud", tag); break; case Tremove: /* 122 */ sprint(buf, "Tremove tag %ud fid %ud", tag, fid); break; case Rremove: sprint(buf, "Rremove tag %ud", tag); break; case Tstat: /* 124 */ sprint(buf, "Tstat tag %ud fid %ud", tag, fid); break; case Rstat: n = sprint(buf, "Rstat tag %ud ", tag); if(f->nstat > sizeof tmp) sprint(buf+n, " stat(%d bytes)", f->nstat); else{ d = (Dir*)tmp; (old9p?convM2Dold:convM2D)(f->stat, f->nstat, d, (char*)(d+1)); sprint(buf+n, " stat "); fdirconv(buf+n+6, d); } break; case Twstat: /* 126 */ n = sprint(buf, "Twstat tag %ud fid %ud", tag, fid); if(f->nstat > sizeof tmp) sprint(buf+n, " stat(%d bytes)", f->nstat); else{ d = (Dir*)tmp; (old9p?convM2Dold:convM2D)(f->stat, f->nstat, d, (char*)(d+1)); sprint(buf+n, " stat "); fdirconv(buf+n+6, d); } break; case Rwstat: sprint(buf, "Rwstat tag %ud", tag); break; default: sprint(buf, "unknown type %d", type); } strconv(buf, f1); return(sizeof(Fcall*)); }