--- ray/src/hd/holofile.c 1997/11/04 10:42:03 3.4 +++ ray/src/hd/holofile.c 1997/11/06 09:37:04 3.6 @@ -16,14 +16,19 @@ static char SCCSid[] = "$SunId$ SGI"; #define CACHESIZE 16 /* default cache size (Mbytes, 0==inf) */ #endif #ifndef FREEBEAMS -#define FREEBEAMS 1024 /* maximum beams to free at a time */ +#define FREEBEAMS 512 /* maximum beams to free at a time */ #endif #ifndef PCTFREE -#define PCTFREE 12 /* maximum fraction to free (%) */ +#define PCTFREE 20 /* maximum fraction to free (%) */ #endif -#define MAXFRAG 8192 /* maximum fragments tracked per open file */ +#ifndef BSD +#define write writebuf /* safe i/o routines */ +#define read readbuf +#endif +#define MAXFRAG (128*FRAGBLK) /* maximum fragments per file */ + #define FRAGBLK 64 /* number of fragments to allocate at a time */ int hdcachesize = CACHESIZE*1024*1024; /* target cache size (bytes) */ @@ -78,6 +83,21 @@ register int fd; } +markdirty(hp) /* mark holodeck section directory dirty */ +register HOLO *hp; +{ + static BEAMI smudge = {0, -1}; + + if (hp->dirty) /* already marked? */ + return; + hp->dirty = 1; + if (lseek(hp->fd, biglob(hp)->fo+(nbeams(hp)-1)*sizeof(BEAMI), 0) < 0 + || write(hp->fd, (char *)&smudge, + sizeof(BEAMI)) != sizeof(BEAMI)) + error(SYSTEM, "seek/write error in markdirty"); +} + + HOLO * hdinit(fd, hproto) /* initialize a holodeck section in a file */ int fd; /* corresponding file descriptor */ @@ -102,6 +122,9 @@ HDGRID *hproto; /* holodeck section grid */ n = nbeams(hp)*sizeof(BEAMI); if (read(fd, (char *)(hp->bi+1), n) != n) error(SYSTEM, "failure loading holodeck directory"); + /* check that it's clean */ + if (hp->bi[nbeams(hp)].fo < 0) + error(USER, "dirty holodeck section"); } else { /* assume we're creating it */ if ((hp = hdalloc(hproto)) == NULL) goto memerr; @@ -314,25 +337,24 @@ register int i; register int j, k; /* relinquish old fragment */ if (hp->bi[i].nrd) { - j = ++f->nfrags; + j = f->nfrags++; #ifdef MAXFRAG - if (j >= MAXFRAG) + if (j >= MAXFRAG-1) f->nfrags--; - else #endif - if (j % FRAGBLK == 1) { /* more frag. space */ + if (j % FRAGBLK == 0) { /* more frag. space */ if (f->fi == NULL) f->fi = (BEAMI *)malloc( FRAGBLK*sizeof(BEAMI)); else f->fi = (BEAMI *)realloc((char *)f->fi, - (FRAGBLK-1+j)*sizeof(BEAMI)); + (j+FRAGBLK)*sizeof(BEAMI)); if (f->fi == NULL) error(SYSTEM, "out of memory in hdgetbi"); } - for ( ; ; ) { /* stick it in our descending list */ - if (!--j || hp->bi[i].fo < f->fi[j-1].fo) { + for ( ; ; j--) { /* insert in descending list */ + if (!j || hp->bi[i].fo < f->fi[j-1].fo) { f->fi[j].fo = hp->bi[i].fo; f->fi[j].nrd = hp->bi[i].nrd; break; @@ -376,7 +398,7 @@ register int i; } biglob(hp)->nrd += nrays - hp->bi[i].nrd; hp->bi[i].nrd = nrays; - hp->dirty++; /* section directory now out of date */ + markdirty(hp); /* section directory now out of date */ return(1); }