(p) = &(vv)->v[(vv)->n++]; \
} while (0)
+typedef uint_least32_t secaddr;
+#define PRIuSEC PRIuLEAST32
+
#define MAXFILES (1 + 2*99 + 1)
struct file {
ident id;
- uint32_t start, end;
+ secaddr start, end;
};
DEFVEC(file_v, struct file);
static file_v filetab = VEC_INIT;
enum { EV_STOP, EV_BEGIN, EV_END, EV_WRITE };
struct event {
unsigned char ev, file;
- uint32_t pos;
+ secaddr pos;
};
DEFVEC(event_v, struct event);
static event_v eventq = VEC_INIT;
return (i);
}
-static void put_event(unsigned evtype, unsigned file, uint32_t pos)
+static void put_event(unsigned evtype, unsigned file, secaddr pos)
{
struct event *ev;
ev->ev = evtype; ev->file = file; ev->pos = pos;
}
-static void put_file(ident id, uint32_t start, uint32_t end)
+static void put_file(ident id, secaddr start, secaddr end)
{
struct file *f;
size_t i;
{
ident id = mkident(VOB, title, 0);
char fn[MAXFNSZ];
- uint32_t start, len;
+ secaddr start, len;
store_filename(fn, id);
start = UDFFindFile(dvd, fn, &len); if (!start) return;
#ifdef DEBUG
- printf(";; %8"PRIu32" .. %-8"PRIu32": %s\n",
+ printf(";; %8"PRIuSEC" .. %-8"PRIuSEC": %s\n",
start, start + SECTORS(len), fn);
#endif
put_file(id, start, start + SECTORS(len));
static void put_title(dvd_reader_t *dvd, unsigned title)
{
char fn[MAXFNSZ];
- uint32_t start[9], len[9];
+ secaddr start[9], len[9];
unsigned i, npart;
for (i = 0; i < 9; i++) {
#ifdef DEBUG
for (i = 0; i < npart; i++) {
store_filename(fn, mkident(VOB, title, i + 1));
- printf(";; %8"PRIu32" .. %-8"PRIu32": %s\n",
+ printf(";; %8"PRIuSEC" .. %-8"PRIuSEC": %s\n",
start[i], start[i] + SECTORS(len[i]), fn);
}
#endif
if (npart > 1)
for (i = 0; i < npart - 1; i++) {
if (len[i]%SECTORSZ)
- bail("title %u part %u length = %"PRIu32" not a multiple of %d",
+ bail("title %u part %u length = %"PRIuSEC" not a multiple of %d",
title, i, len[i], SECTORSZ);
if (start[i] + len[i]/SECTORSZ != start[i + 1])
- bail("title %u part %u end = %"PRIu32" /= part %u start = %"PRIu32"",
- title, i, start[i] + len[i]/SECTORSZ, i + 1, start[i + 1]);
+ bail
+ ("title %u part %u end = %"PRIuSEC" /= part %u start = %"PRIuSEC"",
+ title, i, start[i] + len[i]/SECTORSZ, i + 1, start[i + 1]);
}
put_file(mkident(VOB, title, 1),
unsigned f;
#define SRCF_ALLPROGRESS 1u
- uint32_t last_pos, limit, nsectors, ndone;
+ secaddr last_pos, limit, nsectors, ndone;
struct timeval last_time;
double wsum, wcount;
const char *mapfile; FILE *mapfp;
};
#define SOURCE_INIT { 0, -1, 0, 0, 0, 0, 0, 0, 0, { 0, 0 }, 0.0, 0.0, 0, 0 }
-static void report_progress(struct source *src, uint32_t pos)
+static void report_progress(struct source *src, secaddr pos)
{
char etastr[32];
struct timeval now;
if (src->f&SRCF_ALLPROGRESS) percent = pos*100.0/src->limit;
else percent = src->ndone*100.0/src->nsectors;
- print_progress("copied %.1f%% (%"PRIu32" of %"PRIu32"; %.1f %sB/s, ETA %s)",
- percent, pos, src->limit,
- rate, unit, etastr);
+ print_progress
+ ("copied %.1f%% (%"PRIuSEC" of %"PRIuSEC"; %.1f %sB/s, ETA %s)",
+ percent, pos, src->limit, rate, unit, etastr);
if (src->file && id_kind(src->file->id) == VOB) {
append_progress(" -- %s %d %3.1f%%",
id_part(src->file->id) ? "title" : "menu",
}
static void report_bad_blocks_progress(struct source *src,
- uint32_t lo, uint32_t hi, int err)
+ secaddr lo, secaddr hi, int err)
{
report_progress(src, hi);
if (lo == hi) append_progress(": retrying bad sector");
else
- append_progress(": %"PRIu32" bad %s",
+ append_progress(": %"PRIuSEC" bad %s",
hi - lo, hi == lo + 1 ? "sector" : "sectors");
if (err != EIO) append_progress(" (%s)", strerror(err));
fflush(stdout);
}
-static ssize_t read_sectors(struct source *src, uint32_t pos,
- void *buf, uint32_t want)
+static ssize_t read_sectors(struct source *src, secaddr pos,
+ void *buf, secaddr want)
{
ssize_t n;
n = DVDReadBlocks(src->vob, pos - src->file->start, want, buf);
else if (src->file) {
if (lseek(src->dvdfd, (off_t)pos*SECTORSZ, SEEK_SET) < 0)
- bail_syserr(errno, "failed to seek to sector %"PRIu32"", pos);
+ bail_syserr(errno, "failed to seek to sector %"PRIuSEC"", pos);
n = read(src->dvdfd, buf, want*SECTORSZ);
if (n >= 0) n /= SECTORSZ;
} else {
}
}
-static void emit(struct source *src, int outfd, uint32_t start, uint32_t end)
+static void emit(struct source *src, int outfd, secaddr start, secaddr end)
{
#define BUFSECTORS 512
int least, i;
unsigned char buf[BUFSECTORS*SECTORSZ];
- uint32_t pos;
- uint32_t bad_lo, bad_hi, good, step;
+ secaddr pos;
+ secaddr bad_lo, bad_hi, good, step;
size_t want;
ssize_t n;
static int first_time = 1;
least = least_live();
#ifdef DEBUG
- printf(";; %8"PRIu32" .. %"PRIu32"\n", start, end);
+ printf(";; %8"PRIuSEC" .. %"PRIuSEC"\n", start, end);
for (i = 0; i < filetab.n; i++) {
if (!livep(i)) continue;
if (act == -1) act = i;
f = &filetab.v[i]; store_filename(fn, f->id);
- printf(";;\t\t%8"PRIu32" .. %-8"PRIu32" %s\n",
+ printf(";;\t\t%8"PRIuSEC" .. %-8"PRIuSEC" %s\n",
start - f->start, end - f->start, fn);
}
if (act == -1) printf(";;\t\t#<no live source>\n");
n = read_sectors(src, pos, buf, 1);
if (n > 0) {
clear_progress();
- fprintf(stderr, "%s: sector %"PRIu32" read ok after retry\n",
+ fprintf(stderr, "%s: sector %"PRIuSEC" read ok after retry\n",
prog, pos);
bad_lo = bad_hi = pos;
goto recovered;
recovered:
if (bad_hi > bad_lo) {
clear_progress();
- fprintf(stderr, "%s: skipping %"PRIu32" bad sectors "
- "(%"PRIu32" .. %"PRIu32")\n",
+ fprintf(stderr, "%s: skipping %"PRIuSEC" bad sectors "
+ "(%"PRIuSEC" .. %"PRIuSEC")\n",
prog, bad_hi - bad_lo, bad_lo, bad_hi);
if (src->mapfile) {
if (!src->mapfp) {
optarg);
fprintf(src->mapfp, "## bad sector map\n\n");
}
- fprintf(src->mapfp, "%"PRIu32" %"PRIu32"\n", bad_lo, bad_hi);
+ fprintf(src->mapfp, "%"PRIuSEC" %"PRIuSEC"\n", bad_lo, bad_hi);
fflush(src->mapfp);
if (ferror(src->mapfp))
bail_syserr(errno, "error writing bad-sector map file");
unsigned f = 0;
char *p;
uint64_t volsz;
- uint32_t pos;
+ secaddr pos;
off_t off;
struct source src = SOURCE_INIT;
unsigned long start, end;
for (i = 0; i < filetab.n; i++) {
file = &filetab.v[i];
store_filename(fn, file->id);
- printf(";;\t%8"PRIu32" %s\n", file->start, fn);
+ printf(";;\t%8"PRIuSEC" %s\n", file->start, fn);
}
#endif
switch (ev->ev) {
case EV_WRITE:
if (f&f_write)
- bail("overlapping ranges: range from %lu still open at %"PRIu32"",
+ bail("overlapping ranges: range from %lu still open at %"PRIuSEC"",
start, ev->pos);
n++; f |= f_write; start = ev->pos;
break;
#ifdef DEBUG
store_filename(fn, filetab.v[ev->file].id);
clear_progress();
- printf(";; %8"PRIu32": begin `%s'\n", pos, fn);
+ printf(";; %8"PRIuSEC": begin `%s'\n", pos, fn);
#endif
break;
case EV_WRITE:
lseek(outfd, (off_t)ev->pos*SECTORSZ, SEEK_SET) < 0)
bail_syserr(errno,
"failed to seek to resume position "
- "(sector %"PRIu32") in output file `%s'",
+ "(sector %"PRIuSEC") in output file `%s'",
ev->pos, outfile);
#ifdef DEBUG
clear_progress();
- printf(";; %8"PRIu32": begin write\n", pos);
+ printf(";; %8"PRIuSEC": begin write\n", pos);
#endif
f |= f_write;
break;
f &= ~f_write;
#ifdef DEBUG
clear_progress();
- printf(";; %8"PRIu32": end write\n", pos);
+ printf(";; %8"PRIuSEC": end write\n", pos);
#endif
break;
case EV_END:
#ifdef DEBUG
store_filename(fn, filetab.v[ev->file].id);
clear_progress();
- printf(";; %8"PRIu32": end `%s'\n", pos, fn);
+ printf(";; %8"PRIuSEC": end `%s'\n", pos, fn);
#endif
break;
default: abort();