--- ray/src/hd/holofile.c 1999/08/05 15:53:09 3.41 +++ ray/src/hd/holofile.c 2003/06/13 15:27:04 3.47 @@ -1,9 +1,6 @@ -/* Copyright (c) 1999 Regents of the University of California */ - #ifndef lint -static char SCCSid[] = "$SunId$ SGI"; +static const char RCSid[] = "$Id: holofile.c,v 3.47 2003/06/13 15:27:04 greg Exp $"; #endif - /* * Routines for managing holodeck files * @@ -13,10 +10,10 @@ static char SCCSid[] = "$SunId$ SGI"; #include "holo.h" #ifndef CACHESIZE -#ifdef BIGMEM -#define CACHESIZE 17 /* default cache size (Mbytes, 0==inf) */ -#else +#ifdef SMLMEM #define CACHESIZE 5 +#else +#define CACHESIZE 17 /* default cache size (Mbytes, 0==inf) */ #endif #endif #ifndef FREEBEAMS @@ -55,7 +52,7 @@ static struct fraglist { short writable; /* 0 read-only, <0 write error encountered */ int nfrags; /* number of known fragments */ BEAMI *fi; /* fragments, descending file position */ - long flen; /* last known file length */ + off_t flen; /* last known file length */ } *hdfragl; /* fragment lists, indexed by file descriptor */ static int nhdfragls; /* size of hdfragl array */ @@ -69,7 +66,7 @@ HDGRID *hproto; register HOLO *hp; int n; /* copy grid to temporary header */ - bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID)); + bcopy((void *)hproto, (void *)&hdhead, sizeof(HDGRID)); /* compute grid vectors and sizes */ hdcompgrid(&hdhead); /* allocate header with directory */ @@ -81,16 +78,16 @@ HDGRID *hproto; /* allocate and clear beam list */ hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); if (hp->bl == NULL) { - free((char *)hp); + free((void *)hp); return(NULL); } - bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); + bzero((void *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ hp->fd = -1; hp->dirty = 0; hp->priv = NULL; /* clear beam directory */ - bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); + bzero((void *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); return(hp); /* all is well */ } @@ -104,7 +101,7 @@ char *rout; register char *newp; /* call malloc/realloc */ if (ptr == NULL) newp = (char *)malloc(siz); - else newp = (char *)realloc(ptr, siz); + else newp = (char *)realloc((void *)ptr, siz); /* check success */ if (newp == NULL && rout != NULL) { hdfreecache(25, NULL); /* free some memory */ @@ -126,13 +123,13 @@ int wr; if (fd >= nhdfragls) { hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl, (fd+1)*sizeof(struct fraglist), "hdattach"); - bzero((char *)(hdfragl+nhdfragls), + bzero((void *)(hdfragl+nhdfragls), (fd+1-nhdfragls)*sizeof(struct fraglist)); nhdfragls = fd+1; } hdfragl[fd].nlinks++; hdfragl[fd].writable = wr; /* set writable flag */ - hdfragl[fd].flen = lseek(fd, 0L, 2); /* get file length */ + hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ } @@ -145,7 +142,7 @@ register int fd; if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) return; if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { - free((char *)hdfragl[fd].fi); + free((void *)hdfragl[fd].fi); hdfragl[fd].fi = NULL; hdfragl[fd].nfrags = 0; } @@ -157,14 +154,14 @@ hdinit(fd, hproto) /* initialize a holodeck section in int fd; /* corresponding file descriptor */ HDGRID *hproto; /* holodeck section grid */ { - long rtrunc; - long fpos; + off_t rtrunc; + off_t fpos; int writable; register HOLO *hp; register int n; /* prepare for system errors */ errno = 0; - if ((fpos = lseek(fd, 0L, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, 1)) < 0) error(SYSTEM, "cannot determine holodeck file position"); if (hproto == NULL) { /* assume we're loading it */ HDGRID hpr; @@ -349,18 +346,18 @@ int all; /* include overhead (painful) */ } -long +off_t hdfilen(fd) /* return file length for fd */ int fd; { - long fpos, flen; + off_t fpos, flen; if (fd < 0) return(-1); if (fd >= nhdfragls || !hdfragl[fd].nlinks) { - if ((fpos = lseek(fd, 0L, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, 1)) < 0) return(-1); - flen = lseek(fd, 0L, 2); + flen = lseek(fd, (off_t)0, 2); lseek(fd, fpos, 0); return(flen); } @@ -368,12 +365,12 @@ int fd; } -long +off_t hdfiluse(fd, all) /* compute file usage (in bytes) */ int fd; /* open file descriptor to check */ int all; /* include overhead and unflushed data */ { - long total = 0; + off_t total = 0; register int i, j; for (j = 0; hdlist[j] != NULL; j++) { @@ -432,7 +429,7 @@ int nr; /* number of new rays desired */ hdfreefrag(hp, i); /* relinquish old fragment */ p = hdbray(hp->bl[i]) + hp->bl[i]->nrm; hp->bl[i]->nrm += nr; /* update in-core structure */ - bzero((char *)p, nr*sizeof(RAYVAL)); + bzero((void *)p, nr*sizeof(RAYVAL)); blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ return(p); /* point to new rays */ } @@ -472,15 +469,15 @@ int hdfilord(hb1, hb2) /* order beams for quick loading */ register HDBEAMI *hb1, *hb2; { - register long c; + register off_t c; /* residents go first */ if (hb2->h->bl[hb2->b] != NULL) return(hb1->h->bl[hb1->b] == NULL); if (hb1->h->bl[hb1->b] != NULL) return(-1); /* otherwise sort by file descriptor */ - if ((c = hb1->h->fd - hb2->h->fd)) - return(c); + if (hb1->h->fd != hb2->h->fd) + return(hb1->h->fd - hb2->h->fd); /* then by position in file */ c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo; return(c > 0 ? 1 : c < 0 ? -1 : 0); @@ -502,7 +499,7 @@ int (*bf)(); /* callback function (optional) */ if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) error(CONSISTENCY, "bad beam in hdloadbeams"); /* sort list for optimal access */ - qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord); + qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord); bytesloaded = 0; /* run through loaded beams */ for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) { bp->tick = hdclock; /* preempt swap */ @@ -572,7 +569,7 @@ int i; if (f->fi == NULL) newp = (BEAMI *)malloc((j+FRAGBLK)*sizeof(BEAMI)); else - newp = (BEAMI *)realloc((char *)f->fi, + newp = (BEAMI *)realloc((void *)f->fi, (j+FRAGBLK)*sizeof(BEAMI)); if (newp == NULL) { f->nfrags--; /* graceful failure */ @@ -605,7 +602,7 @@ int i; } biglob(hp)->nrd -= bi->nrd; /* tell fragment it's free */ bi->nrd = 0; - bi->fo = 0L; + bi->fo = 0; hdmarkdirty(hp, i); /* assume we'll reallocate */ return(1); } @@ -635,14 +632,14 @@ register int4 *listsiz; } -long +off_t hdallocfrag(fd, nrays) /* allocate a file fragment */ int fd; unsigned int4 nrays; { register struct fraglist *f; register int j; - long nfo; + off_t nfo; if (nrays == 0) return(-1L); @@ -672,7 +669,7 @@ register int i; int fragfreed; unsigned int4 nrays; unsigned int n; - long nfo; + off_t nfo; /* check file status */ if (hdfragl[hp->fd].writable <= 0) return(hdfragl[hp->fd].writable); @@ -696,7 +693,7 @@ register int i; } hp->bi[i].fo = nfo; } else - hp->bi[i].fo = 0L; + hp->bi[i].fo = 0; biglob(hp)->nrd += nrays - hp->bi[i].nrd; hp->bi[i].nrd = nrays; if (!fragfreed) @@ -740,7 +737,7 @@ register int i; if (nchanged) hdsyncbeam(hp, i); /* write new fragment */ blglob(hp)->nrm -= hp->bl[i]->nrm; - free((char *)hp->bl[i]); /* free memory */ + free((void *)hp->bl[i]); /* free memory */ hp->bl[i] = NULL; return(nchanged); } @@ -777,14 +774,14 @@ register int i; "hdkillbeam called on read-only holodeck"); if (hp->bl[i] != NULL) { /* free memory */ blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm; - free((char *)hp->bl[i]); + free((void *)hp->bl[i]); hp->bl[i] = NULL; } else nchanged = hp->bi[i].nrd; if (hp->bi[i].nrd && !(hdfragflags&FF_KILL && hdfreefrag(hp,i))) { biglob(hp)->nrd -= hp->bi[i].nrd; /* free failed */ hp->bi[i].nrd = 0; - hp->bi[i].fo = 0L; + hp->bi[i].fo = 0; hdmarkdirty(hp, i); } return(nchanged); @@ -875,7 +872,7 @@ register HOLO *hp; /* NULL means clean up all */ if (hp == NULL) { /* NULL means clean up everything */ while (hdlist[0] != NULL) hddone(hdlist[0]); - free((char *)hdfragl); + free((void *)hdfragl); hdfragl = NULL; nhdfragls = 0; return; } @@ -890,6 +887,6 @@ register HOLO *hp; /* NULL means clean up all */ i++; break; } - free((char *)hp->bl); /* free beam list */ - free((char *)hp); /* free holodeck struct */ + free((void *)hp->bl); /* free beam list */ + free((void *)hp); /* free holodeck struct */ }