|
@@ -10,7 +10,7 @@
|
|
|
#include "fns.h"
|
|
|
|
|
|
Buf*
|
|
|
-bopen(long (*fn)(Buf*, void*, long, long), int omode, int bs, int nblock)
|
|
|
+bopen(long (*fn)(Buf*, void*, long, ulong), int omode, int bs, int nblock)
|
|
|
{
|
|
|
Buf *b;
|
|
|
|
|
@@ -24,15 +24,16 @@ bopen(long (*fn)(Buf*, void*, long, long), int omode, int bs, int nblock)
|
|
|
b->nblock = nblock;
|
|
|
b->bs = bs;
|
|
|
b->omode = omode;
|
|
|
- b->fn = fn;
|
|
|
+ b->fn = fn; /* function to read or write bs-byte blocks */
|
|
|
|
|
|
return b;
|
|
|
}
|
|
|
|
|
|
long
|
|
|
-bread(Buf *b, void *v, long n, long off)
|
|
|
+bread(Buf *b, void *v, long n, vlong off)
|
|
|
{
|
|
|
- long m, noff;
|
|
|
+ long m;
|
|
|
+ vlong noff;
|
|
|
|
|
|
assert(b->omode == OREAD);
|
|
|
|
|
@@ -40,13 +41,16 @@ bread(Buf *b, void *v, long n, long off)
|
|
|
if(b->off > off || off >= b->off+b->ndata) {
|
|
|
noff = off - off % b->bs;
|
|
|
if(vflag)
|
|
|
- fprint(2, "try refill at %ld\n", noff);
|
|
|
- if((m = b->fn(b, b->data, b->nblock, noff/b->bs)) <= 0)
|
|
|
+ fprint(2, "try refill at %lld...", noff);
|
|
|
+ if((m = b->fn(b, b->data, b->nblock, noff/b->bs)) <= 0) {
|
|
|
+ if (vflag)
|
|
|
+ fprint(2, "failed\n");
|
|
|
return m;
|
|
|
+ }
|
|
|
b->ndata = b->bs * m;
|
|
|
b->off = noff;
|
|
|
if(vflag)
|
|
|
- fprint(2, "refill %ld at %ld\n", b->ndata, b->off);
|
|
|
+ fprint(2, "got %ld\n", b->ndata);
|
|
|
}
|
|
|
|
|
|
// fprint(2, "read %ld at %ld\n", n, off);
|
|
@@ -104,7 +108,7 @@ bterm(Buf *b)
|
|
|
{
|
|
|
/* DVD & BD prefer full ecc blocks (tracks), but can cope with less */
|
|
|
if(b->omode == OWRITE && b->ndata)
|
|
|
- b->fn(b, b->data, (b->ndata+b->bs-1)/b->bs, b->off);
|
|
|
+ b->fn(b, b->data, (b->ndata + b->bs - 1)/b->bs, 0);
|
|
|
|
|
|
free(b->data);
|
|
|
free(b);
|