18 |
|
|
19 |
|
#ifndef CACHESIZE |
20 |
|
#ifdef SMLMEM |
21 |
< |
#define CACHESIZE 5 |
21 |
> |
#define CACHESIZE 100 |
22 |
|
#else |
23 |
< |
#define CACHESIZE 17 /* default cache size (Mbytes, 0==inf) */ |
23 |
> |
#define CACHESIZE 1000 /* default cache size (Mbytes, 0==inf) */ |
24 |
|
#endif |
25 |
|
#endif |
26 |
|
#ifndef FREEBEAMS |
30 |
|
#define PCTFREE 15 /* maximum fraction to free (%) */ |
31 |
|
#endif |
32 |
|
#ifndef MAXFRAGB |
33 |
< |
#define MAXFRAGB 16 /* fragment blocks/file to track (0==inf) */ |
33 |
> |
#define MAXFRAGB 64 /* fragment blocks/file to track (0==inf) */ |
34 |
|
#endif |
35 |
|
#ifndef FF_DEFAULT |
36 |
|
/* when to free a beam fragment */ |
42 |
|
#endif |
43 |
|
|
44 |
|
#ifndef BSD |
45 |
+ |
#ifdef write /* platform.h renames those for Windows */ |
46 |
+ |
#undef write |
47 |
+ |
#endif |
48 |
|
#define write writebuf /* safe i/o routines */ |
49 |
+ |
#ifdef read |
50 |
+ |
#undef read |
51 |
+ |
#endif |
52 |
|
#define read readbuf |
53 |
|
#endif |
54 |
|
|
90 |
|
) |
91 |
|
{ |
92 |
|
HOLO hdhead; |
93 |
< |
register HOLO *hp; |
93 |
> |
HOLO *hp; |
94 |
|
int n; |
95 |
|
/* copy grid to temporary header */ |
96 |
|
memcpy((void *)&hdhead, (void *)hproto, sizeof(HDGRID)); |
126 |
|
char *rout |
127 |
|
) |
128 |
|
{ |
129 |
< |
register char *newp; |
129 |
> |
char *newp; |
130 |
|
/* call malloc/realloc */ |
131 |
|
if (ptr == NULL) newp = (char *)malloc(siz); |
132 |
|
else newp = (char *)realloc((void *)ptr, siz); |
146 |
|
|
147 |
|
void |
148 |
|
hdattach( /* start tracking file fragments for some section */ |
149 |
< |
register int fd, |
149 |
> |
int fd, |
150 |
|
int wr |
151 |
|
) |
152 |
|
{ |
169 |
|
|
170 |
|
void |
171 |
|
hdrelease( /* stop tracking file fragments for some section */ |
172 |
< |
register int fd |
172 |
> |
int fd |
173 |
|
) |
174 |
|
{ |
175 |
|
if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) |
182 |
|
} |
183 |
|
|
184 |
|
|
185 |
< |
extern HOLO * |
185 |
> |
HOLO * |
186 |
|
hdinit( /* initialize a holodeck section in a file */ |
187 |
|
int fd, /* corresponding file descriptor */ |
188 |
|
HDGRID *hproto /* holodeck section grid */ |
191 |
|
off_t rtrunc; |
192 |
|
off_t fpos; |
193 |
|
int writable; |
194 |
< |
register HOLO *hp; |
195 |
< |
register int n; |
194 |
> |
HOLO *hp; |
195 |
> |
int n; |
196 |
|
/* prepare for system errors */ |
197 |
|
errno = 0; |
198 |
|
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
252 |
|
} |
253 |
|
if (rtrunc) { |
254 |
|
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
255 |
< |
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
255 |
> |
(long)rtrunc, |
256 |
> |
100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
257 |
|
error(WARNING, errmsg); |
258 |
|
} |
259 |
|
/* add to holodeck list */ |
272 |
|
|
273 |
|
void |
274 |
|
hdmarkdirty( /* mark holodeck directory position dirty */ |
275 |
< |
register HOLO *hp, |
275 |
> |
HOLO *hp, |
276 |
|
int i |
277 |
|
) |
278 |
|
{ |
279 |
|
static BEAMI smudge = {0, -1}; |
280 |
|
int mindist, minpos; |
281 |
< |
register int j; |
281 |
> |
int j; |
282 |
|
|
283 |
|
if (!hp->dirty++) { /* write smudge first time */ |
284 |
|
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), |
324 |
|
} |
325 |
|
|
326 |
|
|
327 |
< |
extern int |
327 |
> |
int |
328 |
|
hdsync( /* update beams and directory on disk */ |
329 |
< |
register HOLO *hp, |
329 |
> |
HOLO *hp, |
330 |
|
int all |
331 |
|
) |
332 |
|
{ |
333 |
< |
register int j, n; |
333 |
> |
int j, n; |
334 |
|
|
335 |
|
if (hp == NULL) { /* do all holodecks */ |
336 |
|
n = 0; |
364 |
|
) |
365 |
|
{ |
366 |
|
long total = 0; |
367 |
< |
register int i, j; |
367 |
> |
int i, j; |
368 |
|
|
369 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
370 |
|
total += blglob(hdlist[j])->nrm * sizeof(RAYVAL); |
388 |
|
} |
389 |
|
|
390 |
|
|
391 |
< |
extern off_t |
391 |
> |
off_t |
392 |
|
hdfilen( /* return file length for fd */ |
393 |
|
int fd |
394 |
|
) |
408 |
|
} |
409 |
|
|
410 |
|
|
411 |
< |
extern off_t |
411 |
> |
off_t |
412 |
|
hdfiluse( /* compute file usage (in bytes) */ |
413 |
< |
int fd, /* open file descriptor to check */ |
407 |
< |
int all /* include overhead and unflushed data */ |
413 |
> |
int fd /* open file descriptor to check */ |
414 |
|
) |
415 |
|
{ |
416 |
|
off_t total = 0; |
417 |
< |
register int i, j; |
417 |
> |
int j; |
418 |
|
|
419 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
420 |
|
if (hdlist[j]->fd != fd) |
421 |
|
continue; |
422 |
|
total += biglob(hdlist[j])->nrd * sizeof(RAYVAL); |
423 |
< |
if (all) { |
424 |
< |
for (i = nbeams(hdlist[j]); i > 0; i--) |
425 |
< |
if (hdlist[j]->bl[i] != NULL) |
426 |
< |
total += sizeof(RAYVAL) * |
423 |
> |
total += nbeams(hdlist[j])*sizeof(BEAMI) + sizeof(HDGRID); |
424 |
> |
#if 0 |
425 |
> |
for (i = nbeams(hdlist[j]); i > 0; i--) |
426 |
> |
if (hdlist[j]->bl[i] != NULL) |
427 |
> |
total += sizeof(RAYVAL) * |
428 |
|
(hdlist[j]->bl[i]->nrm - |
429 |
|
hdlist[j]->bi[i].nrd); |
430 |
< |
total += sizeof(HDGRID) + |
424 |
< |
nbeams(hdlist[j])*sizeof(BEAMI); |
425 |
< |
} |
430 |
> |
#endif |
431 |
|
} |
432 |
< |
return(total); /* does not include fragments */ |
432 |
> |
return(total); /* doesn't include fragments, unflushed rays */ |
433 |
|
} |
434 |
|
|
435 |
|
|
436 |
< |
extern RAYVAL * |
436 |
> |
RAYVAL * |
437 |
|
hdnewrays( /* allocate space for add'l rays and return pointer */ |
438 |
< |
register HOLO *hp, |
439 |
< |
register int i, |
438 |
> |
HOLO *hp, |
439 |
> |
int i, |
440 |
|
int nr /* number of new rays desired */ |
441 |
|
) |
442 |
|
{ |
478 |
|
} |
479 |
|
|
480 |
|
|
481 |
< |
extern BEAM * |
481 |
> |
BEAM * |
482 |
|
hdgetbeam( /* get beam (from file if necessary) */ |
483 |
< |
register HOLO *hp, |
484 |
< |
register int i |
483 |
> |
HOLO *hp, |
484 |
> |
int i |
485 |
|
) |
486 |
|
{ |
487 |
< |
register int n; |
487 |
> |
int n; |
488 |
|
|
489 |
|
CHECK((i < 1) | (i > nbeams(hp)), |
490 |
|
CONSISTENCY, "bad beam index given to hdgetbeam"); |
511 |
|
|
512 |
|
int |
513 |
|
hdfilord( /* order beams for quick loading */ |
514 |
< |
register const void *hb1, |
515 |
< |
register const void *hb2 |
514 |
> |
const void *hb1, |
515 |
> |
const void *hb2 |
516 |
|
) |
517 |
|
{ |
518 |
< |
register off_t c; |
518 |
> |
off_t c; |
519 |
|
/* residents go first */ |
520 |
|
if (((HDBEAMI*)hb2)->h->bl[((HDBEAMI*)hb2)->b] != NULL) |
521 |
|
return(((HDBEAMI*)hb1)->h->bl[((HDBEAMI*)hb1)->b] == NULL); |
531 |
|
} |
532 |
|
|
533 |
|
|
534 |
< |
extern void |
534 |
> |
void |
535 |
|
hdloadbeams( /* load a list of beams in optimal order */ |
536 |
< |
register HDBEAMI *hb, /* list gets sorted by hdfilord() */ |
536 |
> |
HDBEAMI *hb, /* list gets sorted by hdfilord() */ |
537 |
|
int n, /* list length */ |
538 |
|
void (*bf)(BEAM *bp, HDBEAMI *hb) /* callback function (optional) */ |
539 |
|
) |
540 |
|
{ |
541 |
|
unsigned origcachesize, memuse; |
542 |
|
int bytesloaded, needbytes, bytes2free; |
543 |
< |
register BEAM *bp; |
544 |
< |
register int i; |
543 |
> |
BEAM *bp; |
544 |
> |
int i; |
545 |
|
/* precheck consistency */ |
546 |
|
if (n <= 0) return; |
547 |
|
for (i = n; i--; ) |
578 |
|
} |
579 |
|
|
580 |
|
|
581 |
< |
extern int |
581 |
> |
int |
582 |
|
hdfreefrag( /* free a file fragment */ |
583 |
|
HOLO *hp, |
584 |
|
int i |
585 |
|
) |
586 |
|
{ |
587 |
< |
register BEAMI *bi = &hp->bi[i]; |
588 |
< |
register struct fraglist *f; |
589 |
< |
register int j, k; |
587 |
> |
BEAMI *bi = &hp->bi[i]; |
588 |
> |
struct fraglist *f; |
589 |
> |
int j, k; |
590 |
|
|
591 |
|
if (bi->nrd <= 0) |
592 |
|
return(0); |
615 |
|
} |
616 |
|
#endif |
617 |
|
if (j % FRAGBLK == 0) { /* more (or less) free list space */ |
618 |
< |
register BEAMI *newp; |
618 |
> |
BEAMI *newp; |
619 |
|
if (f->fi == NULL) |
620 |
|
newp = (BEAMI *)malloc((j+FRAGBLK)*sizeof(BEAMI)); |
621 |
|
else |
658 |
|
} |
659 |
|
|
660 |
|
|
661 |
< |
extern int |
661 |
> |
int |
662 |
|
hdfragOK( /* get fragment list status for file */ |
663 |
|
int fd, |
664 |
|
int *listlen, |
665 |
< |
register int32 *listsiz |
665 |
> |
int32 *listsiz |
666 |
|
) |
667 |
|
{ |
668 |
< |
register struct fraglist *f; |
669 |
< |
register int i; |
668 |
> |
struct fraglist *f; |
669 |
> |
int i; |
670 |
|
|
671 |
|
if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) |
672 |
|
return(0); /* listless */ |
689 |
|
uint32 nrays |
690 |
|
) |
691 |
|
{ |
692 |
< |
register struct fraglist *f; |
693 |
< |
register int j; |
692 |
> |
struct fraglist *f; |
693 |
> |
int j; |
694 |
|
off_t nfo; |
695 |
|
|
696 |
|
if (nrays == 0) |
715 |
|
|
716 |
|
int |
717 |
|
hdsyncbeam( /* sync beam in memory with beam on disk */ |
718 |
< |
register HOLO *hp, |
719 |
< |
register int i |
718 |
> |
HOLO *hp, |
719 |
> |
int i |
720 |
|
) |
721 |
|
{ |
722 |
|
int fragfreed; |
755 |
|
} |
756 |
|
|
757 |
|
|
758 |
< |
extern int |
758 |
> |
int |
759 |
|
hdfreebeam( /* free beam, writing if dirty */ |
760 |
< |
register HOLO *hp, |
761 |
< |
register int i |
760 |
> |
HOLO *hp, |
761 |
> |
int i |
762 |
|
) |
763 |
|
{ |
764 |
|
int nchanged; |
797 |
|
} |
798 |
|
|
799 |
|
|
800 |
< |
extern int |
800 |
> |
int |
801 |
|
hdkillbeam( /* delete beam from holodeck */ |
802 |
< |
register HOLO *hp, |
803 |
< |
register int i |
802 |
> |
HOLO *hp, |
803 |
> |
int i |
804 |
|
) |
805 |
|
{ |
806 |
|
int nchanged; |
845 |
|
|
846 |
|
int |
847 |
|
hdlrulist( /* add beams from holodeck to LRU list */ |
848 |
< |
register HDBEAMI *hb, /* beam list */ |
848 |
> |
HDBEAMI *hb, /* beam list */ |
849 |
|
int nents, /* current list length */ |
850 |
|
int n, /* maximum list length */ |
851 |
< |
register HOLO *hp /* section we're adding from */ |
851 |
> |
HOLO *hp /* section we're adding from */ |
852 |
|
) |
853 |
|
{ |
854 |
< |
register int i, j; |
854 |
> |
int i, j; |
855 |
|
/* insert each beam from hp */ |
856 |
|
for (i = 1; i <= nbeams(hp); i++) { |
857 |
|
if (hp->bl[i] == NULL) /* check if loaded */ |
879 |
|
int |
880 |
|
hdfreecache( /* free up cache space, writing changes */ |
881 |
|
int pct, /* maximum percentage to free */ |
882 |
< |
register HOLO *honly /* NULL means check all */ |
882 |
> |
HOLO *honly /* NULL means check all */ |
883 |
|
) |
884 |
|
{ |
885 |
|
HDBEAMI hb[FREEBEAMS]; |
886 |
|
int freetarget; |
887 |
|
int n; |
888 |
< |
register int i; |
888 |
> |
int i; |
889 |
|
#ifdef DEBUG |
890 |
|
unsigned membefore; |
891 |
|
|
921 |
|
} |
922 |
|
|
923 |
|
|
924 |
< |
extern void |
924 |
> |
void |
925 |
|
hddone( /* clean up holodeck section and free */ |
926 |
< |
register HOLO *hp /* NULL means clean up all */ |
926 |
> |
HOLO *hp /* NULL means clean up all */ |
927 |
|
) |
928 |
|
{ |
929 |
< |
register int i; |
929 |
> |
int i; |
930 |
|
|
931 |
|
if (hp == NULL) { /* NULL means clean up everything */ |
932 |
|
while (hdlist[0] != NULL) |