--- ray/src/hd/holofile.c 1997/11/05 17:28:49 3.5 +++ ray/src/hd/holofile.c 1997/11/11 11:31:54 3.8 @@ -22,8 +22,13 @@ static char SCCSid[] = "$SunId$ SGI"; #define PCTFREE 20 /* maximum fraction to free (%) */ #endif -#define MAXFRAG (128*FRAGBLK) /* maximum fragments per file */ +/* define MAXFRAG if you want to limit fragment tracking memory */ +#ifndef BSD +#define write writebuf /* safe i/o routines */ +#define read readbuf +#endif + #define FRAGBLK 64 /* number of fragments to allocate at a time */ int hdcachesize = CACHESIZE*1024*1024; /* target cache size (bytes) */ @@ -68,7 +73,7 @@ register int fd; hdrelease(fd) /* stop tracking file fragments for some section */ register int fd; { - if (fd >= nhdfrags || !hdfrag[fd].nlinks) + if (fd < 0 | fd >= nhdfrags || !hdfrag[fd].nlinks) return; if (!--hdfrag[fd].nlinks && hdfrag[fd].nfrags) { free((char *)hdfrag[fd].fi); @@ -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; @@ -188,6 +211,25 @@ int all; /* include overhead (painful) */ long +hdfilen(fd) /* return file length for fd */ +int fd; +{ + long fpos, flen; + + if (fd < 0) + return(-1); + if (fd >= nhdfrags || !hdfrag[fd].nlinks) { + if ((fpos = lseek(fd, 0L, 1)) < 0) + return(-1); + flen = lseek(fd, 0L, 2); + lseek(fd, fpos, 0); + return(flen); + } + return(hdfrag[fd].flen); +} + + +long hdfiluse(fd, all) /* compute file usage (in bytes) */ int fd; /* open file descriptor to check */ int all; /* include overhead and unflushed data */ @@ -375,7 +417,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); }