void threadmain(int argc, char *argv[]) { ArenaPart *ap; Part *part; char *file; u8int score[VtScoreSize]; int i, found; ventifmtinstall(); ARGBEGIN{ case 'v': verbose++; break; default: usage(); break; }ARGEND readonly = 1; if(argc != 2) usage(); file = argv[0]; if(strscore(argv[1], score) < 0) sysfatal("bad score %s", argv[1]); part = initpart(file, OREAD|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); ap = initarenapart(part); if(ap == nil) sysfatal("can't initialize arena partition in %s: %r", file); if(verbose > 1){ printarenapart(2, ap); fprint(2, "\n"); } initdcache(8 * MaxDiskBlock); found = 0; for(i = 0; i < ap->narenas; i++) found += findscore(ap->arenas[i], score); print("found %d occurrences of %V\n", found, score); if(verbose > 1) printstats(); threadexitsall(0); }
void threadmain(int argc, char *argv[]) { ArenaPart *ap; Part *part; char *file, *aname; int i; ventifmtinstall(); statsinit(); ARGBEGIN{ case 'q': quiet++; break; case 'v': verbose++; break; default: usage(); break; }ARGEND readonly = 1; if(argc != 2) usage(); file = argv[0]; aname = argv[1]; part = initpart(file, OREAD|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); ap = initarenapart(part); if(ap == nil) sysfatal("can't initialize arena partition in %s: %r", file); if(verbose) printarenapart(2, ap); initdcache(8 * MaxDiskBlock); for(i = 0; i < ap->narenas; i++){ if(strcmp(ap->arenas[i]->name, aname) == 0){ rdarena(ap->arenas[i]); threadexitsall(0); } } sysfatal("couldn't find arena %s", aname); }
int hdisk(HConnect *c) { char *disk, *type; Part *p; int ret; if(hsethtml(c) < 0) return -1; disk = hargstr(c, "disk", ""); if(!disk[0]) return disksummary(c); if((p = initpart(disk, OREAD)) == nil){ hprint(&c->hout, "open %s: %r", disk); return 0; } type = hargstr(c, "type", ""); switch(type[0]){ case 'a': ret = diskarenapart(c, disk, p); break; case 'b': ret = diskbloom(c, disk, p); break; case 'i': ret = diskisect(c, disk, p); break; default: hprint(&c->hout, "unknown disk type %s", type); return 0; } freepart(p); return ret; }
void threadmain(int argc, char *argv[]) { int vers; ArenaPart *ap; Part *part; Arena *arena; uint64_t addr, limit, asize, apsize; char *file, *name, aname[ANameSize]; int i, n, blocksize, tabsize, zero; ventifmtinstall(); statsinit(); blocksize = 8 * 1024; asize = 512 * 1024 *1024; tabsize = 512 * 1024; /* BUG: should be determine from number of arenas */ zero = -1; vers = ArenaVersion5; ARGBEGIN{ case 'D': settrace(EARGF(usage())); break; case 'a': asize = unittoull(EARGF(usage())); if(asize == TWID64) usage(); break; case 'b': blocksize = unittoull(EARGF(usage())); if(blocksize == ~0) usage(); if(blocksize > MaxDiskBlock){ fprint(2, "block size too large, max %d\n", MaxDiskBlock); threadexitsall("usage"); } break; case '4': vers = ArenaVersion4; break; case 'Z': zero = 0; break; default: usage(); break; }ARGEND if(zero == -1){ if(vers == ArenaVersion4) zero = 1; else zero = 0; } if(argc != 2) usage(); name = argv[0]; file = argv[1]; if(nameok(name) < 0) sysfatal("illegal name template %s", name); part = initpart(file, ORDWR|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); if(zero) zeropart(part, blocksize); maxblocksize = blocksize; initdcache(20*blocksize); ap = newarenapart(part, blocksize, tabsize); if(ap == nil) sysfatal("can't initialize arena: %r"); apsize = ap->size - ap->arenabase; n = apsize / asize; if(apsize - (n * asize) >= MinArenaSize) n++; fprint(2, "fmtarenas %s: %,d arenas, %,lld bytes storage, %,d bytes for index map\n", file, n, apsize, ap->tabsize); ap->narenas = n; ap->map = MKNZ(AMap, n); ap->arenas = MKNZ(Arena*, n); addr = ap->arenabase; for(i = 0; i < n; i++){ limit = addr + asize; if(limit >= ap->size || ap->size - limit < MinArenaSize){ limit = ap->size; if(limit - addr < MinArenaSize) sysfatal("bad arena set math: runt arena at %lld,%lld %lld", addr, limit, ap->size); } snprint(aname, ANameSize, "%s%d", name, i); if(0) fprint(2, "adding arena %s at [%lld,%lld)\n", aname, addr, limit); arena = newarena(part, vers, aname, addr, limit - addr, blocksize); if(!arena) fprint(2, "can't make new arena %s: %r", aname); freearena(arena); ap->map[i].start = addr; ap->map[i].stop = limit; namecp(ap->map[i].name, aname); addr = limit; } if(wbarenapart(ap) < 0) fprint(2, "can't write back arena partition header for %s: %r\n", file); flushdcache(); threadexitsall(0); }
int main(int argc, char *argv[]) { unsigned *cloud; int texcomps, texwid, texht; GLUquadricObj *sphere; /* start and end of particles */ static GLfloat begin[] = {0.f, -25.f, 0.f}; static GLfloat end[] = {0.f,-100.f, 0.f}; static GLfloat fogcolor[] = {.4f, .4f, .4f, 1.f}; glutInitWindowSize(winwid, winht); glutInit(&argc, argv); if(argc > 1) { char *args = argv[1]; int done = GL_FALSE; while(!done) { switch(*args) { case 's': /* single buffer */ printf("Single Buffered\n"); dblbuf = GL_FALSE; break; case '-': /* do nothing */ break; case 0: done = GL_TRUE; break; } args++; } } if(dblbuf) glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL|GLUT_DOUBLE); else glutInitDisplayMode(GLUT_RGBA|GLUT_DEPTH|GLUT_STENCIL); (void)glutCreateWindow("snow demo"); glutDisplayFunc(redraw); glutReshapeFunc(reshape); glutMouseFunc(mouse); glutMotionFunc(motion); glutKeyboardFunc(key); glutIdleFunc(idle); glutCreateMenu(menu); glutAddMenuEntry("Toggle Overcast (o, O)", OVERCAST); glutAddMenuEntry("Toggle Fog (f, F)", FOG); glutAddMenuEntry("Toggle Snow (s, S)", SNOW); glutAddMenuEntry("Bigger Flakes (+)", BIGGER); glutAddMenuEntry("Smaller Flakes (-)", SMALLER); glutAddMenuEntry("Reset Flake Size to One (r, R)", RESETSIZE); glutAddMenuEntry("Toggle Point Antialiasing (a, A)", ANTIALIAS); glutAddMenuEntry("Snow Blending (b, B)", BLEND); glutAddMenuEntry("Exit Program", EXIT); glutAttachMenu(GLUT_RIGHT_BUTTON); printf("OpenGL Version %s\n", glGetString(GL_VERSION)); /* draw a perspective scene */ glMatrixMode(GL_PROJECTION); glFrustum(-5., 5., -5., 5., 10., 1000.); glMatrixMode(GL_MODELVIEW); updateMV(); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); /* turn on features */ glEnable(GL_DEPTH_TEST); glEnable(GL_LIGHTING); glEnable(GL_LIGHT0); /* place light 0 in the right place */ glLightfv(GL_LIGHT0, GL_POSITION, lightpos); glClearColor(0.f, 0.f, 1.f, 1.f); glFogfv(GL_FOG_COLOR, fogcolor); glFogi(GL_FOG_MODE, GL_LINEAR); glFogf(GL_FOG_START, -200.f); glFogf(GL_FOG_END, 200.f); glHint(GL_FOG_HINT, GL_NICEST); glEnable(GL_COLOR_MATERIAL); glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE); /* makes texturing faster, and looks better than GL_LINEAR */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT); glNewList(LIGHT, GL_COMPILE); glDisable(GL_LIGHTING); sphere = gluNewQuadric(); glColor3f(.7f, .2f, .7f); gluSphere(sphere, 5.f, 10, 10); gluDeleteQuadric(sphere); glEnable(GL_LIGHTING); glEndList(); /* 10 X 20; vary size with transforms */ /* one corner of house on origin; bottom on xz plane */ glNewList(HOUSE, GL_COMPILE); glBegin(GL_QUADS); /* walls of house */ glColor3f(1.f, 1.f, 0.f); /* front */ glNormal3f( 0.f, 0.f, 1.f); glVertex3i( 0, 0, 0); glVertex3i(10, 0, 0); glVertex3i(10,10, 0); glVertex3i( 0,10, 0); /* back */ glNormal3f( 0.f, 0.f, -1.f); glVertex3i( 0, 0, -20); glVertex3i( 0,10, -20); glVertex3i(10,10, -20); glVertex3i(10, 0, -20); /* left */ glNormal3f(-1, 0.f, 0.f); glVertex3i( 0, 0, 0); glVertex3i( 0, 10, 0); glVertex3i( 0, 10, -20); glVertex3i( 0, 0, -20); /* right */ glNormal3f( 1.f, 0.f, 0.f); glVertex3i(10, 0, 0); glVertex3i(10, 0, -20); glVertex3i(10, 10, -20); glVertex3i(10, 10, 0); /* roof of house */ glColor3f(.8f, .1f, .1f); /* left top */ glNormal3f(-.707f, .707f, 0.f); glVertex3i( 0, 10, 0); glVertex3i( 5, 15, 0); glVertex3i( 5, 15, -20); glVertex3i( 0, 10, -20); /* right top */ glNormal3f( .707f, .707f, 0.f); glVertex3i(10, 10, 0); glVertex3i(10, 10, -20); glVertex3i( 5, 15, -20); glVertex3i( 5, 15, 0); glEnd(); glBegin(GL_TRIANGLES); /* front */ glNormal3f( 0.f, 0.f, 1.f); glVertex3i( 0, 10, 0); glVertex3i(10, 10, 0); glVertex3i( 5, 15, 0); /* back */ glNormal3f( 0.f, 0.f, -1.f); glVertex3i( 0, 10, -20); glVertex3i( 5, 15, -20); glVertex3i(10, 10, -20); glEnd(); glEndList(); glEnable(GL_CULL_FACE); /* load pattern for current 2d texture */ cloud = read_texture("../../data/clouds.bw", &texwid, &texht, &texcomps); gluBuild2DMipmaps(GL_TEXTURE_2D, GL_LUMINANCE, texwid, texht, GL_RGBA, GL_UNSIGNED_BYTE, cloud); glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_BLEND); free(cloud); initpart(&psys, begin, end, 200, 6000); updateptr = updatepart0; CHECK_ERROR("main()"); glutMainLoop(); return 0; }
int readifile(IFile *f, char *name) { Part *p; ZBlock *b; u8int *z; p = initpart(name, OREAD); if(p == nil) return -1; b = alloczblock(Maxconfig+1, 1, 0); if(b == nil){ seterr(EOk, "can't alloc for %s: %R", name); return -1; } if(p->size > PartBlank){ /* * this is likely a real venti partition, in which case we're * looking for the config file stored as 8k at end of PartBlank. */ if(readpart(p, PartBlank-Maxconfig, b->data, Maxconfig) < 0){ seterr(EOk, "can't read %s: %r", name); freezblock(b); freepart(p); return -1; } b->data[Maxconfig] = '\0'; if(memcmp(b->data, vcmagic, Maglen) != 0){ seterr(EOk, "bad venti config magic in %s", name); freezblock(b); freepart(p); return -1; } /* * if we change b->data+b->_size, freezblock * will blow an assertion, so don't. */ b->data += Maglen; b->_size -= Maglen; b->len -= Maglen; z = memchr(b->data, '\0', b->len); if(z) b->len = z - b->data; }else if(p->size > Maxconfig){ seterr(EOk, "config file is too large"); freepart(p); freezblock(b); return -1; }else{ freezblock(b); b = readfile(name); if(b == nil){ freepart(p); return -1; } } freepart(p); f->name = name; f->b = b; f->pos = 0; return 0; }
void threadmain(int argc, char *argv[]) { int i; char *file; Arena *arena; u64int offset, aoffset; Part *part; uchar buf[8192]; ArenaHead head; ZClump zerocl; ventifmtinstall(); qlock(&godot); aoffset = 0; ARGBEGIN{ case 'f': fast = 1; ventidoublechecksha1 = 0; break; case 'h': host = EARGF(usage()); break; case 'o': haveaoffset = 1; aoffset = strtoull(EARGF(usage()), 0, 0); break; case 'M': maxwrites = atoi(EARGF(usage())); break; case 'v': verbose = 1; break; default: usage(); break; }ARGEND offset = ~(u64int)0; switch(argc) { default: usage(); case 2: offset = strtoull(argv[1], 0, 0); /* fall through */ case 1: file = argv[0]; } fmtinstall('V', vtscorefmt); statsinit(); part = initpart(file, OREAD); if(part == nil) sysfatal("can't open file %s: %r", file); if(readpart(part, aoffset, buf, sizeof buf) < 0) sysfatal("can't read file %s: %r", file); if(unpackarenahead(&head, buf) < 0) sysfatal("corrupted arena header: %r"); if(aoffset+head.size > part->size) sysfatal("arena is truncated: want %llud bytes have %llud", head.size, part->size); partblocksize(part, head.blocksize); initdcache(8 * MaxDiskBlock); arena = initarena(part, aoffset, head.size, head.blocksize); if(arena == nil) sysfatal("initarena: %r"); z = nil; if(host==nil || strcmp(host, "/dev/null") != 0){ z = vtdial(host); if(z == nil) sysfatal("could not connect to server: %r"); if(vtconnect(z) < 0) sysfatal("vtconnect: %r"); } c = chancreate(sizeof(ZClump), 0); for(i=0; i<12; i++) vtproc(vtsendthread, nil); rdarena(arena, offset); if(vtsync(z) < 0) sysfatal("executing sync: %r"); memset(&zerocl, 0, sizeof zerocl); for(i=0; i<12; i++) send(c, &zerocl); if(z){ vthangup(z); } threadexitsall(0); }
void threadmain(int argc, char *argv[]) { int vers; ISect *is; Part *part; char *file, *name; int blocksize, setsize, zero; ventifmtinstall(); statsinit(); blocksize = 8 * 1024; setsize = 512 * 1024; zero = -1; vers = ISectVersion2; ARGBEGIN{ case 'b': blocksize = unittoull(ARGF()); if(blocksize == ~0) usage(); if(blocksize > MaxDiskBlock){ fprint(2, "block size too large, max %d\n", MaxDiskBlock); threadexitsall("usage"); } break; case '1': vers = ISectVersion1; break; case 'Z': zero = 0; break; default: usage(); break; }ARGEND if(zero == -1){ if(vers == ISectVersion1) zero = 1; else zero = 0; } if(argc != 2) usage(); name = argv[0]; file = argv[1]; if(nameok(name) < 0) sysfatal("illegal name %s", name); part = initpart(file, ORDWR|ODIRECT); if(part == nil) sysfatal("can't open partition %s: %r", file); if(zero) zeropart(part, blocksize); is = newisect(part, vers, name, blocksize, setsize); if(is == nil) sysfatal("can't initialize new index: %r"); fprint(2, "fmtisect %s: %,d buckets of %,d entries, %,d bytes for index map\n", file, is->blocks, is->buckmax, setsize); if(wbisect(is) < 0) fprint(2, "can't write back index section header for %s: %r\n", file); threadexitsall(0); }