13 |
|
|
14 |
|
#include "holo.h" |
15 |
|
|
16 |
+ |
#include "platform.h" |
17 |
+ |
|
18 |
|
#ifndef CACHESIZE |
19 |
|
#ifdef SMLMEM |
20 |
|
#define CACHESIZE 5 |
135 |
|
} |
136 |
|
hdfragl[fd].nlinks++; |
137 |
|
hdfragl[fd].writable = wr; /* set writable flag */ |
138 |
< |
hdfragl[fd].flen = lseek(fd, (off_t)0, 2); /* get file length */ |
138 |
> |
/* get file length */ |
139 |
> |
hdfragl[fd].flen = lseek(fd, (off_t)0, SEEK_END); |
140 |
|
} |
141 |
|
|
142 |
|
|
146 |
|
hdrelease(fd) /* stop tracking file fragments for some section */ |
147 |
|
register int fd; |
148 |
|
{ |
149 |
< |
if (fd < 0 | fd >= nhdfragls || !hdfragl[fd].nlinks) |
149 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !hdfragl[fd].nlinks) |
150 |
|
return; |
151 |
|
if (!--hdfragl[fd].nlinks && hdfragl[fd].nfrags) { |
152 |
|
free((void *)hdfragl[fd].fi); |
168 |
|
register int n; |
169 |
|
/* prepare for system errors */ |
170 |
|
errno = 0; |
171 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
171 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
172 |
|
error(SYSTEM, "cannot determine holodeck file position"); |
173 |
|
if (hproto == NULL) { /* assume we're loading it */ |
174 |
|
HDGRID hpr; |
193 |
|
if (fd < nhdfragls && hdfragl[fd].nlinks) |
194 |
|
writable = hdfragl[fd].writable; |
195 |
|
else |
196 |
< |
writable = lseek(fd, fpos, 0) == fpos && |
196 |
> |
writable = lseek(fd, fpos, SEEK_SET) == fpos && |
197 |
|
write(fd, (char *)hp, sizeof(HDGRID)) == |
198 |
|
sizeof(HDGRID); |
199 |
|
} else { /* else assume we're creating it */ |
216 |
|
fpos = hdfilen(fd); |
217 |
|
biglob(hp)->nrd = rtrunc = 0; |
218 |
|
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
219 |
< |
if (hp->bi[n].nrd) |
219 |
> |
if (hp->bi[n].nrd) { |
220 |
|
if (hp->bi[n].fo+hp->bi[n].nrd*sizeof(RAYVAL) > fpos) { |
221 |
|
rtrunc += hp->bi[n].nrd; |
222 |
|
hp->bi[n].nrd = 0; |
223 |
|
} else |
224 |
|
biglob(hp)->nrd += hp->bi[n].nrd; |
225 |
+ |
} |
226 |
|
if (rtrunc) { |
227 |
|
sprintf(errmsg, "truncated section, %ld rays lost (%.1f%%)", |
228 |
|
rtrunc, 100.*rtrunc/(rtrunc+biglob(hp)->nrd)); |
250 |
|
register int j; |
251 |
|
|
252 |
|
if (!hp->dirty++) { /* write smudge first time */ |
253 |
< |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), 0) < 0 |
254 |
< |
|| write(hp->fd, (char *)&smudge, |
253 |
> |
if (lseek(hp->fd, biglob(hp)->fo+(i-1)*sizeof(BEAMI), |
254 |
> |
SEEK_SET) < 0 || |
255 |
> |
write(hp->fd, (char *)&smudge, |
256 |
|
sizeof(BEAMI)) != sizeof(BEAMI)) |
257 |
|
error(SYSTEM, "seek/write error in hdmarkdirty"); |
258 |
|
hp->dirseg[0].s = i; |
315 |
|
errno = 0; /* write dirty segments */ |
316 |
|
for (j = 0; j < hp->dirty; j++) { |
317 |
|
if (lseek(hp->fd, biglob(hp)->fo + |
318 |
< |
(hp->dirseg[j].s-1)*sizeof(BEAMI), 0) < 0) |
318 |
> |
(hp->dirseg[j].s-1)*sizeof(BEAMI), SEEK_SET) < 0) |
319 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
320 |
|
n = hp->dirseg[j].n * sizeof(BEAMI); |
321 |
|
if (write(hp->fd, (char *)(hp->bi+hp->dirseg[j].s), n) != n) |
364 |
|
if (fd < 0) |
365 |
|
return(-1); |
366 |
|
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
367 |
< |
if ((fpos = lseek(fd, (off_t)0, 1)) < 0) |
367 |
> |
if ((fpos = lseek(fd, (off_t)0, SEEK_CUR)) < 0) |
368 |
|
return(-1); |
369 |
< |
flen = lseek(fd, (off_t)0, 2); |
370 |
< |
lseek(fd, fpos, 0); |
369 |
> |
flen = lseek(fd, (off_t)0, SEEK_END); |
370 |
> |
lseek(fd, fpos, SEEK_SET); |
371 |
|
return(flen); |
372 |
|
} |
373 |
|
return(hdfragl[fd].flen); |
410 |
|
int n; |
411 |
|
|
412 |
|
if (nr <= 0) return(NULL); |
413 |
< |
CHECK(i < 1 | i > nbeams(hp), |
413 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
414 |
|
CONSISTENCY, "bad beam index given to hdnewrays"); |
415 |
|
if (hp->bl[i] != NULL) |
416 |
|
hp->bl[i]->tick = hdclock; /* preempt swap */ |
422 |
|
blglob(hp)->nrm += n; |
423 |
|
if ((n = hp->bl[i]->nrm = hp->bi[i].nrd)) { |
424 |
|
errno = 0; |
425 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
425 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
426 |
|
error(SYSTEM, "seek error on holodeck file"); |
427 |
|
n *= sizeof(RAYVAL); |
428 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
451 |
|
{ |
452 |
|
register int n; |
453 |
|
|
454 |
< |
CHECK(i < 1 | i > nbeams(hp), |
454 |
> |
CHECK((i < 1) | (i > nbeams(hp)), |
455 |
|
CONSISTENCY, "bad beam index given to hdgetbeam"); |
456 |
|
if (hp->bl[i] == NULL) { /* load from disk */ |
457 |
|
if (!(n = hp->bi[i].nrd)) |
461 |
|
hp->bl[i] = (BEAM *)hdrealloc(NULL, hdbsiz(n), "hdgetbeam"); |
462 |
|
blglob(hp)->nrm += hp->bl[i]->nrm = n; |
463 |
|
errno = 0; |
464 |
< |
if (lseek(hp->fd, hp->bi[i].fo, 0) < 0) |
464 |
> |
if (lseek(hp->fd, hp->bi[i].fo, SEEK_SET) < 0) |
465 |
|
error(SYSTEM, "seek error on holodeck file"); |
466 |
|
n *= sizeof(RAYVAL); |
467 |
|
if (read(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) |
505 |
|
/* precheck consistency */ |
506 |
|
if (n <= 0) return; |
507 |
|
for (i = n; i--; ) |
508 |
< |
if (hb[i].h==NULL || hb[i].b<1 | hb[i].b>nbeams(hb[i].h)) |
508 |
> |
if (hb[i].h==NULL || (hb[i].b<1) | (hb[i].b>nbeams(hb[i].h))) |
509 |
|
error(CONSISTENCY, "bad beam in hdloadbeams"); |
510 |
|
/* sort list for optimal access */ |
511 |
|
qsort((void *)hb, n, sizeof(HDBEAMI), hdfilord); |
626 |
|
register struct fraglist *f; |
627 |
|
register int i; |
628 |
|
|
629 |
< |
if (fd < 0 | fd >= nhdfragls || !(f = &hdfragl[fd])->nlinks) |
629 |
> |
if ((fd < 0) | (fd >= nhdfragls) || !(f = &hdfragl[fd])->nlinks) |
630 |
|
return(0); /* listless */ |
631 |
|
if (listlen != NULL) |
632 |
|
*listlen = f->nfrags; |
692 |
|
if (nrays) { /* get and write new fragment */ |
693 |
|
nfo = hdallocfrag(hp->fd, nrays); |
694 |
|
errno = 0; |
695 |
< |
if (lseek(hp->fd, nfo, 0) < 0) |
695 |
> |
if (lseek(hp->fd, nfo, SEEK_SET) < 0) |
696 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
697 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
698 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
766 |
|
return(nchanged); |
767 |
|
} |
768 |
|
if (i == 0) { /* clobber entire holodeck */ |
769 |
< |
if (biglob(hp)->nrd == 0 & blglob(hp)->nrm == 0) |
769 |
> |
if ((biglob(hp)->nrd == 0) & (blglob(hp)->nrm == 0)) |
770 |
|
return(0); /* already empty */ |
771 |
|
nchanged = 0; |
772 |
|
nchanged = 0; |