void main(int argc, char *argv[]) { VtSession *z; int i, j, t; int start; uchar buf[BlockSize]; srand(time(0)); ARGBEGIN{ case 'r': rflag++; break; case 'n': nblock = atoi(ARGF()); break; }ARGEND for(i=0; i<nblock; i++) perm[i] = i; if(rflag) { for(i=0; i<nblock; i++) { j = nrand(nblock); t = perm[j]; perm[j] = perm[i]; perm[i] = t; } } if(readn(0, data, VtScoreSize*nblock) < VtScoreSize*nblock) sysfatal("read failed: %r"); vtAttach(); z = vtDial("iolaire2"); if(z == nil) sysfatal("cound not connect to venti"); if(!vtConnect(z, 0)) vtFatal("vtConnect: %s", vtGetError()); print("starting\n"); start = times(0); if(rflag && nblock > 10000) nblock = 10000; for(i=0; i<nblock; i++) { if(vtRead(z, data+perm[i]*VtScoreSize, VtDataType, buf, BlockSize) < 0) vtFatal("vtRead failed: %d: %s", i, vtGetError()); } print("time = %f\n", (times(0) - start)*0.001); vtClose(z); vtDetach(); }
int vtThread(void (*f)(void*), void *rock) { int tid; tid = rfork(RFNOWAIT|RFMEM|RFPROC); switch(tid){ case -1: vtOSError(); return -1; case 0: break; default: return tid; } vtAttach(); (*f)(rock); vtDetach(); _exits(0); return 0; }
void main(int argc, char* argv[]) { char **cmd, *p; int i, ncmd, tflag; fmtinstall('D', dirfmt); fmtinstall('F', fcallfmt); fmtinstall('M', dirmodefmt); quotefmtinstall(); /* * Insulate from the invoker's environment. */ if(rfork(RFREND|RFNOTEG|RFNAMEG) < 0) sysfatal("rfork: %r"); close(0); open("/dev/null", OREAD); close(1); open("/dev/null", OWRITE); cmd = nil; ncmd = tflag = 0; vtAttach(); ARGBEGIN{ case '?': default: usage(); break; case 'c': p = EARGF(usage()); currfsysname = p; cmd = vtMemRealloc(cmd, (ncmd+1)*sizeof(char*)); cmd[ncmd++] = p; break; case 'D': Dflag ^= 1; break; case 'f': p = EARGF(usage()); currfsysname = foptname = p; readCmdPart(p, &cmd, &ncmd); break; case 'm': mempcnt = atoi(EARGF(usage())); if(mempcnt <= 0 || mempcnt >= 100) usage(); break; case 't': tflag = 1; break; }ARGEND if(argc != 0) usage(); consInit(); cliInit(); msgInit(); conInit(); cmdInit(); fsysInit(); exclInit(); fidInit(); srvInit(); lstnInit(); usersInit(); for(i = 0; i < ncmd; i++) if(cliExec(cmd[i]) == 0) fprint(2, "%s: %R\n", cmd[i]); vtMemFree(cmd); if(tflag && consTTY() == 0) consPrint("%s\n", vtGetError()); vtDetach(); exits(0); }
void main(int argc, char *argv[]) { int fd, force; Header h; ulong bn; Entry e; char *label = "vfs"; char *host = nil; char *score = nil; u32int root; Dir *d; force = 0; ARGBEGIN{ default: usage(); case 'b': bsize = unittoull(EARGF(usage())); if(bsize == ~0) usage(); break; case 'h': host = EARGF(usage()); break; case 'i': iso9660file = EARGF(usage()); iso9660off = atoi(EARGF(usage())); break; case 'l': label = EARGF(usage()); break; case 'v': score = EARGF(usage()); break; /* * This is -y instead of -f because flchk has a * (frequently used) -f option. I type flfmt instead * of flchk all the time, and want to make it hard * to reformat my file system accidentally. */ case 'y': force = 1; break; }ARGEND if(argc != 1) usage(); if(iso9660file && score) vtFatal("cannot use -i with -v"); vtAttach(); fmtinstall('V', scoreFmt); fmtinstall('R', vtErrFmt); fmtinstall('L', labelFmt); fd = open(argv[0], ORDWR); if(fd < 0) vtFatal("could not open file: %s: %r", argv[0]); buf = vtMemAllocZ(bsize); if(pread(fd, buf, bsize, HeaderOffset) != bsize) vtFatal("could not read fs header block: %r"); if(headerUnpack(&h, buf) && !force && !confirm("fs header block already exists; are you sure?")) goto Out; if((d = dirfstat(fd)) == nil) vtFatal("dirfstat: %r"); if(d->type == 'M' && !force && !confirm("fs file is mounted via devmnt (is not a kernel device); are you sure?")) goto Out; partition(fd, bsize, &h); headerPack(&h, buf); if(pwrite(fd, buf, bsize, HeaderOffset) < bsize) vtFatal("could not write fs header: %r"); disk = diskAlloc(fd); if(disk == nil) vtFatal("could not open disk: %r"); if(iso9660file) iso9660init(fd, &h, iso9660file, iso9660off); /* zero labels */ memset(buf, 0, bsize); for(bn = 0; bn < diskSize(disk, PartLabel); bn++) blockWrite(PartLabel, bn); if(iso9660file) iso9660labels(disk, buf, blockWrite); if(score) root = ventiRoot(host, score); else{ rootMetaInit(&e); root = rootInit(&e); } superInit(label, root, vtZeroScore); diskFree(disk); if(score == nil) topLevel(argv[0]); Out: vtDetach(); exits(0); }