--- ray/src/hd/holofile.c 2003/05/13 17:58:33 3.44 +++ ray/src/hd/holofile.c 2003/06/13 15:27:04 3.47 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: holofile.c,v 3.44 2003/05/13 17:58:33 greg Exp $"; +static const char RCSid[] = "$Id: holofile.c,v 3.47 2003/06/13 15:27:04 greg Exp $"; #endif /* * Routines for managing holodeck files @@ -10,10 +10,10 @@ static const char RCSid[] = "$Id: holofile.c,v 3.44 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 */ @@ -129,7 +129,7 @@ int wr; } 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 */ } @@ -154,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, (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; @@ -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,31 +346,31 @@ 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, (off_t)0L, 1)) < 0) + if ((fpos = lseek(fd, (off_t)0, 1)) < 0) return(-1); - flen = lseek(fd, (off_t)0L, 2); - lseek(fd, (off_t)fpos, 0); + flen = lseek(fd, (off_t)0, 2); + 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) @@ -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) @@ -469,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); @@ -602,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); } @@ -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) { @@ -693,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) @@ -781,7 +781,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);