| 52 |
|
short writable; /* 0 read-only, <0 write error encountered */ |
| 53 |
|
int nfrags; /* number of known fragments */ |
| 54 |
|
BEAMI *fi; /* fragments, descending file position */ |
| 55 |
< |
long flen; /* last known file length */ |
| 55 |
> |
off_t flen; /* last known file length */ |
| 56 |
|
} *hdfragl; /* fragment lists, indexed by file descriptor */ |
| 57 |
|
|
| 58 |
|
static int nhdfragls; /* size of hdfragl array */ |
| 129 |
|
} |
| 130 |
|
hdfragl[fd].nlinks++; |
| 131 |
|
hdfragl[fd].writable = wr; /* set writable flag */ |
| 132 |
< |
hdfragl[fd].flen = lseek(fd, (off_t)0L, 2); /* get file length */ |
| 132 |
> |
hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ |
| 133 |
|
} |
| 134 |
|
|
| 135 |
|
|
| 154 |
|
int fd; /* corresponding file descriptor */ |
| 155 |
|
HDGRID *hproto; /* holodeck section grid */ |
| 156 |
|
{ |
| 157 |
< |
long rtrunc; |
| 158 |
< |
long fpos; |
| 157 |
> |
off_t rtrunc; |
| 158 |
> |
off_t fpos; |
| 159 |
|
int writable; |
| 160 |
|
register HOLO *hp; |
| 161 |
|
register int n; |
| 162 |
|
/* prepare for system errors */ |
| 163 |
|
errno = 0; |
| 164 |
< |
if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) |
| 164 |
> |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
| 165 |
|
error(SYSTEM, "cannot determine holodeck file position"); |
| 166 |
|
if (hproto == NULL) { /* assume we're loading it */ |
| 167 |
|
HDGRID hpr; |
| 186 |
|
if (fd < nhdfragls && hdfragl[fd].nlinks) |
| 187 |
|
writable = hdfragl[fd].writable; |
| 188 |
|
else |
| 189 |
< |
writable = lseek(fd, (off_t)fpos, 0) == fpos && |
| 189 |
> |
writable = lseek(fd, fpos, 0) == fpos && |
| 190 |
|
write(fd, (char *)hp, sizeof(HDGRID)) == |
| 191 |
|
sizeof(HDGRID); |
| 192 |
|
} else { /* else assume we're creating it */ |
| 242 |
|
register int j; |
| 243 |
|
|
| 244 |
|
if (!hp->dirty++) { /* write smudge first time */ |
| 245 |
< |
if (lseek(hp->fd, (off_t)(biglob(hp)->fo+(i-1)*sizeof(BEAMI)), 0) < 0 |
| 245 |
> |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 |
| 246 |
|
|| write(hp->fd, (char *)&smudge, |
| 247 |
|
sizeof(BEAMI)) != sizeof(BEAMI)) |
| 248 |
|
error(SYSTEM, "seek/write error in hdmarkdirty"); |
| 305 |
|
return(0); |
| 306 |
|
errno = 0; /* write dirty segments */ |
| 307 |
|
for (j = 0; j < hp->dirty; j++) { |
| 308 |
< |
if (lseek(hp->fd, (off_t)(biglob(hp)->fo + |
| 309 |
< |
(hp->dirseg[j].s-1)*sizeof(BEAMI)), 0) < 0) |
| 308 |
> |
if (lseek(hp->fd, biglob(hp)->fo + |
| 309 |
> |
(hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) |
| 310 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
| 311 |
|
n = hp->dirseg[j].n * sizeof(BEAMI); |
| 312 |
|
if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) |
| 346 |
|
} |
| 347 |
|
|
| 348 |
|
|
| 349 |
< |
long |
| 349 |
> |
off_t |
| 350 |
|
hdfilen(fd) /* return file length for fd */ |
| 351 |
|
int fd; |
| 352 |
|
{ |
| 353 |
< |
long fpos, flen; |
| 353 |
> |
off_t fpos, flen; |
| 354 |
|
|
| 355 |
|
if (fd < 0) |
| 356 |
|
return(-1); |
| 357 |
|
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
| 358 |
< |
if ((fpos = lseek(fd, (off_t)0L, 1)) < 0) |
| 358 |
> |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
| 359 |
|
return(-1); |
| 360 |
< |
flen = lseek(fd, (off_t)0L, 2); |
| 361 |
< |
lseek(fd, (off_t)fpos, 0); |
| 360 |
> |
flen = lseek(fd, (off_t)0, 2); |
| 361 |
> |
lseek(fd, fpos, 0); |
| 362 |
|
return(flen); |
| 363 |
|
} |
| 364 |
|
return(hdfragl[fd].flen); |
| 365 |
|
} |
| 366 |
|
|
| 367 |
|
|
| 368 |
< |
long |
| 368 |
> |
off_t |
| 369 |
|
hdfiluse(fd, all) /* compute file usage (in bytes) */ |
| 370 |
|
int fd; /* open file descriptor to check */ |
| 371 |
|
int all; /* include overhead and unflushed data */ |
| 372 |
|
{ |
| 373 |
< |
long total = 0; |
| 373 |
> |
off_t total = 0; |
| 374 |
|
register int i, j; |
| 375 |
|
|
| 376 |
|
for (j = 0; hdlist[j] != NULL; j++) { |
| 413 |
|
blglob(hp)->nrm += n; |
| 414 |
|
if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { |
| 415 |
|
errno = 0; |
| 416 |
< |
if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) |
| 416 |
> |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
| 417 |
|
error(SYSTEM, "seek error on holodeck file"); |
| 418 |
|
n *= sizeof(RAYVAL); |
| 419 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
| 452 |
|
hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); |
| 453 |
|
blglob(hp)->nrm += hp->bl[i]->nrm = n; |
| 454 |
|
errno = 0; |
| 455 |
< |
if (lseek(hp->fd, (off_t)hp->bi[i].fo, 0) < 0) |
| 455 |
> |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
| 456 |
|
error(SYSTEM, "seek error on holodeck file"); |
| 457 |
|
n *= sizeof(RAYVAL); |
| 458 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
| 469 |
|
hdfilord(hb1, hb2) /* order beams for quick loading */ |
| 470 |
|
register HDBEAMI *hb1, *hb2; |
| 471 |
|
{ |
| 472 |
< |
register long c; |
| 472 |
> |
register off_t c; |
| 473 |
|
/* residents go first */ |
| 474 |
|
if (hb2->h->bl[hb2->b] != NULL) |
| 475 |
|
return(hb1->h->bl[hb1->b] == NULL); |
| 476 |
|
if (hb1->h->bl[hb1->b] != NULL) |
| 477 |
|
return(-1); |
| 478 |
|
/* otherwise sort by file descriptor */ |
| 479 |
< |
if ((c = hb1->h->fd - hb2->h->fd)) |
| 480 |
< |
return(c); |
| 479 |
> |
if (hb1->h->fd != hb2->h->fd) |
| 480 |
> |
return(hb1->h->fd - hb2->h->fd); |
| 481 |
|
/* then by position in file */ |
| 482 |
|
c = hb1->h->bi[hb1->b].fo - hb2->h->bi[hb2->b].fo; |
| 483 |
|
return(c > 0 ? 1 : c < 0 ? -1 : 0); |
| 602 |
|
} |
| 603 |
|
biglob(hp)->nrd -= bi->nrd; /* tell fragment it's free */ |
| 604 |
|
bi->nrd = 0; |
| 605 |
< |
bi->fo = 0L; |
| 605 |
> |
bi->fo = 0; |
| 606 |
|
hdmarkdirty(hp, i); /* assume we'll reallocate */ |
| 607 |
|
return(1); |
| 608 |
|
} |
| 632 |
|
} |
| 633 |
|
|
| 634 |
|
|
| 635 |
< |
long |
| 635 |
> |
off_t |
| 636 |
|
hdallocfrag(fd, nrays) /* allocate a file fragment */ |
| 637 |
|
int fd; |
| 638 |
|
unsigned int4 nrays; |
| 639 |
|
{ |
| 640 |
|
register struct fraglist *f; |
| 641 |
|
register int j; |
| 642 |
< |
long nfo; |
| 642 |
> |
off_t nfo; |
| 643 |
|
|
| 644 |
|
if (nrays == 0) |
| 645 |
|
return(-1L); |
| 669 |
|
int fragfreed; |
| 670 |
|
unsigned int4 nrays; |
| 671 |
|
unsigned int n; |
| 672 |
< |
long nfo; |
| 672 |
> |
off_t nfo; |
| 673 |
|
/* check file status */ |
| 674 |
|
if (hdfragl[hp->fd].writable <= 0) |
| 675 |
|
return(hdfragl[hp->fd].writable); |
| 683 |
|
if (nrays) { /* get and write new fragment */ |
| 684 |
|
nfo = hdallocfrag(hp->fd, nrays); |
| 685 |
|
errno = 0; |
| 686 |
< |
if (lseek(hp->fd, (off_t)nfo, 0) < 0) |
| 686 |
> |
if (lseek(hp->fd, nfo, 0) < 0) |
| 687 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
| 688 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
| 689 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
| 693 |
|
} |
| 694 |
|
hp->bi[i].fo = nfo; |
| 695 |
|
} else |
| 696 |
< |
hp->bi[i].fo = 0L; |
| 696 |
> |
hp->bi[i].fo = 0; |
| 697 |
|
biglob(hp)->nrd += nrays - hp->bi[i].nrd; |
| 698 |
|
hp->bi[i].nrd = nrays; |
| 699 |
|
if (!fragfreed) |
| 781 |
|
if (hp->bi[i].nrd && !(hdfragflags&FF_KILL && hdfreefrag(hp,i))) { |
| 782 |
|
biglob(hp)->nrd -= hp->bi[i].nrd; /* free failed */ |
| 783 |
|
hp->bi[i].nrd = 0; |
| 784 |
< |
hp->bi[i].fo = 0L; |
| 784 |
> |
hp->bi[i].fo = 0; |
| 785 |
|
hdmarkdirty(hp, i); |
| 786 |
|
} |
| 787 |
|
return(nchanged); |