static int pcinfo(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String vers, cm; int i; chat("host=%I, port=%ld: pcinfo...", cmd->host, cmd->port); if(n <= 16) return garbage(reply, "count too small"); argptr += string2S(argptr, &vers); argptr += string2S(argptr, &cm); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); chat("\"%.*s\",\"%.*s\"\n", utfnlen(vers.s, vers.n), vers.s, utfnlen(cm.s, cm.n), cm.s); PLONG(sizeof(pc_vers)-1); PPTR(pc_vers, sizeof(pc_vers)-1); PLONG(sizeof(no_comment)-1); PPTR(no_comment, sizeof(no_comment)-1); PLONG(nelem(pcfacilities)); for(i=0; i<nelem(pcfacilities); i++) PLONG(pcfacilities[i]); return dataptr - (uchar *)reply->results; }
static int mntexport(int n, Rpccall *cmd, Rpccall *reply) { uchar *dataptr = reply->results; Authunix au; int i; chat("mntexport..."); if(n != 0) return garbage(reply, "mntexport"); if(auth2unix(&cmd->cred, &au) != 0){ chat("auth flavor=%ld, count=%ld\n", cmd->cred.flavor, cmd->cred.count); for(i=0; i<cmd->cred.count; i++) chat(" %.2ux", ((uchar *)cmd->cred.data)[i]); chat("..."); au.mach.n = 0; }else chat("%ld@%.*s...", au.uid, utfnlen(au.mach.s, au.mach.n), au.mach.s); PLONG(TRUE); PLONG(1); PPTR("/", 1); if(au.mach.n > 0){ PLONG(TRUE); PLONG(au.mach.n); PPTR(au.mach.s, au.mach.n); } PLONG(FALSE); PLONG(FALSE); chat("OK\n"); return dataptr - (uchar *)reply->results; }
int main() { //foo_transport_block_allocator::initialize_storage(); foo_transport_block_allocator_t p; transport_block* p1 = p.allocate(1); p1->buf = "foo"; p1->rnti = 16; p1->mcs = 32; p1->rb = 2; PPTR(p1); transport_block* p2 = p.allocate(1); p2->buf = "baz"; p2->rnti = 17; p2->mcs = 33; p2->rb = 3; PPTR(p2); p.deallocate(p1); transport_block* p3 = p.allocate(1); PPTR(p3); p3->buf = "bar"; p3->rnti = 18; p3->mcs = 34; p3->rb = 4; }
static int pcauth(int n, Rpccall *cmd, Rpccall *reply) { uchar *argptr = cmd->args; uchar *dataptr = reply->results; String sys, id, pw, cm; Unixidmap *m; int uid; chat("host=%I, port=%ld: pcauth...", cmd->host, cmd->port); if(n <= 16) return garbage(reply, "count too small"); argptr += string2S(argptr, &sys); argptr += string2S(argptr, &id); argptr += string2S(argptr, &pw); argptr += string2S(argptr, &cm); if(argptr != &((uchar *)cmd->args)[n]) return garbage(reply, "bad count"); scramble(&id); scramble(&pw); m = pair2idmap("pcnfsd", cmd->host); uid = -1; if(m) uid = name2id(&m->u.ids, id.s); if(uid < 0) uid = 1; chat("\"%.*s\",\"%.*s\",\"%.*s\",\"%.*s\"\n", utfnlen(sys.s, sys.n), sys.s, utfnlen(id.s, id.n), id.s, utfnlen(pw.s, pw.n), pw.s, utfnlen(cm.s, cm.n), cm.s); PLONG(0); /* status - OK */ PLONG(uid); PLONG(uid); /* gid */ PLONG(0); /* ngids */ PLONG(sizeof(pc_home)-1); PPTR(pc_home, sizeof(pc_home)-1); PLONG(0); /* umask */ PLONG(sizeof(no_comment)-1); PPTR(no_comment, sizeof(no_comment)-1); return dataptr - (uchar *)reply->results; }
static int nfsreaddir(int n, Rpccall *cmd, Rpccall *reply) { Session *s; Xfid *xf; Dir dir; char *rdata; int k, offset, count, sfcount, entries, dsize; uchar *argptr = cmd->args; uchar *dataptr = reply->results; chat("readdir..."); if(n != FHSIZE+8) return garbage(reply, "bad count"); xf = rpc2xfid(cmd, 0); argptr += FHSIZE; offset = GLONG(); count = GLONG(); if(xf == 0) return error(reply, NFSERR_STALE); chat("%s (%ld) %d %d...", xf->xp->name, xf->offset, offset, count); s = xf->xp->s; if((xf->mode & Open) && xf->offset > offset) xfclose(xf); if(xfopen(xf, Oread) < 0) return error(reply, NFSERR_PERM); while(xf->offset < offset){ /* if we reopened, xf->offset will be zero */ sfcount = offset - xf->offset; if(sfcount > messagesize-IOHDRSZ) sfcount = messagesize-IOHDRSZ; setfid(s, xf->opfid); s->f.offset = xf->offset; s->f.count = sfcount; if(xmesg(s, Tread) < 0){ xfclose(xf); return error(reply, NFSERR_IO); } if(s->f.count <= BIT16SZ) break; xf->offset += s->f.count; } if(count > messagesize-IOHDRSZ) count = messagesize-IOHDRSZ; PLONG(NFS_OK); entries = 0; while(count > 16){ /* at least 16 bytes required; we don't know size of name */ chat("top of loop\n"); setfid(s, xf->opfid); s->f.offset = xf->offset; s->f.count = count; /* as good a guess as any */ if(xmesg(s, Tread) < 0){ xfclose(xf); return error(reply, NFSERR_IO); } sfcount = s->f.count; if(sfcount <= BIT16SZ) break; xf->offset += sfcount; chat("count %d data 0x%p\n", s->f.count, s->f.data); rdata = s->f.data; /* now have a buffer of Plan 9 directories; unpack into NFS thingies */ while(sfcount >= 0){ dsize = convM2D((uchar*)rdata, sfcount, &dir, (char*)s->statbuf); if(dsize <= BIT16SZ){ count = 0; /* force break from outer loop */ break; } offset += dsize; k = strlen(dir.name); if(count < 16+ROUNDUP(k)){ count = 0; /* force break from outer loop */ break; } PLONG(TRUE); PLONG(dir.qid.path); PLONG(k); PPTR(dir.name, k); PLONG(offset); count -= 16+ROUNDUP(k); rdata += dsize; sfcount -= dsize; } } PLONG(FALSE); if(s->f.count <= 0){ xfclose(xf); chat("eof..."); PLONG(TRUE); }else PLONG(FALSE); chat("%d OK\n", entries); return dataptr - (uchar *)reply->results; }