11 |
|
|
12 |
|
#include <string.h> |
13 |
|
|
14 |
+ |
#include "platform.h" |
15 |
+ |
#include "rtprocess.h" |
16 |
+ |
|
17 |
|
#include "holo.h" |
18 |
|
|
19 |
|
#ifndef CACHESIZE |
64 |
|
|
65 |
|
static int nhdfragls; /* size of hdfragl array */ |
66 |
|
|
67 |
+ |
static HOLO *hdalloc(HDGRID *hproto); |
68 |
+ |
static char *hdrealloc(char *ptr, unsigned siz, char *rout); |
69 |
+ |
static void hdattach(int fd, int wr); |
70 |
+ |
static void hdrelease(int fd); |
71 |
+ |
static void hdmarkdirty(HOLO *hp, int i); |
72 |
+ |
static unsigned int hdmemuse(int all); |
73 |
+ |
static int hdfilord(const void *hb1, const void *hb2); |
74 |
+ |
static off_t hdallocfrag(int fd, uint32 nrays); |
75 |
+ |
static int hdsyncbeam(HOLO *hp, int i); |
76 |
+ |
static int hdlrulist(HDBEAMI *hb, int nents, int n, HOLO *hp); |
77 |
+ |
static int hdfreecache(int pct, HOLO *honly); |
78 |
|
|
79 |
+ |
|
80 |
+ |
|
81 |
|
HOLO * |
82 |
< |
hdalloc(hproto) /* allocate and set holodeck section based on grid */ |
83 |
< |
HDGRID *hproto; |
82 |
> |
hdalloc( /* allocate and set holodeck section based on grid */ |
83 |
> |
HDGRID *hproto |
84 |
> |
) |
85 |
|
{ |
86 |
|
HOLO hdhead; |
87 |
|
register HOLO *hp; |
95 |
|
if ((hp = (HOLO *)malloc(n)) == NULL) |
96 |
|
return(NULL); |
97 |
|
/* copy header information */ |
98 |
< |
copystruct(hp, &hdhead); |
98 |
> |
*hp = hdhead; |
99 |
|
/* allocate and clear beam list */ |
100 |
|
hp->bl = (BEAM **)malloc((nbeams(hp)+1)*sizeof(BEAM *)+sizeof(BEAM)); |
101 |
|
if (hp->bl == NULL) { |
114 |
|
|
115 |
|
|
116 |
|
char * |
117 |
< |
hdrealloc(ptr, siz, rout) /* (re)allocate memory, retry then error */ |
118 |
< |
char *ptr; |
119 |
< |
unsigned siz; |
120 |
< |
char *rout; |
117 |
> |
hdrealloc( /* (re)allocate memory, retry then error */ |
118 |
> |
char *ptr, |
119 |
> |
unsigned siz, |
120 |
> |
char *rout |
121 |
> |
) |
122 |
|
{ |
123 |
|
register char *newp; |
124 |
|
/* call malloc/realloc */ |
138 |
|
} |
139 |
|
|
140 |
|
|
141 |
< |
hdattach(fd, wr) /* start tracking file fragments for some section */ |
142 |
< |
register int fd; |
143 |
< |
int wr; |
141 |
> |
void |
142 |
> |
hdattach( /* start tracking file fragments for some section */ |
143 |
> |
register int fd, |
144 |
> |
int wr |
145 |
> |
) |
146 |
|
{ |
147 |
|
if (fd >= nhdfragls) { |
148 |
|
hdfragl = (struct fraglist *)hdrealloc((char *)hdfragl, |
153 |
|
} |
154 |
|
hdfragl[fd].nlinks++; |
155 |
|
hdfragl[fd].writable = wr; /* set writable flag */ |
156 |
< |
hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ |
156 |
> |
/* get file length */ |
157 |
> |
hdfragl[fd].flen = lseek(fd, (off_t)0, SEEK_END); |
158 |
|
} |
159 |
|
|
160 |
|
|
161 |
|
/* Do we need a routine to locate file fragments given known occupants? */ |
162 |
|
|
163 |
|
|
164 |
< |
hdrelease(fd) /* stop tracking file fragments for some section */ |
165 |
< |
register int fd; |
164 |
> |
void |
165 |
> |
hdrelease( /* stop tracking file fragments for some section */ |
166 |
> |
register int fd |
167 |
> |
) |
168 |
|
{ |
169 |
< |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
169 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) |
170 |
|
return; |
171 |
|
if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { |
172 |
|
free((void *)hdfragl[fd].fi); |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
< |
HOLO * |
180 |
< |
hdinit(fd, hproto) /* initialize a holodeck section in a file */ |
181 |
< |
int fd; /* corresponding file descriptor */ |
182 |
< |
HDGRID *hproto; /* holodeck section grid */ |
179 |
> |
extern HOLO * |
180 |
> |
hdinit( /* initialize a holodeck section in a file */ |
181 |
> |
int fd, /* corresponding file descriptor */ |
182 |
> |
HDGRID *hproto /* holodeck section grid */ |
183 |
> |
) |
184 |
|
{ |
185 |
|
off_t rtrunc; |
186 |
|
off_t fpos; |
189 |
|
register int n; |
190 |
|
/* prepare for system errors */ |
191 |
|
errno = 0; |
192 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
192 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
193 |
|
error(SYSTEM, "cannot determine holodeck file position"); |
194 |
|
if (hproto == NULL) { /* assume we're loading it */ |
195 |
|
HDGRID hpr; |
214 |
|
if (fd < nhdfragls && hdfragl[fd].nlinks) |
215 |
|
writable = hdfragl[fd].writable; |
216 |
|
else |
217 |
< |
writable = lseek(fd, fpos, 0) == fpos && |
217 |
> |
writable = lseek(fd, fpos, SEEK_SET) == fpos && |
218 |
|
write(fd, (char *)hp, sizeof(HDGRID)) == |
219 |
|
sizeof(HDGRID); |
220 |
|
} else { /* else assume we're creating it */ |
237 |
|
fpos = hdfilen(fd); |
238 |
|
biglob(hp)->nrd = rtrunc = 0; |
239 |
|
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
240 |
< |
if (hp->bi[n].nrd) |
240 |
> |
if (hp->bi[n].nrd) { |
241 |
|
if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) { |
242 |
|
rtrunc += hp->bi[n].nrd; |
243 |
|
hp->bi[n].nrd = 0; |
244 |
|
} else |
245 |
|
biglob(hp)->nrd += hp->bi[n].nrd; |
246 |
+ |
} |
247 |
|
if (rtrunc) { |
248 |
|
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
249 |
|
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
259 |
|
return(hp); |
260 |
|
memerr: |
261 |
|
error(SYSTEM, "cannot allocate holodeck grid"); |
262 |
+ |
return NULL; /* pro forma return */ |
263 |
|
} |
264 |
|
|
265 |
|
|
266 |
< |
hdmarkdirty(hp, i) /* mark holodeck directory position dirty */ |
267 |
< |
register HOLO *hp; |
268 |
< |
int i; |
266 |
> |
void |
267 |
> |
hdmarkdirty( /* mark holodeck directory position dirty */ |
268 |
> |
register HOLO *hp, |
269 |
> |
int i |
270 |
> |
) |
271 |
|
{ |
272 |
|
static BEAMI smudge = {0, -1}; |
273 |
|
int mindist, minpos; |
274 |
|
register int j; |
275 |
|
|
276 |
|
if (!hp->dirty++) { /* write smudge first time */ |
277 |
< |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 |
278 |
< |
|| write(hp->fd, (char *)&smudge, |
277 |
> |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), |
278 |
> |
SEEK_SET) < 0 || |
279 |
> |
write(hp->fd, (char *)&smudge, |
280 |
|
sizeof(BEAMI)) != sizeof(BEAMI)) |
281 |
|
error(SYSTEM, "seek/write error in hdmarkdirty"); |
282 |
|
hp->dirseg[0].s = i; |
290 |
|
hp->dirseg[j].n = 1; |
291 |
|
break; |
292 |
|
} |
293 |
< |
copystruct(hp->dirseg+j, hp->dirseg+(j-1)); |
293 |
> |
*(hp->dirseg+j) = *(hp->dirseg+(j-1)); |
294 |
|
} |
295 |
|
do { /* check neighbors */ |
296 |
|
mindist = nbeams(hp); /* find closest */ |
312 |
|
hp->dirseg[minpos].n - hp->dirseg[j].s; |
313 |
|
hp->dirty--; |
314 |
|
while (++j < hp->dirty) /* close the gap */ |
315 |
< |
copystruct(hp->dirseg+j, hp->dirseg+(j+1)); |
315 |
> |
*(hp->dirseg+j) = *(hp->dirseg+(j+1)); |
316 |
|
} while (mindist <= MINDIRSEL); |
317 |
|
} |
318 |
|
|
319 |
|
|
320 |
< |
int |
321 |
< |
hdsync(hp, all) /* update beams and directory on disk */ |
322 |
< |
register HOLO *hp; |
323 |
< |
int all; |
320 |
> |
extern int |
321 |
> |
hdsync( /* update beams and directory on disk */ |
322 |
> |
register HOLO *hp, |
323 |
> |
int all |
324 |
> |
) |
325 |
|
{ |
326 |
|
register int j, n; |
327 |
|
|
340 |
|
errno = 0; /* write dirty segments */ |
341 |
|
for (j = 0; j < hp->dirty; j++) { |
342 |
|
if (lseek(hp->fd, biglob(hp)->fo + |
343 |
< |
(hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) |
343 |
> |
(hp->dirseg[j].s-1)*sizeof(BEAMI), SEEK_SET) < 0) |
344 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
345 |
|
n = hp->dirseg[j].n * sizeof(BEAMI); |
346 |
|
if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) |
351 |
|
} |
352 |
|
|
353 |
|
|
354 |
< |
unsigned |
355 |
< |
hdmemuse(all) /* return memory usage (in bytes) */ |
356 |
< |
int all; /* include overhead (painful) */ |
354 |
> |
unsigned int |
355 |
> |
hdmemuse( /* return memory usage (in bytes) */ |
356 |
> |
int all /* include overhead (painful) */ |
357 |
> |
) |
358 |
|
{ |
359 |
|
long total = 0; |
360 |
|
register int i, j; |
381 |
|
} |
382 |
|
|
383 |
|
|
384 |
< |
off_t |
385 |
< |
hdfilen(fd) /* return file length for fd */ |
386 |
< |
int fd; |
384 |
> |
extern off_t |
385 |
> |
hdfilen( /* return file length for fd */ |
386 |
> |
int fd |
387 |
> |
) |
388 |
|
{ |
389 |
|
off_t fpos, flen; |
390 |
|
|
391 |
|
if (fd < 0) |
392 |
|
return(-1); |
393 |
|
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
394 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
394 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
395 |
|
return(-1); |
396 |
< |
flen = lseek(fd, (off_t)0, 2); |
397 |
< |
lseek(fd, fpos, 0); |
396 |
> |
flen = lseek(fd, (off_t)0, SEEK_END); |
397 |
> |
lseek(fd, fpos, SEEK_SET); |
398 |
|
return(flen); |
399 |
|
} |
400 |
|
return(hdfragl[fd].flen); |
401 |
|
} |
402 |
|
|
403 |
|
|
404 |
< |
off_t |
405 |
< |
hdfiluse(fd, all) /* compute file usage (in bytes) */ |
406 |
< |
int fd; /* open file descriptor to check */ |
407 |
< |
int all; /* include overhead and unflushed data */ |
404 |
> |
extern off_t |
405 |
> |
hdfiluse( /* compute file usage (in bytes) */ |
406 |
> |
int fd /* open file descriptor to check */ |
407 |
> |
) |
408 |
|
{ |
409 |
|
off_t total = 0; |
410 |
|
register int i, j; |
413 |
|
if (hdlist[j]->fd != fd) |
414 |
|
continue; |
415 |
|
total += biglob(hdlist[j])->nrd * sizeof(RAYVAL); |
416 |
< |
if (all) { |
417 |
< |
for (i = nbeams(hdlist[j]); i > 0; i--) |
418 |
< |
if (hdlist[j]->bl[i] != NULL) |
419 |
< |
total += sizeof(RAYVAL) * |
416 |
> |
i = nbeams(hdlist[j]); |
417 |
> |
total += i*sizeof(BEAMI) + sizeof(HDGRID); |
418 |
> |
for ( ; i > 0; i--) |
419 |
> |
if (hdlist[j]->bl[i] != NULL) |
420 |
> |
total += sizeof(RAYVAL) * |
421 |
|
(hdlist[j]->bl[i]->nrm - |
422 |
|
hdlist[j]->bi[i].nrd); |
390 |
– |
total += sizeof(HDGRID) + |
391 |
– |
nbeams(hdlist[j])*sizeof(BEAMI); |
392 |
– |
} |
423 |
|
} |
424 |
|
return(total); /* does not include fragments */ |
425 |
|
} |
426 |
|
|
427 |
|
|
428 |
< |
RAYVAL * |
429 |
< |
hdnewrays(hp, i, nr) /* allocate space for add'l rays and return pointer */ |
430 |
< |
register HOLO *hp; |
431 |
< |
register int i; |
432 |
< |
int nr; /* number of new rays desired */ |
428 |
> |
extern RAYVAL * |
429 |
> |
hdnewrays( /* allocate space for add'l rays and return pointer */ |
430 |
> |
register HOLO *hp, |
431 |
> |
register int i, |
432 |
> |
int nr /* number of new rays desired */ |
433 |
> |
) |
434 |
|
{ |
435 |
|
RAYVAL *p; |
436 |
|
int n; |
437 |
|
|
438 |
|
if (nr <= 0) return(NULL); |
439 |
< |
CHECK(i < 1 | i > nbeams(hp), |
439 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
440 |
|
CONSISTENCY, "bad beam index given to hdnewrays"); |
441 |
|
if (hp->bl[i] != NULL) |
442 |
|
hp->bl[i]->tick = hdclock; /* preempt swap */ |
448 |
|
blglob(hp)->nrm += n; |
449 |
|
if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { |
450 |
|
errno = 0; |
451 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
451 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
452 |
|
error(SYSTEM, "seek error on holodeck file"); |
453 |
|
n *= sizeof(RAYVAL); |
454 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
470 |
|
} |
471 |
|
|
472 |
|
|
473 |
< |
BEAM * |
474 |
< |
hdgetbeam(hp, i) /* get beam (from file if necessary) */ |
475 |
< |
register HOLO *hp; |
476 |
< |
register int i; |
473 |
> |
extern BEAM * |
474 |
> |
hdgetbeam( /* get beam (from file if necessary) */ |
475 |
> |
register HOLO *hp, |
476 |
> |
register int i |
477 |
> |
) |
478 |
|
{ |
479 |
|
register int n; |
480 |
|
|
481 |
< |
CHECK(i < 1 | i > nbeams(hp), |
481 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
482 |
|
CONSISTENCY, "bad beam index given to hdgetbeam"); |
483 |
|
if (hp->bl[i] == NULL) { /* load from disk */ |
484 |
|
if (!(n = hp->bi[i].nrd)) |
488 |
|
hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); |
489 |
|
blglob(hp)->nrm += hp->bl[i]->nrm = n; |
490 |
|
errno = 0; |
491 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
491 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
492 |
|
error(SYSTEM, "seek error on holodeck file"); |
493 |
|
n *= sizeof(RAYVAL); |
494 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
502 |
|
|
503 |
|
|
504 |
|
int |
505 |
< |
hdfilord(hb1, hb2) /* order beams for quick loading */ |
506 |
< |
register HDBEAMI *hb1, *hb2; |
505 |
> |
hdfilord( /* order beams for quick loading */ |
506 |
> |
register const void *hb1, |
507 |
> |
register const void *hb2 |
508 |
> |
) |
509 |
|
{ |
510 |
|
register off_t c; |
511 |
|
/* residents go first */ |
512 |
< |
if (hb2->h->bl[hb2->b] != NULL) |
513 |
< |
return(hb1->h->bl[hb1->b] == NULL); |
514 |
< |
if (hb1->h->bl[hb1->b] != NULL) |
512 |
> |
if (((HDBEAMI*)hb2)->h->bl[((HDBEAMI*)hb2)->b] != NULL) |
513 |
> |
return(((HDBEAMI*)hb1)->h->bl[((HDBEAMI*)hb1)->b] == NULL); |
514 |
> |
if (((HDBEAMI*)hb1)->h->bl[((HDBEAMI*)hb1)->b] != NULL) |
515 |
|
return(-1); |
516 |
|
/* otherwise sort by file descriptor */ |
517 |
< |
if (hb1->h->fd != hb2->h->fd) |
518 |
< |
return(hb1->h->fd - hb2->h->fd); |
517 |
> |
if (((HDBEAMI*)hb1)->h->fd != ((HDBEAMI*)hb2)->h->fd) |
518 |
> |
return(((HDBEAMI*)hb1)->h->fd - ((HDBEAMI*)hb2)->h->fd); |
519 |
|
/* then by position in file */ |
520 |
< |
c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo; |
520 |
> |
c = ((HDBEAMI*)hb1)->h->bi[((HDBEAMI*)hb1)->b].fo |
521 |
> |
- ((HDBEAMI*)hb2)->h->bi[((HDBEAMI*)hb2)->b].fo; |
522 |
|
return(c > 0 ? 1 : c < 0 ? -1 : 0); |
523 |
|
} |
524 |
|
|
525 |
|
|
526 |
< |
hdloadbeams(hb, n, bf) /* load a list of beams in optimal order */ |
527 |
< |
register HDBEAMI *hb; /* list gets sorted by hdfilord() */ |
528 |
< |
int n; /* list length */ |
529 |
< |
int (*bf)(); /* callback function (optional) */ |
526 |
> |
extern void |
527 |
> |
hdloadbeams( /* load a list of beams in optimal order */ |
528 |
> |
register HDBEAMI *hb, /* list gets sorted by hdfilord() */ |
529 |
> |
int n, /* list length */ |
530 |
> |
void (*bf)(BEAM *bp, HDBEAMI *hb) /* callback function (optional) */ |
531 |
> |
) |
532 |
|
{ |
533 |
|
unsigned origcachesize, memuse; |
534 |
|
int bytesloaded, needbytes, bytes2free; |
537 |
|
/* precheck consistency */ |
538 |
|
if (n <= 0) return; |
539 |
|
for (i = n; i--; ) |
540 |
< |
if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) |
540 |
> |
if (hb[i].h==NULL || (hb[i].b<1) | (hb[i].b>nbeams(hb[i].h))) |
541 |
|
error(CONSISTENCY, "bad beam in hdloadbeams"); |
542 |
|
/* sort list for optimal access */ |
543 |
|
qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord); |
570 |
|
} |
571 |
|
|
572 |
|
|
573 |
< |
int |
574 |
< |
hdfreefrag(hp, i) /* free a file fragment */ |
575 |
< |
HOLO *hp; |
576 |
< |
int i; |
573 |
> |
extern int |
574 |
> |
hdfreefrag( /* free a file fragment */ |
575 |
> |
HOLO *hp, |
576 |
> |
int i |
577 |
> |
) |
578 |
|
{ |
579 |
|
register BEAMI *bi = &hp->bi[i]; |
580 |
|
register struct fraglist *f; |
593 |
|
if (++k >= f->nfrags) |
594 |
|
goto endloop; |
595 |
|
if (k > j) |
596 |
< |
copystruct(f->fi+j, f->fi+k); |
596 |
> |
*(f->fi+j) = *(f->fi+k); |
597 |
|
} |
598 |
|
endloop: |
599 |
|
f->nfrags = j; |
625 |
|
f->fi[j].nrd = bi->nrd; |
626 |
|
break; |
627 |
|
} |
628 |
< |
copystruct(f->fi+j, f->fi+(j-1)); |
628 |
> |
*(f->fi+j) = *(f->fi+(j-1)); |
629 |
|
} |
630 |
|
/* coalesce adjacent fragments */ |
631 |
|
/* successors never empty */ |
650 |
|
} |
651 |
|
|
652 |
|
|
653 |
< |
int |
654 |
< |
hdfragOK(fd, listlen, listsiz) /* get fragment list status for file */ |
655 |
< |
int fd; |
656 |
< |
int *listlen; |
657 |
< |
register int32 *listsiz; |
653 |
> |
extern int |
654 |
> |
hdfragOK( /* get fragment list status for file */ |
655 |
> |
int fd, |
656 |
> |
int *listlen, |
657 |
> |
register int32 *listsiz |
658 |
> |
) |
659 |
|
{ |
660 |
|
register struct fraglist *f; |
661 |
|
register int i; |
662 |
|
|
663 |
< |
if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks) |
663 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) |
664 |
|
return(0); /* listless */ |
665 |
|
if (listlen != NULL) |
666 |
|
*listlen = f->nfrags; |
676 |
|
|
677 |
|
|
678 |
|
off_t |
679 |
< |
hdallocfrag(fd, nrays) /* allocate a file fragment */ |
680 |
< |
int fd; |
681 |
< |
uint32 nrays; |
679 |
> |
hdallocfrag( /* allocate a file fragment */ |
680 |
> |
int fd, |
681 |
> |
uint32 nrays |
682 |
> |
) |
683 |
|
{ |
684 |
|
register struct fraglist *f; |
685 |
|
register int j; |
706 |
|
|
707 |
|
|
708 |
|
int |
709 |
< |
hdsyncbeam(hp, i) /* sync beam in memory with beam on disk */ |
710 |
< |
register HOLO *hp; |
711 |
< |
register int i; |
709 |
> |
hdsyncbeam( /* sync beam in memory with beam on disk */ |
710 |
> |
register HOLO *hp, |
711 |
> |
register int i |
712 |
> |
) |
713 |
|
{ |
714 |
|
int fragfreed; |
715 |
|
uint32 nrays; |
728 |
|
if (nrays) { /* get and write new fragment */ |
729 |
|
nfo = hdallocfrag(hp->fd, nrays); |
730 |
|
errno = 0; |
731 |
< |
if (lseek(hp->fd, nfo, 0) < 0) |
731 |
> |
if (lseek(hp->fd, nfo, SEEK_SET) < 0) |
732 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
733 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
734 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
747 |
|
} |
748 |
|
|
749 |
|
|
750 |
< |
int |
751 |
< |
hdfreebeam(hp, i) /* free beam, writing if dirty */ |
752 |
< |
register HOLO *hp; |
753 |
< |
register int i; |
750 |
> |
extern int |
751 |
> |
hdfreebeam( /* free beam, writing if dirty */ |
752 |
> |
register HOLO *hp, |
753 |
> |
register int i |
754 |
> |
) |
755 |
|
{ |
756 |
|
int nchanged; |
757 |
|
|
789 |
|
} |
790 |
|
|
791 |
|
|
792 |
< |
int |
793 |
< |
hdkillbeam(hp, i) /* delete beam from holodeck */ |
794 |
< |
register HOLO *hp; |
795 |
< |
register int i; |
792 |
> |
extern int |
793 |
> |
hdkillbeam( /* delete beam from holodeck */ |
794 |
> |
register HOLO *hp, |
795 |
> |
register int i |
796 |
> |
) |
797 |
|
{ |
798 |
|
int nchanged; |
799 |
|
|
804 |
|
return(nchanged); |
805 |
|
} |
806 |
|
if (i == 0) { /* clobber entire holodeck */ |
807 |
< |
if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0) |
807 |
> |
if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0)) |
808 |
|
return(0); /* already empty */ |
809 |
|
nchanged = 0; |
810 |
|
nchanged = 0; |
836 |
|
|
837 |
|
|
838 |
|
int |
839 |
< |
hdlrulist(hb, nents, n, hp) /* add beams from holodeck to LRU list */ |
840 |
< |
register HDBEAMI *hb; /* beam list */ |
841 |
< |
int nents; /* current list length */ |
842 |
< |
int n; /* maximum list length */ |
843 |
< |
register HOLO *hp; /* section we're adding from */ |
839 |
> |
hdlrulist( /* add beams from holodeck to LRU list */ |
840 |
> |
register HDBEAMI *hb, /* beam list */ |
841 |
> |
int nents, /* current list length */ |
842 |
> |
int n, /* maximum list length */ |
843 |
> |
register HOLO *hp /* section we're adding from */ |
844 |
> |
) |
845 |
|
{ |
846 |
|
register int i, j; |
847 |
|
/* insert each beam from hp */ |
861 |
|
hb[j].b = i; |
862 |
|
break; |
863 |
|
} |
864 |
< |
copystruct(hb+j, hb+(j-1)); |
864 |
> |
*(hb+j) = *(hb+(j-1)); |
865 |
|
} |
866 |
|
} |
867 |
|
return(nents); /* return new list length */ |
869 |
|
|
870 |
|
|
871 |
|
int |
872 |
< |
hdfreecache(pct, honly) /* free up cache space, writing changes */ |
873 |
< |
int pct; /* maximum percentage to free */ |
874 |
< |
register HOLO *honly; /* NULL means check all */ |
872 |
> |
hdfreecache( /* free up cache space, writing changes */ |
873 |
> |
int pct, /* maximum percentage to free */ |
874 |
> |
register HOLO *honly /* NULL means check all */ |
875 |
> |
) |
876 |
|
{ |
877 |
|
HDBEAMI hb[FREEBEAMS]; |
878 |
|
int freetarget; |
913 |
|
} |
914 |
|
|
915 |
|
|
916 |
< |
hddone(hp) /* clean up holodeck section and free */ |
917 |
< |
register HOLO *hp; /* NULL means clean up all */ |
916 |
> |
extern void |
917 |
> |
hddone( /* clean up holodeck section and free */ |
918 |
> |
register HOLO *hp /* NULL means clean up all */ |
919 |
> |
) |
920 |
|
{ |
921 |
|
register int i; |
922 |
|
|