--- ray/src/hd/holofile.c 2003/05/29 16:26:21 3.46 +++ ray/src/hd/holofile.c 2003/07/27 22:12:02 3.52 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: holofile.c,v 3.46 2003/05/29 16:26:21 greg Exp $"; +static const char RCSid[] = "$Id: holofile.c,v 3.52 2003/07/27 22:12:02 schorsch Exp $"; #endif /* * Routines for managing holodeck files @@ -7,6 +7,10 @@ static const char RCSid[] = "$Id: holofile.c,v 3.46 20 * 9/30/97 GWLarson */ +#include "copyright.h" + +#include + #include "holo.h" #ifndef CACHESIZE @@ -66,7 +70,7 @@ HDGRID *hproto; register HOLO *hp; int n; /* copy grid to temporary header */ - bcopy((void *)hproto, (void *)&hdhead, sizeof(HDGRID)); + memcpy((void *)&hdhead, (void *)hproto, sizeof(HDGRID)); /* compute grid vectors and sizes */ hdcompgrid(&hdhead); /* allocate header with directory */ @@ -74,20 +78,20 @@ HDGRID *hproto; if ((hp = (HOLO *)malloc(n)) == NULL) return(NULL); /* copy header information */ - copystruct(hp, &hdhead); + *hp = hdhead; /* allocate and clear beam list */ hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); if (hp->bl == NULL) { free((void *)hp); return(NULL); } - bzero((void *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); + memset((void *)hp->bl, '\0', (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((void *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); + memset((void *)hp->bi, '\0', (nbeams(hp)+1)*sizeof(BEAMI)); return(hp); /* all is well */ } @@ -123,13 +127,13 @@ int wr; if (fd >= nhdfragls) { hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl, (fd+1)*sizeof(struct fraglist), "hdattach"); - bzero((void *)(hdfragl+nhdfragls), - (fd+1-nhdfragls)*sizeof(struct fraglist)); + memset((void *)(hdfragl+nhdfragls), + '\0', (fd+1-nhdfragls)*sizeof(struct fraglist)); nhdfragls = fd+1; } hdfragl[fd].nlinks++; hdfragl[fd].writable = wr; /* set writable flag */ - hdfragl[fd].flen = lseek(fd, (off_t)0L, 2); /* get file length */ + hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ } @@ -139,7 +143,7 @@ int wr; hdrelease(fd) /* stop tracking file fragments for some section */ register int fd; { - if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) + if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) return; if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { free((void *)hdfragl[fd].fi); @@ -161,7 +165,7 @@ HDGRID *hproto; /* holodeck section grid */ register int n; /* prepare for system errors */ errno = 0; - if ((fpos = lseek(fd, (off_t)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; @@ -209,12 +213,13 @@ HDGRID *hproto; /* holodeck section grid */ fpos = hdfilen(fd); biglob(hp)->nrd = rtrunc = 0; for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) - if (hp->bi[n].nrd) + if (hp->bi[n].nrd) { if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) { rtrunc += hp->bi[n].nrd; hp->bi[n].nrd = 0; } else biglob(hp)->nrd += hp->bi[n].nrd; + } if (rtrunc) { sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); @@ -257,7 +262,7 @@ int i; hp->dirseg[j].n = 1; break; } - copystruct(hp->dirseg+j, hp->dirseg+(j-1)); + *(hp->dirseg+j) = *(hp->dirseg+(j-1)); } do { /* check neighbors */ mindist = nbeams(hp); /* find closest */ @@ -279,7 +284,7 @@ int i; hp->dirseg[minpos].n - hp->dirseg[j].s; hp->dirty--; while (++j < hp->dirty) /* close the gap */ - copystruct(hp->dirseg+j, hp->dirseg+(j+1)); + *(hp->dirseg+j) = *(hp->dirseg+(j+1)); } while (mindist <= MINDIRSEL); } @@ -355,9 +360,9 @@ int fd; if (fd < 0) return(-1); if (fd >= nhdfragls || !hdfragl[fd].nlinks) { - if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, 1)) < 0) return(-1); - flen = lseek(fd, (off_t)0L, 2); + flen = lseek(fd, (off_t)0, 2); lseek(fd, fpos, 0); return(flen); } @@ -401,7 +406,7 @@ int nr; /* number of new rays desired */ int n; if (nr <= 0) return(NULL); - CHECK(i < 1 | i > nbeams(hp), + CHECK((i < 1) | (i > nbeams(hp)), CONSISTENCY, "bad beam index given to hdnewrays"); if (hp->bl[i] != NULL) hp->bl[i]->tick = hdclock; /* preempt swap */ @@ -429,7 +434,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((void *)p, nr*sizeof(RAYVAL)); + memset((void *)p, '\0', nr*sizeof(RAYVAL)); blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */ return(p); /* point to new rays */ } @@ -442,7 +447,7 @@ register int i; { register int n; - CHECK(i < 1 | i > nbeams(hp), + CHECK((i < 1) | (i > nbeams(hp)), CONSISTENCY, "bad beam index given to hdgetbeam"); if (hp->bl[i] == NULL) { /* load from disk */ if (!(n = hp->bi[i].nrd)) @@ -469,15 +474,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); @@ -487,7 +492,7 @@ register HDBEAMI *hb1, *hb2; hdloadbeams(hb, n, bf) /* load a list of beams in optimal order */ register HDBEAMI *hb; /* list gets sorted by hdfilord() */ int n; /* list length */ -int (*bf)(); /* callback function (optional) */ +void (*bf)(); /* callback function (optional) */ { unsigned origcachesize, memuse; int bytesloaded, needbytes, bytes2free; @@ -496,7 +501,7 @@ int (*bf)(); /* callback function (optional) */ /* precheck consistency */ if (n <= 0) return; for (i = n; i--; ) - if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) + 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((void *)hb, n, sizeof(HDBEAMI), hdfilord); @@ -551,7 +556,7 @@ int i; if (++k >= f->nfrags) goto endloop; if (k > j) - copystruct(f->fi+j, f->fi+k); + *(f->fi+j) = *(f->fi+k); } endloop: f->nfrags = j; @@ -583,7 +588,7 @@ int i; f->fi[j].nrd = bi->nrd; break; } - copystruct(f->fi+j, f->fi+(j-1)); + *(f->fi+j) = *(f->fi+(j-1)); } /* coalesce adjacent fragments */ /* successors never empty */ @@ -602,7 +607,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); } @@ -612,12 +617,12 @@ int hdfragOK(fd, listlen, listsiz) /* get fragment list status for file */ int fd; int *listlen; -register int4 *listsiz; +register int32 *listsiz; { register struct fraglist *f; register int i; - if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks) + if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) return(0); /* listless */ if (listlen != NULL) *listlen = f->nfrags; @@ -635,7 +640,7 @@ register int4 *listsiz; off_t hdallocfrag(fd, nrays) /* allocate a file fragment */ int fd; -unsigned int4 nrays; +uint32 nrays; { register struct fraglist *f; register int j; @@ -667,7 +672,7 @@ register HOLO *hp; register int i; { int fragfreed; - unsigned int4 nrays; + uint32 nrays; unsigned int n; off_t nfo; /* check file status */ @@ -693,7 +698,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) @@ -757,7 +762,7 @@ register int i; return(nchanged); } if (i == 0) { /* clobber entire holodeck */ - if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0) + if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0)) return(0); /* already empty */ nchanged = 0; nchanged = 0; @@ -781,7 +786,7 @@ register int i; 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); @@ -813,7 +818,7 @@ register HOLO *hp; /* section we're adding from */ hb[j].b = i; break; } - copystruct(hb+j, hb+(j-1)); + *(hb+j) = *(hb+(j-1)); } } return(nents); /* return new list length */