22 |
|
#define PCTFREE 20 /* 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 |
|
|
213 |
|
} |
214 |
|
} |
215 |
|
if (all) |
216 |
< |
for (j = 0; j < nhdfrags; j++) { |
217 |
< |
total += sizeof(struct fragment); |
218 |
< |
if (hdfrag[j].nfrags) |
216 |
> |
for (j = 0; j < nhdfragls; j++) { |
217 |
> |
total += sizeof(struct fraglist); |
218 |
> |
if (hdfragl[j].nfrags) |
219 |
|
total += FRAGBLK*sizeof(BEAMI) * |
220 |
< |
((hdfrag[j].nfrags-1)/FRAGBLK + 1) ; |
220 |
> |
((hdfragl[j].nfrags-1)/FRAGBLK + 1) ; |
221 |
|
} |
222 |
|
return(total); |
223 |
|
} |
231 |
|
|
232 |
|
if (fd < 0) |
233 |
|
return(-1); |
234 |
< |
if (fd >= nhdfrags || !hdfrag[fd].nlinks) { |
234 |
> |
if (fd >= nhdfragls || !hdfragl[fd].nlinks) { |
235 |
|
if ((fpos = lseek(fd, 0L, 1)) < 0) |
236 |
|
return(-1); |
237 |
|
flen = lseek(fd, 0L, 2); |
238 |
|
lseek(fd, fpos, 0); |
239 |
|
return(flen); |
240 |
|
} |
241 |
< |
return(hdfrag[fd].flen); |
241 |
> |
return(hdfragl[fd].flen); |
242 |
|
} |
243 |
|
|
244 |
|
|
410 |
|
long nfo; |
411 |
|
unsigned int n; |
412 |
|
/* check file status */ |
413 |
< |
if (hdfrag[hp->fd].writerr) |
413 |
> |
if (hdfragl[hp->fd].writerr) |
414 |
|
return(-1); |
415 |
|
#ifdef DEBUG |
416 |
|
if (i < 1 | i > nbeams(hp)) |
420 |
|
if (hp->bl[i] == NULL || (nrays = hp->bl[i]->nrm) == hp->bi[i].nrd) |
421 |
|
return(0); |
422 |
|
/* locate fragment */ |
423 |
< |
if (hp->fd >= nhdfrags || !hdfrag[hp->fd].nlinks) /* untracked */ |
423 |
> |
if (hp->fd >= nhdfragls || !hdfragl[hp->fd].nlinks) /* untracked */ |
424 |
|
hp->bi[i].fo = lseek(hp->fd, 0L, 2); |
425 |
|
|
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); |
427 |
> |
hdfragl[hp->fd].flen) /* EOF special case */ |
428 |
> |
hdfragl[hp->fd].flen = (nfo=hp->bi[i].fo) + nrays*sizeof(RAYVAL); |
429 |
|
|
430 |
|
else { /* general case */ |
431 |
< |
register struct fragment *f = &hdfrag[hp->fd]; |
431 |
> |
register struct fraglist *f = &hdfragl[hp->fd]; |
432 |
|
register int j, k; |
433 |
< |
/* relinquish old fragment */ |
433 |
> |
n = f->nfrags; /* relinquish old fragment */ |
434 |
|
if (hp->bi[i].nrd) { |
435 |
|
j = f->nfrags++; |
436 |
|
#if MAXFRAG |
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 |
+ |
n = j-1; |
465 |
|
} |
466 |
|
if (j+1 < f->nfrags && f->fi[j].fo == f->fi[j+1].fo + |
467 |
|
f->fi[j+1].nrd*sizeof(RAYVAL)) { |
468 |
|
f->fi[j+1].nrd += f->fi[j].nrd; |
469 |
|
f->fi[j].nrd = 0; |
470 |
+ |
if (j < n) n = j; |
471 |
|
} |
472 |
|
} |
473 |
|
k = -1; /* find closest-sized fragment */ |
482 |
|
} else { /* else use fragment */ |
483 |
|
nfo = f->fi[k].fo; |
484 |
|
f->fi[k].fo += nrays*sizeof(RAYVAL); |
485 |
< |
f->fi[k].nrd -= nrays; |
485 |
> |
if (!(f->fi[k].nrd -= nrays) && k < n) |
486 |
> |
n = k; |
487 |
|
} |
488 |
|
/* delete empty remnants */ |
489 |
< |
for (j = k = 0; k < f->nfrags; j++, k++) { |
489 |
> |
for (j = k = n; k < f->nfrags; j++, k++) { |
490 |
|
while (f->fi[k].nrd == 0) |
491 |
|
if (++k >= f->nfrags) |
492 |
|
goto endloop; |
502 |
|
error(SYSTEM, "cannot seek on holodeck file"); |
503 |
|
n = hp->bl[i]->nrm * sizeof(RAYVAL); |
504 |
|
if (write(hp->fd, (char *)hdbray(hp->bl[i]), n) != n) { |
505 |
< |
hdfrag[hp->fd].writerr++; |
505 |
> |
hdfragl[hp->fd].writerr++; |
506 |
|
hdsync(hp, 0); /* sync directory */ |
507 |
|
error(SYSTEM, "write error in hdsyncbeam"); |
508 |
|
} |
528 |
|
nchanged += hdfreebeam(hdlist[i], 0); |
529 |
|
return(nchanged); |
530 |
|
} |
531 |
< |
if (hdfrag[hp->fd].writerr) /* check for file error */ |
531 |
> |
if (hdfragl[hp->fd].writerr) /* check for file error */ |
532 |
|
return(0); |
533 |
|
if (i == 0) { /* clear entire holodeck */ |
534 |
|
nchanged = 0; |