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.41 by gwlarson, Thu Aug 5 15:53:09 1999 UTC vs.
Revision 3.47 by greg, Fri Jun 13 15:27:04 2003 UTC

# Line 1 | Line 1
1 /* Copyright (c) 1999 Regents of the University of California */
2
1   #ifndef lint
2 < static char SCCSid[] = "$SunId$ SGI";
2 > static const char       RCSid[] = "$Id$";
3   #endif
6
4   /*
5   * Routines for managing holodeck files
6   *
# Line 13 | Line 10 | static char SCCSid[] = "$SunId$ SGI";
10   #include "holo.h"
11  
12   #ifndef CACHESIZE
13 < #ifdef BIGMEM
17 < #define CACHESIZE       17      /* default cache size (Mbytes, 0==inf) */
18 < #else
13 > #ifdef SMLMEM
14   #define CACHESIZE       5
15 + #else
16 + #define CACHESIZE       17      /* default cache size (Mbytes, 0==inf) */
17   #endif
18   #endif
19   #ifndef FREEBEAMS
# Line 55 | Line 52 | static struct fraglist {
52          short   writable;       /* 0 read-only, <0 write error encountered */
53          int     nfrags;         /* number of known fragments */
54          BEAMI   *fi;            /* fragments, descending file position */
55 <        long    flen;           /* last known file length */
55 >        off_t   flen;           /* last known file length */
56   } *hdfragl;             /* fragment lists, indexed by file descriptor */
57  
58   static int      nhdfragls;      /* size of hdfragl array */
# Line 69 | Line 66 | HDGRID *hproto;
66          register HOLO   *hp;
67          int     n;
68                                  /* copy grid to temporary header */
69 <        bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID));
69 >        bcopy((void *)hproto, (void *)&hdhead, sizeof(HDGRID));
70                                  /* compute grid vectors and sizes */
71          hdcompgrid(&hdhead);
72                                  /* allocate header with directory */
# Line 81 | Line 78 | HDGRID *hproto;
78                                  /* allocate and clear beam list */
79          hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
80          if (hp->bl == NULL) {
81 <                free((char *)hp);
81 >                free((void *)hp);
82                  return(NULL);
83          }
84 <        bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
84 >        bzero((void *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM));
85          hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1);      /* set blglob(hp) */
86          hp->fd = -1;
87          hp->dirty = 0;
88          hp->priv = NULL;
89                                  /* clear beam directory */
90 <        bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI));
90 >        bzero((void *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI));
91          return(hp);             /* all is well */
92   }
93  
# Line 104 | Line 101 | char   *rout;
101          register char   *newp;
102                                          /* call malloc/realloc */
103          if (ptr == NULL) newp = (char *)malloc(siz);
104 <        else newp = (char *)realloc(ptr, siz);
104 >        else newp = (char *)realloc((void *)ptr, siz);
105                                          /* check success */
106          if (newp == NULL && rout != NULL) {
107                  hdfreecache(25, NULL);  /* free some memory */
# Line 126 | Line 123 | int    wr;
123          if (fd >= nhdfragls) {
124                  hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl,
125                                  (fd+1)*sizeof(struct fraglist), "hdattach");
126 <                bzero((char *)(hdfragl+nhdfragls),
126 >                bzero((void *)(hdfragl+nhdfragls),
127                                  (fd+1-nhdfragls)*sizeof(struct fraglist));
128                  nhdfragls = fd+1;
129          }
130          hdfragl[fd].nlinks++;
131          hdfragl[fd].writable = wr;              /* set writable flag */
132 <        hdfragl[fd].flen = lseek(fd, 0L, 2);    /* get file length */
132 >        hdfragl[fd].flen = lseek(fd, (off_t)0, 2);      /* get file length */
133   }
134  
135  
# Line 145 | Line 142 | register int   fd;
142          if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks)
143                  return;
144          if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) {
145 <                free((char *)hdfragl[fd].fi);
145 >                free((void *)hdfragl[fd].fi);
146                  hdfragl[fd].fi = NULL;
147                  hdfragl[fd].nfrags = 0;
148          }
# Line 157 | Line 154 | hdinit(fd, hproto)     /* initialize a holodeck section in
154   int     fd;                     /* corresponding file descriptor */
155   HDGRID  *hproto;                /* holodeck section grid */
156   {
157 <        long    rtrunc;
158 <        long    fpos;
157 >        off_t   rtrunc;
158 >        off_t   fpos;
159          int     writable;
160          register HOLO   *hp;
161          register int    n;
162                                          /* prepare for system errors */
163          errno = 0;
164 <        if ((fpos = lseek(fd, 0L, 1)) < 0)
164 >        if ((fpos = lseek(fd, (off_t)0, 1)) < 0)
165                  error(SYSTEM, "cannot determine holodeck file position");
166          if (hproto == NULL) {           /* assume we're loading it */
167                  HDGRID  hpr;
# Line 349 | Line 346 | int    all;                    /* include overhead (painful) */
346   }
347  
348  
349 < long
349 > off_t
350   hdfilen(fd)             /* return file length for fd */
351   int     fd;
352   {
353 <        long    fpos, flen;
353 >        off_t   fpos, flen;
354  
355          if (fd < 0)
356                  return(-1);
357          if (fd >= nhdfragls || !hdfragl[fd].nlinks) {
358 <                if ((fpos = lseek(fd, 0L, 1)) < 0)
358 >                if ((fpos = lseek(fd, (off_t)0, 1)) < 0)
359                          return(-1);
360 <                flen = lseek(fd, 0L, 2);
360 >                flen = lseek(fd, (off_t)0, 2);
361                  lseek(fd, fpos, 0);
362                  return(flen);
363          }
# Line 368 | Line 365 | int    fd;
365   }
366  
367  
368 < long
368 > off_t
369   hdfiluse(fd, all)       /* compute file usage (in bytes) */
370   int     fd;                     /* open file descriptor to check */
371   int     all;                    /* include overhead and unflushed data */
372   {
373 <        long    total = 0;
373 >        off_t   total = 0;
374          register int    i, j;
375  
376          for (j = 0; hdlist[j] != NULL; j++) {
# Line 432 | Line 429 | int    nr;                     /* number of new rays desired */
429                  hdfreefrag(hp, i);              /* relinquish old fragment */
430          p = hdbray(hp->bl[i]) + hp->bl[i]->nrm;
431          hp->bl[i]->nrm += nr;                   /* update in-core structure */
432 <        bzero((char *)p, nr*sizeof(RAYVAL));
432 >        bzero((void *)p, nr*sizeof(RAYVAL));
433          blglob(hp)->tick = hp->bl[i]->tick = hdclock++; /* update LRU clock */
434          return(p);                              /* point to new rays */
435   }
# Line 472 | Line 469 | int
469   hdfilord(hb1, hb2)      /* order beams for quick loading */
470   register HDBEAMI        *hb1, *hb2;
471   {
472 <        register long   c;
472 >        register off_t  c;
473                                  /* residents go first */
474          if (hb2->h->bl[hb2->b] != NULL)
475                  return(hb1->h->bl[hb1->b] == NULL);
476          if (hb1->h->bl[hb1->b] != NULL)
477                  return(-1);
478                                  /* otherwise sort by file descriptor */
479 <        if ((c = hb1->h->fd - hb2->h->fd))
480 <                return(c);
479 >        if (hb1->h->fd != hb2->h->fd)
480 >                return(hb1->h->fd - hb2->h->fd);
481                                  /* then by position in file */
482          c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo;
483          return(c > 0 ? 1 : c < 0 ? -1 : 0);
# Line 502 | Line 499 | int    (*bf)();                /* callback function (optional) */
499                  if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h))
500                          error(CONSISTENCY, "bad beam in hdloadbeams");
501                                          /* sort list for optimal access */
502 <        qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord);
502 >        qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord);
503          bytesloaded = 0;                /* run through loaded beams */
504          for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) {
505                  bp->tick = hdclock;     /* preempt swap */
# Line 572 | Line 569 | int    i;
569                  if (f->fi == NULL)
570                          newp = (BEAMI *)malloc((j+FRAGBLK)*sizeof(BEAMI));
571                  else
572 <                        newp = (BEAMI *)realloc((char *)f->fi,
572 >                        newp = (BEAMI *)realloc((void *)f->fi,
573                                          (j+FRAGBLK)*sizeof(BEAMI));
574                  if (newp == NULL) {
575                          f->nfrags--;    /* graceful failure */
# Line 605 | Line 602 | int    i;
602                  }
603          biglob(hp)->nrd -= bi->nrd;             /* tell fragment it's free */
604          bi->nrd = 0;
605 <        bi->fo = 0L;
605 >        bi->fo = 0;
606          hdmarkdirty(hp, i);                     /* assume we'll reallocate */
607          return(1);
608   }
# Line 635 | Line 632 | register int4  *listsiz;
632   }
633  
634  
635 < long
635 > off_t
636   hdallocfrag(fd, nrays)          /* allocate a file fragment */
637   int     fd;
638   unsigned int4   nrays;
639   {
640          register struct fraglist        *f;
641          register int    j;
642 <        long    nfo;
642 >        off_t   nfo;
643  
644          if (nrays == 0)
645                  return(-1L);
# Line 672 | Line 669 | register int   i;
669          int     fragfreed;
670          unsigned int4   nrays;
671          unsigned int    n;
672 <        long    nfo;
672 >        off_t   nfo;
673                                          /* check file status */
674          if (hdfragl[hp->fd].writable <= 0)
675                  return(hdfragl[hp->fd].writable);
# Line 696 | Line 693 | register int   i;
693                  }
694                  hp->bi[i].fo = nfo;
695          } else
696 <                hp->bi[i].fo = 0L;
696 >                hp->bi[i].fo = 0;
697          biglob(hp)->nrd += nrays - hp->bi[i].nrd;
698          hp->bi[i].nrd = nrays;
699          if (!fragfreed)
# Line 740 | Line 737 | register int   i;
737          if (nchanged)
738                  hdsyncbeam(hp, i);              /* write new fragment */
739          blglob(hp)->nrm -= hp->bl[i]->nrm;
740 <        free((char *)hp->bl[i]);                /* free memory */
740 >        free((void *)hp->bl[i]);                /* free memory */
741          hp->bl[i] = NULL;
742          return(nchanged);
743   }
# Line 777 | Line 774 | register int   i;
774                          "hdkillbeam called on read-only holodeck");
775          if (hp->bl[i] != NULL) {        /* free memory */
776                  blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm;
777 <                free((char *)hp->bl[i]);
777 >                free((void *)hp->bl[i]);
778                  hp->bl[i] = NULL;
779          } else
780                  nchanged = hp->bi[i].nrd;
781          if (hp->bi[i].nrd && !(hdfragflags&FF_KILL && hdfreefrag(hp,i))) {
782                  biglob(hp)->nrd -= hp->bi[i].nrd;       /* free failed */
783                  hp->bi[i].nrd = 0;
784 <                hp->bi[i].fo = 0L;
784 >                hp->bi[i].fo = 0;
785                  hdmarkdirty(hp, i);
786          }
787          return(nchanged);
# Line 875 | Line 872 | register HOLO  *hp;            /* NULL means clean up all */
872          if (hp == NULL) {               /* NULL means clean up everything */
873                  while (hdlist[0] != NULL)
874                          hddone(hdlist[0]);
875 <                free((char *)hdfragl);
875 >                free((void *)hdfragl);
876                  hdfragl = NULL; nhdfragls = 0;
877                  return;
878          }
# Line 890 | Line 887 | register HOLO  *hp;            /* NULL means clean up all */
887                                  i++;
888                          break;
889                  }
890 <        free((char *)hp->bl);           /* free beam list */
891 <        free((char *)hp);               /* free holodeck struct */
890 >        free((void *)hp->bl);           /* free beam list */
891 >        free((void *)hp);               /* free holodeck struct */
892   }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines