30 |
|
#endif |
31 |
|
#ifndef FF_DEFAULT |
32 |
|
/* when to free a beam fragment */ |
33 |
< |
#define FF_DEFAULT (FF_ALLOC|FF_WRITE|FF_KILL) |
33 |
> |
#define FF_DEFAULT (FF_WRITE|FF_KILL) |
34 |
|
#endif |
35 |
|
#ifndef MINDIRSEL |
36 |
|
/* minimum directory seek length */ |
61 |
|
static int nhdfragls; /* size of hdfragl array */ |
62 |
|
|
63 |
|
|
64 |
+ |
HOLO * |
65 |
+ |
hdalloc(hproto) /* allocate and set holodeck section based on grid */ |
66 |
+ |
HDGRID *hproto; |
67 |
+ |
{ |
68 |
+ |
HOLO hdhead; |
69 |
+ |
register HOLO *hp; |
70 |
+ |
int n; |
71 |
+ |
/* copy grid to temporary header */ |
72 |
+ |
bcopy((char *)hproto, (char *)&hdhead, sizeof(HDGRID)); |
73 |
+ |
/* compute grid vectors and sizes */ |
74 |
+ |
hdcompgrid(&hdhead); |
75 |
+ |
/* allocate header with directory */ |
76 |
+ |
n = sizeof(HOLO)+nbeams(&hdhead)*sizeof(BEAMI); |
77 |
+ |
if ((hp = (HOLO *)malloc(n)) == NULL) |
78 |
+ |
return(NULL); |
79 |
+ |
/* copy header information */ |
80 |
+ |
copystruct(hp, &hdhead); |
81 |
+ |
/* allocate and clear beam list */ |
82 |
+ |
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
83 |
+ |
if (hp->bl == NULL) { |
84 |
+ |
free((char *)hp); |
85 |
+ |
return(NULL); |
86 |
+ |
} |
87 |
+ |
bzero((char *)hp->bl, (nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
88 |
+ |
hp->bl[0] = (BEAM *)(hp->bl+nbeams(hp)+1); /* set blglob(hp) */ |
89 |
+ |
hp->fd = -1; |
90 |
+ |
hp->dirty = 0; |
91 |
+ |
hp->priv = NULL; |
92 |
+ |
/* clear beam directory */ |
93 |
+ |
bzero((char *)hp->bi, (nbeams(hp)+1)*sizeof(BEAMI)); |
94 |
+ |
return(hp); /* all is well */ |
95 |
+ |
} |
96 |
+ |
|
97 |
+ |
|
98 |
|
char * |
99 |
|
hdrealloc(ptr, siz, rout) /* (re)allocate memory, retry then error */ |
100 |
|
char *ptr; |
593 |
|
biglob(hp)->nrd -= bi->nrd; /* tell fragment it's free */ |
594 |
|
bi->nrd = 0; |
595 |
|
bi->fo = 0L; |
596 |
+ |
hdmarkdirty(hp, i); /* assume we'll reallocate */ |
597 |
|
return(1); |
598 |
|
} |
599 |
|
|
656 |
|
register HOLO *hp; |
657 |
|
register int i; |
658 |
|
{ |
659 |
+ |
int fragfreed; |
660 |
|
unsigned int4 nrays; |
661 |
|
unsigned int n; |
662 |
|
long nfo; |
668 |
|
/* is current fragment OK? */ |
669 |
|
if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd) |
670 |
|
return(0); |
671 |
< |
if (hdfragflags&FF_WRITE && hp->bi[i].nrd) |
672 |
< |
hdfreefrag(hp, i); /* relinquish old fragment */ |
671 |
> |
/* relinquish old fragment? */ |
672 |
> |
fragfreed = hdfragflags&FF_WRITE && hp->bi[i].nrd && hdfreefrag(hp,i); |
673 |
|
if (nrays) { /* get and write new fragment */ |
674 |
|
nfo = hdallocfrag(hp->fd, nrays); |
675 |
|
errno = 0; |
686 |
|
hp->bi[i].fo = 0L; |
687 |
|
biglob(hp)->nrd += nrays - hp->bi[i].nrd; |
688 |
|
hp->bi[i].nrd = nrays; |
689 |
< |
hdmarkdirty(hp, i); /* section directory now out of date */ |
689 |
> |
if (!fragfreed) |
690 |
> |
hdmarkdirty(hp, i); /* need to flag dir. ent. */ |
691 |
|
return(1); |
692 |
|
} |
693 |
|
|
763 |
|
if (hp->bl[i] != NULL) { /* free memory */ |
764 |
|
blglob(hp)->nrm -= nchanged = hp->bl[i]->nrm; |
765 |
|
free((char *)hp->bl[i]); |
766 |
+ |
hp->bl[i] = NULL; |
767 |
|
} else |
768 |
|
nchanged = hp->bi[i].nrd; |
769 |
< |
if (hp->bi[i].nrd) { |
770 |
< |
if (hdfragflags&FF_KILL) |
771 |
< |
hdfreefrag(hp, i); |
734 |
< |
biglob(hp)->nrd -= hp->bi[i].nrd; |
735 |
< |
hp->bi[i].nrd = 0; /* make sure it's gone */ |
769 |
> |
if (hp->bi[i].nrd && !(hdfragflags&FF_KILL && hdfreefrag(hp,i))) { |
770 |
> |
biglob(hp)->nrd -= hp->bi[i].nrd; /* free failed */ |
771 |
> |
hp->bi[i].nrd = 0; |
772 |
|
hp->bi[i].fo = 0L; |
773 |
+ |
hdmarkdirty(hp, i); |
774 |
|
} |
738 |
– |
hp->bl[i] = NULL; |
775 |
|
return(nchanged); |
776 |
|
} |
777 |
|
|