16 |
|
#define CACHESIZE 16 /* default cache size (Mbytes, 0==inf) */ |
17 |
|
#endif |
18 |
|
#ifndef FREEBEAMS |
19 |
< |
#define FREEBEAMS 1024 /* maximum beams to free at a time */ |
19 |
> |
#define FREEBEAMS 512 /* maximum beams to free at a time */ |
20 |
|
#endif |
21 |
|
#ifndef PCTFREE |
22 |
< |
#define PCTFREE 12 /* maximum fraction to free (%) */ |
22 |
> |
#define PCTFREE 20 /* maximum fraction to free (%) */ |
23 |
|
#endif |
24 |
|
|
25 |
< |
#define MAXFRAG 8192 /* maximum fragments tracked per open file */ |
25 |
> |
#ifndef BSD |
26 |
> |
#define write writebuf /* safe i/o routines */ |
27 |
> |
#define read readbuf |
28 |
> |
#endif |
29 |
|
|
30 |
+ |
#define MAXFRAG (128*FRAGBLK) /* maximum fragments per file */ |
31 |
+ |
|
32 |
|
#define FRAGBLK 64 /* number of fragments to allocate at a time */ |
33 |
|
|
34 |
|
int hdcachesize = CACHESIZE*1024*1024; /* target cache size (bytes) */ |
83 |
|
} |
84 |
|
|
85 |
|
|
86 |
+ |
markdirty(hp) /* mark holodeck section directory dirty */ |
87 |
+ |
register HOLO *hp; |
88 |
+ |
{ |
89 |
+ |
static BEAMI smudge = {0, -1}; |
90 |
+ |
|
91 |
+ |
if (hp->dirty) /* already marked? */ |
92 |
+ |
return; |
93 |
+ |
hp->dirty = 1; |
94 |
+ |
if (lseek(hp->fd, biglob(hp)->fo+(nbeams(hp)-1)*sizeof(BEAMI), 0) < 0 |
95 |
+ |
|| write(hp->fd, (char *)&smudge, |
96 |
+ |
sizeof(BEAMI)) != sizeof(BEAMI)) |
97 |
+ |
error(SYSTEM, "seek/write error in markdirty"); |
98 |
+ |
} |
99 |
+ |
|
100 |
+ |
|
101 |
|
HOLO * |
102 |
|
hdinit(fd, hproto) /* initialize a holodeck section in a file */ |
103 |
|
int fd; /* corresponding file descriptor */ |
122 |
|
n = nbeams(hp)*sizeof(BEAMI); |
123 |
|
if (read(fd, (char *)(hp->bi+1), n) != n) |
124 |
|
error(SYSTEM, "failure loading holodeck directory"); |
125 |
+ |
/* check that it's clean */ |
126 |
+ |
if (hp->bi[nbeams(hp)].fo < 0) |
127 |
+ |
error(USER, "dirty holodeck section"); |
128 |
|
} else { /* assume we're creating it */ |
129 |
|
if ((hp = hdalloc(hproto)) == NULL) |
130 |
|
goto memerr; |
337 |
|
register int j, k; |
338 |
|
/* relinquish old fragment */ |
339 |
|
if (hp->bi[i].nrd) { |
340 |
< |
j = ++f->nfrags; |
340 |
> |
j = f->nfrags++; |
341 |
|
#ifdef MAXFRAG |
342 |
< |
if (j >= MAXFRAG) |
342 |
> |
if (j >= MAXFRAG-1) |
343 |
|
f->nfrags--; |
321 |
– |
else |
344 |
|
#endif |
345 |
< |
if (j % FRAGBLK == 1) { /* more frag. space */ |
345 |
> |
if (j % FRAGBLK == 0) { /* more frag. space */ |
346 |
|
if (f->fi == NULL) |
347 |
|
f->fi = (BEAMI *)malloc( |
348 |
|
FRAGBLK*sizeof(BEAMI)); |
349 |
|
else |
350 |
|
f->fi = (BEAMI *)realloc((char *)f->fi, |
351 |
< |
(FRAGBLK-1+j)*sizeof(BEAMI)); |
351 |
> |
(j+FRAGBLK)*sizeof(BEAMI)); |
352 |
|
if (f->fi == NULL) |
353 |
|
error(SYSTEM, |
354 |
|
"out of memory in hdgetbi"); |
355 |
|
} |
356 |
< |
for ( ; ; ) { /* stick it in our descending list */ |
357 |
< |
if (!--j || hp->bi[i].fo < f->fi[j-1].fo) { |
356 |
> |
for ( ; ; j--) { /* insert in descending list */ |
357 |
> |
if (!j || hp->bi[i].fo < f->fi[j-1].fo) { |
358 |
|
f->fi[j].fo = hp->bi[i].fo; |
359 |
|
f->fi[j].nrd = hp->bi[i].nrd; |
360 |
|
break; |
398 |
|
} |
399 |
|
biglob(hp)->nrd += nrays - hp->bi[i].nrd; |
400 |
|
hp->bi[i].nrd = nrays; |
401 |
< |
hp->dirty++; /* section directory now out of date */ |
401 |
> |
markdirty(hp); /* section directory now out of date */ |
402 |
|
return(1); |
403 |
|
} |
404 |
|
|