| 1 |
< |
/* Copyright (c) 1997 Silicon Graphics, Inc. */ |
| 1 |
> |
/* Copyright (c) 1998 Silicon Graphics, Inc. */ |
| 2 |
|
|
| 3 |
|
#ifndef lint |
| 4 |
|
static char SCCSid[] = "$SunId$ SGI"; |
| 16 |
|
#define CACHESIZE 16 /* default cache size (Mbytes, 0==inf) */ |
| 17 |
|
#endif |
| 18 |
|
#ifndef FREEBEAMS |
| 19 |
< |
#define FREEBEAMS 512 /* maximum beams to free at a time */ |
| 19 |
> |
#define FREEBEAMS 1024 /* maximum beams to free at a time */ |
| 20 |
|
#endif |
| 21 |
|
#ifndef PCTFREE |
| 22 |
< |
#define PCTFREE 20 /* maximum fraction to free (%) */ |
| 22 |
> |
#define PCTFREE 15 /* maximum fraction to free (%) */ |
| 23 |
|
#endif |
| 24 |
|
#ifndef MAXFRAG |
| 25 |
< |
#define MAXFRAG 131000 /* maximum fragments/file to track (0==inf) */ |
| 25 |
> |
#define MAXFRAG 32767 /* maximum fragments/file to track (0==inf) */ |
| 26 |
|
#endif |
| 27 |
|
|
| 28 |
|
#ifndef BSD |
| 30 |
|
#define read readbuf |
| 31 |
|
#endif |
| 32 |
|
|
| 33 |
< |
#define FRAGBLK 64 /* number of fragments to allocate at a time */ |
| 33 |
> |
#define FRAGBLK 256 /* number of fragments to allocate at a time */ |
| 34 |
|
|
| 35 |
|
unsigned hdcachesize = CACHESIZE*1024*1024; /* target cache size */ |
| 36 |
|
unsigned long hdclock; /* clock value */ |
| 37 |
|
|
| 38 |
|
HOLO *hdlist[HDMAX+1]; /* holodeck pointers (NULL term.) */ |
| 39 |
|
|
| 40 |
< |
static struct fragment { |
| 40 |
> |
static struct fraglist { |
| 41 |
|
short nlinks; /* number of holodeck sections using us */ |
| 42 |
|
short writerr; /* write error encountered */ |
| 43 |
|
int nfrags; /* number of known fragments */ |
| 44 |
|
BEAMI *fi; /* fragments, descending file position */ |
| 45 |
|
long flen; /* last known file length */ |
| 46 |
< |
} *hdfrag; /* fragment lists, indexed by file descriptor */ |
| 46 |
> |
} *hdfragl; /* fragment lists, indexed by file descriptor */ |
| 47 |
|
|
| 48 |
< |
static int nhdfrags; /* size of hdfrag array */ |
| 48 |
> |
static int nhdfragls; /* size of hdfragl array */ |
| 49 |
|
|
| 50 |
|
|
| 51 |
|
hdattach(fd) /* start tracking file fragments for some section */ |
| 52 |
|
register int fd; |
| 53 |
|
{ |
| 54 |
< |
if (fd >= nhdfrags) { |
| 55 |
< |
if (nhdfrags) |
| 56 |
< |
hdfrag = (struct fragment *)realloc((char *)hdfrag, |
| 57 |
< |
(fd+1)*sizeof(struct fragment)); |
| 54 |
> |
if (fd >= nhdfragls) { |
| 55 |
> |
if (nhdfragls) |
| 56 |
> |
hdfragl = (struct fraglist *)realloc((char *)hdfragl, |
| 57 |
> |
(fd+1)*sizeof(struct fraglist)); |
| 58 |
|
else |
| 59 |
< |
hdfrag = (struct fragment *)malloc( |
| 60 |
< |
(fd+1)*sizeof(struct fragment)); |
| 61 |
< |
if (hdfrag == NULL) |
| 59 |
> |
hdfragl = (struct fraglist *)malloc( |
| 60 |
> |
(fd+1)*sizeof(struct fraglist)); |
| 61 |
> |
if (hdfragl == NULL) |
| 62 |
|
error(SYSTEM, "out of memory in hdattach"); |
| 63 |
< |
bzero((char *)(hdfrag+nhdfrags), |
| 64 |
< |
(fd+1-nhdfrags)*sizeof(struct fragment)); |
| 65 |
< |
nhdfrags = fd+1; |
| 63 |
> |
bzero((char *)(hdfragl+nhdfragls), |
| 64 |
> |
(fd+1-nhdfragls)*sizeof(struct fraglist)); |
| 65 |
> |
nhdfragls = fd+1; |
| 66 |
|
} |
| 67 |
< |
hdfrag[fd].nlinks++; |
| 68 |
< |
hdfrag[fd].flen = lseek(fd, 0L, 2); /* get file length */ |
| 67 |
> |
hdfragl[fd].nlinks++; |
| 68 |
> |
hdfragl[fd].flen = lseek(fd, 0L, 2); /* get file length */ |
| 69 |
|
} |
| 70 |
|
|
| 71 |
|
|
| 75 |
|
hdrelease(fd) /* stop tracking file fragments for some section */ |
| 76 |
|
register int fd; |
| 77 |
|
{ |
| 78 |
< |
if (fd < 0 | fd >= nhdfrags || !hdfrag[fd].nlinks) |
| 78 |
> |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
| 79 |
|
return; |
| 80 |
< |
if (!--hdfrag[fd].nlinks && hdfrag[fd].nfrags) { |
| 81 |
< |
free((char *)hdfrag[fd].fi); |
| 82 |
< |
hdfrag[fd].fi = NULL; |
| 83 |
< |
hdfrag[fd].nfrags = 0; |
| 80 |
> |
if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { |
| 81 |
> |
free((char *)hdfragl[fd].fi); |
| 82 |
> |
hdfragl[fd].fi = NULL; |
| 83 |
> |
hdfragl[fd].nfrags = 0; |
| 84 |
|
} |
| 85 |
|
} |
| 86 |
|
|
| 105 |
|
int fd; /* corresponding file descriptor */ |
| 106 |
|
HDGRID *hproto; /* holodeck section grid */ |
| 107 |
|
{ |
| 108 |
+ |
long rtrunc; |
| 109 |
|
long fpos; |
| 110 |
|
register HOLO *hp; |
| 111 |
|
register int n; |
| 127 |
|
error(SYSTEM, "failure loading holodeck directory"); |
| 128 |
|
/* check that it's clean */ |
| 129 |
|
if (hp->bi[nbeams(hp)].fo < 0) |
| 130 |
< |
error(USER, "dirty holodeck section"); |
| 130 |
> |
error(WARNING, "dirty holodeck section"); |
| 131 |
|
} else { /* assume we're creating it */ |
| 132 |
|
if ((hp = hdalloc(hproto)) == NULL) |
| 133 |
|
goto memerr; |
| 145 |
|
hdattach(fd); |
| 146 |
|
/* check rays on disk */ |
| 147 |
|
fpos = hdfilen(fd); |
| 148 |
< |
biglob(hp)->nrd = 0; |
| 148 |
> |
biglob(hp)->nrd = rtrunc = 0; |
| 149 |
|
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
| 150 |
|
if (hp->bi[n].nrd) |
| 151 |
< |
if (hp->bi[n].fo + hp->bi[n].nrd > fpos) |
| 152 |
< |
hp->bi[n].nrd = 0; /* off end */ |
| 153 |
< |
else |
| 151 |
> |
if (hp->bi[n].fo + hp->bi[n].nrd > fpos) { |
| 152 |
> |
rtrunc += hp->bi[n].nrd; |
| 153 |
> |
hp->bi[n].nrd = 0; |
| 154 |
> |
} else |
| 155 |
|
biglob(hp)->nrd += hp->bi[n].nrd; |
| 156 |
+ |
if (rtrunc) { |
| 157 |
+ |
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
| 158 |
+ |
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
| 159 |
+ |
error(WARNING, errmsg); |
| 160 |
+ |
} |
| 161 |
|
/* add to holodeck list */ |
| 162 |
|
for (n = 0; n < HDMAX; n++) |
| 163 |
|
if (hdlist[n] == NULL) { |
| 220 |
|
} |
| 221 |
|
} |
| 222 |
|
if (all) |
| 223 |
< |
for (j = 0; j < nhdfrags; j++) { |
| 224 |
< |
total += sizeof(struct fragment); |
| 225 |
< |
if (hdfrag[j].nfrags) |
| 223 |
> |
for (j = 0; j < nhdfragls; j++) { |
| 224 |
> |
total += sizeof(struct fraglist); |
| 225 |
> |
if (hdfragl[j].nfrags) |
| 226 |
|
total += FRAGBLK*sizeof(BEAMI) * |
| 227 |
< |
((hdfrag[j].nfrags-1)/FRAGBLK + 1) ; |
| 227 |
> |
((hdfragl[j].nfrags-1)/FRAGBLK + 1) ; |
| 228 |
|
} |
| 229 |
|
return(total); |
| 230 |
|
} |
| 238 |
|
|
| 239 |
|
if (fd < 0) |
| 240 |
|
return(-1); |
| 241 |
< |
if (fd >= nhdfrags || !hdfrag[fd].nlinks) { |
| 241 |
> |
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
| 242 |
|
if ((fpos = lseek(fd, 0L, 1)) < 0) |
| 243 |
|
return(-1); |
| 244 |
|
flen = lseek(fd, 0L, 2); |
| 245 |
|
lseek(fd, fpos, 0); |
| 246 |
|
return(flen); |
| 247 |
|
} |
| 248 |
< |
return(hdfrag[fd].flen); |
| 248 |
> |
return(hdfragl[fd].flen); |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
|
| 355 |
|
|
| 356 |
|
|
| 357 |
|
int |
| 358 |
< |
hdfilord(hb1, hb2) /* order beams for optimal loading */ |
| 358 |
> |
hdfilord(hb1, hb2) /* order beams for quick loading */ |
| 359 |
|
register HDBEAMI *hb1, *hb2; |
| 360 |
|
{ |
| 361 |
< |
register int c; |
| 362 |
< |
/* sort by file descriptor first */ |
| 361 |
> |
register long c; |
| 362 |
> |
/* residents go first */ |
| 363 |
> |
if (hb2->h->bl[hb2->b] != NULL) |
| 364 |
> |
return(hb1->h->bl[hb1->b] == NULL); |
| 365 |
> |
if (hb1->h->bl[hb1->b] != NULL) |
| 366 |
> |
return(-1); |
| 367 |
> |
/* otherwise sort by file descriptor */ |
| 368 |
|
if ((c = hb1->h->fd - hb2->h->fd)) |
| 369 |
|
return(c); |
| 370 |
|
/* then by position in file */ |
| 371 |
< |
return(hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo); |
| 371 |
> |
c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo; |
| 372 |
> |
return(c > 0 ? 1 : c < 0 ? -1 : 0); |
| 373 |
|
} |
| 374 |
|
|
| 375 |
|
|
| 388 |
|
error(CONSISTENCY, "bad beam in hdloadbeams"); |
| 389 |
|
/* sort list for optimal access */ |
| 390 |
|
qsort((char *)hb, n, sizeof(HDBEAMI), hdfilord); |
| 391 |
< |
bytesloaded = needbytes = 0; /* figure out memory needs */ |
| 391 |
> |
bytesloaded = 0; /* run through loaded beams */ |
| 392 |
> |
for ( ; n && (bp = hb->h->bl[hb->b]) != NULL; n--, hb++) { |
| 393 |
> |
bp->tick = hdclock; /* preempt swap */ |
| 394 |
> |
bytesloaded += bp->nrm; |
| 395 |
> |
if (bf != NULL) |
| 396 |
> |
(*bf)(bp, hb->h, hb->b); |
| 397 |
> |
} |
| 398 |
> |
bytesloaded *= sizeof(RAYVAL); |
| 399 |
|
if ((origcachesize = hdcachesize) > 0) { |
| 400 |
+ |
needbytes = 0; /* figure out memory needs */ |
| 401 |
|
for (i = n; i--; ) |
| 402 |
< |
if ((bp = hb[i].h->bl[hb[i].b]) != NULL) { |
| 382 |
< |
bp->tick = hdclock; /* preempt swap */ |
| 383 |
< |
bytesloaded += bp->nrm; |
| 384 |
< |
} else /* prepare to load */ |
| 385 |
< |
needbytes += hb[i].h->bi[hb[i].b].nrd; |
| 386 |
< |
bytesloaded *= sizeof(RAYVAL); |
| 402 |
> |
needbytes += hb[i].h->bi[hb[i].b].nrd; |
| 403 |
|
needbytes *= sizeof(RAYVAL); |
| 404 |
|
do { /* free enough memory */ |
| 405 |
|
memuse = hdmemuse(0); |
| 406 |
< |
bytes2free = needbytes - (signed)(hdcachesize-memuse); |
| 407 |
< |
if (bytes2free > (signed)(memuse - bytesloaded)) |
| 406 |
> |
bytes2free = needbytes - (int)(hdcachesize-memuse); |
| 407 |
> |
if (bytes2free > (int)(memuse - bytesloaded)) |
| 408 |
|
bytes2free = memuse - bytesloaded; |
| 409 |
|
} while (bytes2free > 0 && |
| 410 |
|
hdfreecache(100*bytes2free/memuse, NULL) < 0); |
| 411 |
+ |
hdcachesize = 0; /* load beams w/o swap */ |
| 412 |
|
} |
| 396 |
– |
hdcachesize = 0; /* load the ordered beams w/o swap */ |
| 413 |
|
for (i = 0; i < n; i++) |
| 414 |
|
if ((bp = hdgetbeam(hb[i].h, hb[i].b)) != NULL && bf != NULL) |
| 415 |
|
(*bf)(bp, hb[i].h, hb[i].b); |
| 417 |
|
} |
| 418 |
|
|
| 419 |
|
|
| 420 |
+ |
hdfreefrag(fd, bi) /* free a file fragment */ |
| 421 |
+ |
int fd; |
| 422 |
+ |
register BEAMI *bi; |
| 423 |
+ |
{ |
| 424 |
+ |
register struct fraglist *f; |
| 425 |
+ |
register int j, k; |
| 426 |
+ |
|
| 427 |
+ |
if (bi->nrd == 0) |
| 428 |
+ |
return; |
| 429 |
+ |
#ifdef DEBUG |
| 430 |
+ |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
| 431 |
+ |
error(CONSISTENCY, "bad file descriptor in hdfreefrag"); |
| 432 |
+ |
#endif |
| 433 |
+ |
f = &hdfragl[fd]; |
| 434 |
+ |
if (f->nfrags % FRAGBLK == 0) { /* delete empty remnants */ |
| 435 |
+ |
for (j = k = 0; k < f->nfrags; j++, k++) { |
| 436 |
+ |
while (f->fi[k].nrd == 0) |
| 437 |
+ |
if (++k >= f->nfrags) |
| 438 |
+ |
goto endloop; |
| 439 |
+ |
if (k > j) |
| 440 |
+ |
copystruct(f->fi+j, f->fi+k); |
| 441 |
+ |
} |
| 442 |
+ |
endloop: |
| 443 |
+ |
f->nfrags = j; |
| 444 |
+ |
} |
| 445 |
+ |
j = f->nfrags++; /* allocate a slot in free list */ |
| 446 |
+ |
#if MAXFRAG |
| 447 |
+ |
if (j >= MAXFRAG-1) |
| 448 |
+ |
f->nfrags--; |
| 449 |
+ |
#endif |
| 450 |
+ |
if (j % FRAGBLK == 0) { /* more free list space */ |
| 451 |
+ |
if (f->fi == NULL) |
| 452 |
+ |
f->fi = (BEAMI *)malloc(FRAGBLK*sizeof(BEAMI)); |
| 453 |
+ |
else |
| 454 |
+ |
f->fi = (BEAMI *)realloc((char *)f->fi, |
| 455 |
+ |
(j+FRAGBLK)*sizeof(BEAMI)); |
| 456 |
+ |
if (f->fi == NULL) |
| 457 |
+ |
error(SYSTEM, "out of memory in hdfreefrag"); |
| 458 |
+ |
} |
| 459 |
+ |
for ( ; ; j--) { /* insert in descending list */ |
| 460 |
+ |
if (!j || bi->fo < f->fi[j-1].fo) { |
| 461 |
+ |
f->fi[j].fo = bi->fo; |
| 462 |
+ |
f->fi[j].nrd = bi->nrd; |
| 463 |
+ |
break; |
| 464 |
+ |
} |
| 465 |
+ |
copystruct(f->fi+j, f->fi+(j-1)); |
| 466 |
+ |
} |
| 467 |
+ |
/* coalesce adjacent fragments */ |
| 468 |
+ |
/* successors never empty */ |
| 469 |
+ |
if (j && f->fi[j-1].fo == f->fi[j].fo + f->fi[j].nrd*sizeof(RAYVAL)) { |
| 470 |
+ |
f->fi[j].nrd += f->fi[j-1].nrd; |
| 471 |
+ |
f->fi[j-1].nrd = 0; |
| 472 |
+ |
} |
| 473 |
+ |
for (k = j+1; k < f->nfrags; k++) /* get non-empty predecessor */ |
| 474 |
+ |
if (f->fi[k].nrd) { |
| 475 |
+ |
if (f->fi[j].fo == f->fi[k].fo + |
| 476 |
+ |
f->fi[k].nrd*sizeof(RAYVAL)) { |
| 477 |
+ |
f->fi[k].nrd += f->fi[j].nrd; |
| 478 |
+ |
f->fi[j].nrd = 0; |
| 479 |
+ |
} |
| 480 |
+ |
break; |
| 481 |
+ |
} |
| 482 |
+ |
} |
| 483 |
+ |
|
| 484 |
+ |
|
| 485 |
+ |
long |
| 486 |
+ |
hdallocfrag(fd, nrays) /* allocate a file fragment */ |
| 487 |
+ |
int fd; |
| 488 |
+ |
unsigned int4 nrays; |
| 489 |
+ |
{ |
| 490 |
+ |
register struct fraglist *f; |
| 491 |
+ |
register int j, k; |
| 492 |
+ |
long nfo; |
| 493 |
+ |
|
| 494 |
+ |
if (nrays == 0) |
| 495 |
+ |
return(-1L); |
| 496 |
+ |
#ifdef DEBUG |
| 497 |
+ |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
| 498 |
+ |
error(CONSISTENCY, "bad file descriptor in hdallocfrag"); |
| 499 |
+ |
#endif |
| 500 |
+ |
f = &hdfragl[fd]; |
| 501 |
+ |
k = -1; /* find closest-sized fragment */ |
| 502 |
+ |
for (j = f->nfrags; j-- > 0; ) |
| 503 |
+ |
if (f->fi[j].nrd >= nrays && |
| 504 |
+ |
(k < 0 || f->fi[j].nrd < f->fi[k].nrd)) |
| 505 |
+ |
if (f->fi[k=j].nrd == nrays) |
| 506 |
+ |
break; |
| 507 |
+ |
if (k < 0) { /* no fragment -- extend file */ |
| 508 |
+ |
nfo = f->flen; |
| 509 |
+ |
f->flen += nrays*sizeof(RAYVAL); |
| 510 |
+ |
} else { /* else use fragment */ |
| 511 |
+ |
nfo = f->fi[k].fo; |
| 512 |
+ |
f->fi[k].fo += nrays*sizeof(RAYVAL); |
| 513 |
+ |
f->fi[k].nrd -= nrays; |
| 514 |
+ |
} |
| 515 |
+ |
return(nfo); |
| 516 |
+ |
} |
| 517 |
+ |
|
| 518 |
+ |
|
| 519 |
|
int |
| 520 |
|
hdsyncbeam(hp, i) /* sync beam in memory with beam on disk */ |
| 521 |
|
register HOLO *hp; |
| 522 |
|
register int i; |
| 523 |
|
{ |
| 524 |
< |
unsigned int nrays; |
| 410 |
< |
long nfo; |
| 524 |
> |
unsigned int4 nrays; |
| 525 |
|
unsigned int n; |
| 526 |
+ |
long nfo; |
| 527 |
|
/* check file status */ |
| 528 |
< |
if (hdfrag[hp->fd].writerr) |
| 528 |
> |
if (hdfragl[hp->fd].writerr) |
| 529 |
|
return(-1); |
| 530 |
|
#ifdef DEBUG |
| 531 |
|
if (i < 1 | i > nbeams(hp)) |
| 534 |
|
/* is current fragment OK? */ |
| 535 |
|
if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd) |
| 536 |
|
return(0); |
| 537 |
< |
/* locate fragment */ |
| 538 |
< |
if (hp->fd >= nhdfrags || !hdfrag[hp->fd].nlinks) /* untracked */ |
| 539 |
< |
hp->bi[i].fo = lseek(hp->fd, 0L, 2); |
| 540 |
< |
|
| 426 |
< |
else if (hp->bi[i].fo + hp->bi[i].nrd*sizeof(RAYVAL) == |
| 427 |
< |
hdfrag[hp->fd].flen) /* EOF special case */ |
| 428 |
< |
hdfrag[hp->fd].flen = (nfo=hp->bi[i].fo) + nrays*sizeof(RAYVAL); |
| 429 |
< |
|
| 430 |
< |
else { /* general case */ |
| 431 |
< |
register struct fragment *f = &hdfrag[hp->fd]; |
| 432 |
< |
register int j, k; |
| 433 |
< |
/* relinquish old fragment */ |
| 434 |
< |
if (hp->bi[i].nrd) { |
| 435 |
< |
j = f->nfrags++; |
| 436 |
< |
#if MAXFRAG |
| 437 |
< |
if (j >= MAXFRAG-1) |
| 438 |
< |
f->nfrags--; |
| 439 |
< |
#endif |
| 440 |
< |
if (j % FRAGBLK == 0) { /* more frag. space */ |
| 441 |
< |
if (f->fi == NULL) |
| 442 |
< |
f->fi = (BEAMI *)malloc( |
| 443 |
< |
FRAGBLK*sizeof(BEAMI)); |
| 444 |
< |
else |
| 445 |
< |
f->fi = (BEAMI *)realloc((char *)f->fi, |
| 446 |
< |
(j+FRAGBLK)*sizeof(BEAMI)); |
| 447 |
< |
if (f->fi == NULL) |
| 448 |
< |
error(SYSTEM, |
| 449 |
< |
"out of memory in hdsyncbeam"); |
| 450 |
< |
} |
| 451 |
< |
for ( ; ; j--) { /* insert in descending list */ |
| 452 |
< |
if (!j || hp->bi[i].fo < f->fi[j-1].fo) { |
| 453 |
< |
f->fi[j].fo = hp->bi[i].fo; |
| 454 |
< |
f->fi[j].nrd = hp->bi[i].nrd; |
| 455 |
< |
break; |
| 456 |
< |
} |
| 457 |
< |
copystruct(f->fi+j, f->fi+(j-1)); |
| 458 |
< |
} |
| 459 |
< |
/* coalesce adjacent fragments */ |
| 460 |
< |
if (j && f->fi[j-1].fo == f->fi[j].fo + |
| 461 |
< |
f->fi[j].nrd*sizeof(RAYVAL)) { |
| 462 |
< |
f->fi[j].nrd += f->fi[j-1].nrd; |
| 463 |
< |
f->fi[j-1].nrd = 0; |
| 464 |
< |
} |
| 465 |
< |
if (j+1 < f->nfrags && f->fi[j].fo == f->fi[j+1].fo + |
| 466 |
< |
f->fi[j+1].nrd*sizeof(RAYVAL)) { |
| 467 |
< |
f->fi[j+1].nrd += f->fi[j].nrd; |
| 468 |
< |
f->fi[j].nrd = 0; |
| 469 |
< |
} |
| 470 |
< |
} |
| 471 |
< |
k = -1; /* find closest-sized fragment */ |
| 472 |
< |
for (j = (nrays ? f->nfrags : 0); j-- > 0; ) |
| 473 |
< |
if (f->fi[j].nrd >= nrays && |
| 474 |
< |
(k < 0 || f->fi[j].nrd < f->fi[k].nrd)) |
| 475 |
< |
if (f->fi[k=j].nrd == nrays) |
| 476 |
< |
break; |
| 477 |
< |
if (k < 0) { /* no fragment -- extend file */ |
| 478 |
< |
nfo = f->flen; |
| 479 |
< |
f->flen += nrays*sizeof(RAYVAL); |
| 480 |
< |
} else { /* else use fragment */ |
| 481 |
< |
nfo = f->fi[k].fo; |
| 482 |
< |
f->fi[k].fo += nrays*sizeof(RAYVAL); |
| 483 |
< |
f->fi[k].nrd -= nrays; |
| 484 |
< |
} |
| 485 |
< |
/* delete empty remnants */ |
| 486 |
< |
for (j = k = 0; k < f->nfrags; j++, k++) { |
| 487 |
< |
while (f->fi[k].nrd == 0) |
| 488 |
< |
if (++k >= f->nfrags) |
| 489 |
< |
goto endloop; |
| 490 |
< |
if (k > j) |
| 491 |
< |
copystruct(f->fi+j, f->fi+k); |
| 492 |
< |
} |
| 493 |
< |
endloop: |
| 494 |
< |
f->nfrags = j; |
| 495 |
< |
} |
| 496 |
< |
if (nrays) { /* write the new fragment */ |
| 537 |
> |
if (hp->bi[i].nrd) /* relinquish old fragment */ |
| 538 |
> |
hdfreefrag(hp->fd, &hp->bi[i]); |
| 539 |
> |
if (nrays) { /* get and write new fragment */ |
| 540 |
> |
nfo = hdallocfrag(hp->fd, nrays); |
| 541 |
|
errno = 0; |
| 542 |
|
if (lseek(hp->fd, nfo, 0) < 0) |
| 543 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
| 544 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
| 545 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
| 546 |
< |
hdfrag[hp->fd].writerr++; |
| 547 |
< |
hdsync(hp, 0); /* sync directory */ |
| 546 |
> |
hdfragl[hp->fd].writerr++; |
| 547 |
> |
hdsync(NULL, 0); /* sync directories */ |
| 548 |
|
error(SYSTEM, "write error in hdsyncbeam"); |
| 549 |
|
} |
| 550 |
< |
} |
| 550 |
> |
hp->bi[i].fo = nfo; |
| 551 |
> |
} else |
| 552 |
> |
hp->bi[i].fo = 0L; |
| 553 |
|
biglob(hp)->nrd += nrays - hp->bi[i].nrd; |
| 554 |
|
hp->bi[i].nrd = nrays; |
| 555 |
< |
hp->bi[i].fo = nfo; |
| 510 |
< |
markdirty(hp); /* section directory now out of date */ |
| 555 |
> |
markdirty(hp); /* section directory now out of date */ |
| 556 |
|
return(1); |
| 557 |
|
} |
| 558 |
|
|
| 570 |
|
nchanged += hdfreebeam(hdlist[i], 0); |
| 571 |
|
return(nchanged); |
| 572 |
|
} |
| 573 |
< |
if (hdfrag[hp->fd].writerr) /* check for file error */ |
| 573 |
> |
if (hdfragl[hp->fd].writerr) /* check for file error */ |
| 574 |
|
return(0); |
| 575 |
|
if (i == 0) { /* clear entire holodeck */ |
| 576 |
|
nchanged = 0; |
| 648 |
|
{ |
| 649 |
|
register int i, j; |
| 650 |
|
/* insert each beam from hp */ |
| 651 |
< |
for (i = nbeams(hp); i > 0; i--) { |
| 651 |
> |
for (i = 1; i <= nbeams(hp); i++) { |
| 652 |
|
if (hp->bl[i] == NULL) /* check if loaded */ |
| 653 |
|
continue; |
| 654 |
|
#if 0 |