ViewVC Help
View File | Revision Log | Show Annotations | Download File | Root Listing
root/radiance/ray/src/hd/holofile.c
(Generate patch)

Comparing ray/src/hd/holofile.c (file contents):
Revision 3.40 by gwlarson, Fri Mar 12 09:37:48 1999 UTC vs.
Revision 3.41 by gwlarson, Thu Aug 5 15:53:09 1999 UTC

# Line 1 | Line 1
1 < /* Copyright (c) 1999 Silicon Graphics, Inc. */
1 > /* Copyright (c) 1999 Regents of the University of California */
2  
3   #ifndef lint
4   static char SCCSid[] = "$SunId$ SGI";
# Line 52 | Line 52 | HOLO   *hdlist[HDMAX+1];       /* holodeck pointers (NULL term
52  
53   static struct fraglist {
54          short   nlinks;         /* number of holodeck sections using us */
55 <        short   writerr;        /* write error encountered */
55 >        short   writable;       /* 0 read-only, <0 write error encountered */
56          int     nfrags;         /* number of known fragments */
57          BEAMI   *fi;            /* fragments, descending file position */
58          long    flen;           /* last known file length */
# Line 119 | Line 119 | char   *rout;
119   }
120  
121  
122 < hdattach(fd)            /* start tracking file fragments for some section */
122 > hdattach(fd, wr)        /* start tracking file fragments for some section */
123   register int    fd;
124 + int     wr;
125   {
126          if (fd >= nhdfragls) {
127                  hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl,
# Line 130 | Line 131 | register int   fd;
131                  nhdfragls = fd+1;
132          }
133          hdfragl[fd].nlinks++;
134 +        hdfragl[fd].writable = wr;              /* set writable flag */
135          hdfragl[fd].flen = lseek(fd, 0L, 2);    /* get file length */
136   }
137  
# Line 157 | Line 159 | HDGRID *hproto;                /* holodeck section grid */
159   {
160          long    rtrunc;
161          long    fpos;
162 +        int     writable;
163          register HOLO   *hp;
164          register int    n;
165                                          /* prepare for system errors */
# Line 182 | Line 185 | HDGRID *hproto;                /* holodeck section grid */
185                                  error(WARNING, "dirty holodeck section");
186                                  break;
187                          }
188 <        } else {                        /* assume we're creating it */
188 >                                                /* check writability */
189 >                if (fd < nhdfragls && hdfragl[fd].nlinks)
190 >                        writable = hdfragl[fd].writable;
191 >                else
192 >                        writable = lseek(fd, fpos, 0) == fpos &&
193 >                                write(fd, (char *)hp, sizeof(HDGRID)) ==
194 >                                                        sizeof(HDGRID);
195 >        } else {                        /* else assume we're creating it */
196                  if ((hp = hdalloc(hproto)) == NULL)
197                          goto memerr;
198                                                  /* write header and skeleton */
# Line 191 | Line 201 | HDGRID *hproto;                /* holodeck section grid */
201                                          sizeof(HDGRID) ||
202                                  write(fd, (char *)(hp->bi+1), n) != n)
203                          error(SYSTEM, "cannot write header to holodeck file");
204 +                writable = 1;
205          }
206          hp->fd = fd;    
207          hp->dirty = 0;
208          biglob(hp)->fo = fpos + sizeof(HDGRID);
209                                          /* start tracking fragments */
210 <        hdattach(fd);
210 >        hdattach(fd, writable);
211                                          /* check rays on disk */
212          fpos = hdfilen(fd);
213          biglob(hp)->nrd = rtrunc = 0;
# Line 535 | Line 546 | int    i;
546          DCHECK(hp->fd < 0 | hp->fd >= nhdfragls || !hdfragl[hp->fd].nlinks,
547                          CONSISTENCY, "bad file descriptor in hdfreefrag");
548          f = &hdfragl[hp->fd];
549 +        if (!f->writable)
550 +                return(0);
551          if (f->nfrags % FRAGBLK == 0) { /* delete empty remnants */
552                  for (j = k = 0; k < f->nfrags; j++, k++) {
553                          while (f->fi[k].nrd == 0)
# Line 661 | Line 674 | register int   i;
674          unsigned int    n;
675          long    nfo;
676                                          /* check file status */
677 <        if (hdfragl[hp->fd].writerr)
678 <                return(-1);
677 >        if (hdfragl[hp->fd].writable <= 0)
678 >                return(hdfragl[hp->fd].writable);
679          DCHECK(i < 1 | i > nbeams(hp),
680                          CONSISTENCY, "bad beam index in hdsyncbeam");
681                                          /* is current fragment OK? */
# Line 677 | Line 690 | register int   i;
690                          error(SYSTEM, "cannot seek on holodeck file");
691                  n = hp->bl[i]->nrm * sizeof(RAYVAL);
692                  if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) {
693 <                        hdfragl[hp->fd].writerr++;
693 >                        hdfragl[hp->fd].writable = -1;
694                          hdsync(NULL, 0);        /* sync directories */
695                          error(SYSTEM, "write error in hdsyncbeam");
696                  }
# Line 705 | Line 718 | register int   i;
718                          nchanged += hdfreebeam(hdlist[i], 0);
719                  return(nchanged);
720          }
721 <        if (hdfragl[hp->fd].writerr)    /* check for file error */
721 >        if (hdfragl[hp->fd].writable < 0)       /* check for file error */
722                  return(0);
723          if (i == 0) {                   /* clear entire holodeck */
724                  if (blglob(hp)->nrm == 0)
# Line 758 | Line 771 | register int   i;
771                                  CONSISTENCY, "bad beam count in hdkillbeam");
772                  return(nchanged);
773          }
774 <        DCHECK(i < 1 | i > nbeams(hp),
775 <                        CONSISTENCY, "bad beam index to hdkillbeam");
774 >        DCHECK(i < 1 | i > nbeams(hp), CONSISTENCY,
775 >                        "bad beam index to hdkillbeam");
776 >        DCHECK(!hdfragl[hp->fd].writable, CONSISTENCY,
777 >                        "hdkillbeam called on read-only holodeck");
778          if (hp->bl[i] != NULL) {        /* free memory */
779                  blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm;
780                  free((char *)hp->bl[i]);

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines