--- ray/src/hd/holofile.c 2003/02/22 02:07:24 3.42 +++ ray/src/hd/holofile.c 2003/05/29 16:26:21 3.46 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: holofile.c,v 3.42 2003/02/22 02:07:24 greg Exp $"; +static const char RCSid[] = "$Id: holofile.c,v 3.46 2003/05/29 16:26:21 greg Exp $"; #endif /* * Routines for managing holodeck files @@ -10,10 +10,10 @@ static const char RCSid[] = "$Id: holofile.c,v 3.42 20 #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 @@ -52,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 */ @@ -66,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,13 +81,13 @@ HDGRID *hproto; 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 */ } @@ -101,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 */ @@ -123,7 +123,7 @@ 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; } @@ -154,8 +154,8 @@ 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; @@ -186,7 +186,7 @@ HDGRID *hproto; /* holodeck section grid */ if (fd < nhdfragls && hdfragl[fd].nlinks) writable = hdfragl[fd].writable; else - writable = lseek(fd, (off_t)fpos, 0) == fpos && + writable = lseek(fd, fpos, 0) == fpos && write(fd, (char *)hp, sizeof(HDGRID)) == sizeof(HDGRID); } else { /* else assume we're creating it */ @@ -242,7 +242,7 @@ int i; register int j; if (!hp->dirty++) { /* write smudge first time */ - if (lseek(hp->fd, (off_t)(biglob(hp)->fo+(i-1)*sizeof(BEAMI)), 0) < 0 + if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 || write(hp->fd, (char *)&smudge, sizeof(BEAMI)) != sizeof(BEAMI)) error(SYSTEM, "seek/write error in hdmarkdirty"); @@ -305,8 +305,8 @@ int all; return(0); errno = 0; /* write dirty segments */ for (j = 0; j < hp->dirty; j++) { - if (lseek(hp->fd, (off_t)(biglob(hp)->fo + - (hp->dirseg[j].s-1)*sizeof(BEAMI)), 0) < 0) + if (lseek(hp->fd, biglob(hp)->fo + + (hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) error(SYSTEM, "cannot seek on holodeck file"); n = hp->dirseg[j].n * sizeof(BEAMI); if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) @@ -346,11 +346,11 @@ 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); @@ -358,19 +358,19 @@ int fd; if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) return(-1); flen = lseek(fd, (off_t)0L, 2); - lseek(fd, (off_t)fpos, 0); + lseek(fd, fpos, 0); return(flen); } return(hdfragl[fd].flen); } -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++) { @@ -413,7 +413,7 @@ int nr; /* number of new rays desired */ blglob(hp)->nrm += n; if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { errno = 0; - if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) + if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) error(SYSTEM, "seek error on holodeck file"); n *= sizeof(RAYVAL); if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) @@ -429,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 */ } @@ -452,7 +452,7 @@ register int i; hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); blglob(hp)->nrm += hp->bl[i]->nrm = n; errno = 0; - if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) + if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) error(SYSTEM, "seek error on holodeck file"); n *= sizeof(RAYVAL); if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) @@ -499,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 */ @@ -569,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 */ @@ -632,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); @@ -669,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); @@ -683,7 +683,7 @@ register int i; if (nrays) { /* get and write new fragment */ nfo = hdallocfrag(hp->fd, nrays); errno = 0; - if (lseek(hp->fd, (off_t)nfo, 0) < 0) + if (lseek(hp->fd, nfo, 0) < 0) error(SYSTEM, "cannot seek on holodeck file"); n = hp->bl[i]->nrm * sizeof(RAYVAL); if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {