| 38 |
|
|
| 39 |
|
static struct fragment { |
| 40 |
|
short nlinks; /* number of holodeck sections using us */ |
| 41 |
< |
short nfrags; /* number of known fragments */ |
| 41 |
> |
short writerr; /* write error encountered */ |
| 42 |
> |
int nfrags; /* number of known fragments */ |
| 43 |
|
BEAMI *fi; /* fragments, descending file position */ |
| 44 |
|
long flen; /* last known file length */ |
| 45 |
|
} *hdfrag; /* fragment lists, indexed by file descriptor */ |
| 139 |
|
hp->fd = fd; |
| 140 |
|
hp->dirty = 0; |
| 141 |
|
biglob(hp)->fo = fpos + sizeof(HDGRID); |
| 142 |
< |
biglob(hp)->nrd = 0; /* count rays on disk */ |
| 143 |
< |
for (n = nbeams(hp); n > 0; n--) |
| 144 |
< |
biglob(hp)->nrd += hp->bi[n].nrd; |
| 142 |
> |
/* start tracking fragments */ |
| 143 |
> |
hdattach(fd); |
| 144 |
> |
/* check rays on disk */ |
| 145 |
> |
fpos = hdfilen(fd); |
| 146 |
> |
biglob(hp)->nrd = 0; |
| 147 |
> |
for (n = hproto == NULL ? nbeams(hp) : 0; n > 0; n--) |
| 148 |
> |
if (hp->bi[n].nrd) |
| 149 |
> |
if (hp->bi[n].fo + hp->bi[n].nrd > fpos) |
| 150 |
> |
hp->bi[n].nrd = 0; /* off end */ |
| 151 |
> |
else |
| 152 |
> |
biglob(hp)->nrd += hp->bi[n].nrd; |
| 153 |
|
/* add to holodeck list */ |
| 154 |
|
for (n = 0; n < HDMAX; n++) |
| 155 |
|
if (hdlist[n] == NULL) { |
| 156 |
|
hdlist[n] = hp; |
| 157 |
|
break; |
| 158 |
|
} |
| 150 |
– |
/* start tracking fragments (last) */ |
| 151 |
– |
hdattach(fd); |
| 159 |
|
/* all done */ |
| 160 |
|
return(hp); |
| 161 |
|
memerr: |
| 180 |
|
for (j = all ? nbeams(hp) : 0; j > 0; j--) |
| 181 |
|
if (hp->bl[j] != NULL) |
| 182 |
|
hdsyncbeam(hp, j); |
| 183 |
< |
if (!hp->dirty) /* directory dirty? */ |
| 183 |
> |
if (!hp->dirty) /* directory clean? */ |
| 184 |
|
return(0); |
| 185 |
|
errno = 0; |
| 186 |
|
if (lseek(hp->fd, biglob(hp)->fo, 0) < 0) |
| 354 |
|
unsigned int nrays; |
| 355 |
|
long nfo; |
| 356 |
|
unsigned int n; |
| 357 |
+ |
/* check file status */ |
| 358 |
+ |
if (hdfrag[hp->fd].writerr) |
| 359 |
+ |
return(-1); |
| 360 |
|
#ifdef DEBUG |
| 361 |
|
if (i < 1 | i > nbeams(hp)) |
| 362 |
|
error(CONSISTENCY, "bad beam index in hdsyncbeam"); |
| 364 |
|
/* is current fragment OK? */ |
| 365 |
|
if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd) |
| 366 |
|
return(0); |
| 367 |
< |
/* check file status */ |
| 358 |
< |
if (hp->dirty < 0) |
| 359 |
< |
return(-1); |
| 360 |
< |
|
| 367 |
> |
/* locate fragment */ |
| 368 |
|
if (hp->fd >= nhdfrags || !hdfrag[hp->fd].nlinks) /* untracked */ |
| 369 |
|
hp->bi[i].fo = lseek(hp->fd, 0L, 2); |
| 370 |
|
|
| 442 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
| 443 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
| 444 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
| 445 |
< |
hp->dirty = -1; /* avoid recursive error */ |
| 445 |
> |
hdfrag[hp->fd].writerr++; |
| 446 |
> |
hdsync(hp, 0); /* sync directory */ |
| 447 |
|
error(SYSTEM, "write error in hdsyncbeam"); |
| 448 |
|
} |
| 449 |
|
} |
| 468 |
|
nchanged += hdfreebeam(hdlist[i], 0); |
| 469 |
|
return(nchanged); |
| 470 |
|
} |
| 471 |
+ |
if (hdfrag[hp->fd].writerr) /* check for file error */ |
| 472 |
+ |
return(0); |
| 473 |
|
if (i == 0) { /* clear entire holodeck */ |
| 474 |
|
nchanged = 0; |
| 475 |
|
for (i = nbeams(hp); i > 0; i--) |