dvd-sector-copy.c: Show overall progress if we're simply continuing.
authorMark Wooding <mdw@distorted.org.uk>
Tue, 15 Feb 2022 10:07:54 +0000 (10:07 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Tue, 15 Feb 2022 10:07:54 +0000 (10:07 +0000)
If we're supposed to write a single region extending to the end of the
disc then show the percentage completion in terms of the absolute
position in the disc rather than as a percentage of the number of
sectors we're supposed to copy.  This makes the percentage shown easier
to relate to that displayed by a previous interrupted operation.

dvd-sector-copy.c

index 9c1c7d8..1782ee4 100644 (file)
@@ -282,19 +282,21 @@ struct source {
   struct file *file;
   dvd_file_t *vob;
 
   struct file *file;
   dvd_file_t *vob;
 
+  unsigned f;
+#define SRCF_ALLPROGRESS 1u
   uint32_t last_pos, limit, nsectors, ndone;
   struct timeval last_time;
   double wsum, wcount;
   const char *mapfile; FILE *mapfp;
 };
   uint32_t 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 }
+#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)
 {
   char etastr[32];
   struct timeval now;
   int eta;
 
 static void report_progress(struct source *src, uint32_t pos)
 {
   char etastr[32];
   struct timeval now;
   int eta;
-  double t, f, g, rate;
+  double percent, t, f, g, rate;
   char *unit;
 
 #define ALPHA 0.02
   char *unit;
 
 #define ALPHA 0.02
@@ -325,8 +327,10 @@ static void report_progress(struct source *src, uint32_t pos)
   if (rate > 128) { rate /= 1024; unit = "M"; }
   if (rate > 128) { rate /= 1024; unit = "G"; }
 
   if (rate > 128) { rate /= 1024; unit = "M"; }
   if (rate > 128) { rate /= 1024; unit = "G"; }
 
+  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)",
   print_progress("copied %.1f%% (%"PRIu32" of %"PRIu32"; %.1f %sB/s, ETA %s)",
-                src->ndone*100.0/src->nsectors, pos, src->limit,
+                percent, pos, src->limit,
                 rate, unit, etastr);
   if (src->file && id_kind(src->file->id) == VOB) {
     append_progress(" -- %s %d %3.1f%%",
                 rate, unit, etastr);
   if (src->file && id_kind(src->file->id) == VOB) {
     append_progress(" -- %s %d %3.1f%%",
@@ -594,6 +598,7 @@ int main(int argc, char *argv[])
   const struct event *ev;
   const char *device = "/dev/dvd", *outfile = 0;
   int opt, err, outfd = -1, blksz;
   const struct event *ev;
   const char *device = "/dev/dvd", *outfile = 0;
   int opt, err, outfd = -1, blksz;
+  unsigned n;
   size_t i;
   FILE *fp;
   struct buf buf = BUF_INIT;
   size_t i;
   FILE *fp;
   struct buf buf = BUF_INIT;
@@ -745,7 +750,7 @@ int main(int argc, char *argv[])
 
   qsort(eventq.v, eventq.n, sizeof(struct event), compare_event);
 
 
   qsort(eventq.v, eventq.n, sizeof(struct event), compare_event);
 
-  f &= ~f_write; start = 0;
+  f &= ~f_write; start = 0; n = 0;
   for (i = 0; i < eventq.n; i++) {
     ev = &eventq.v[i];
     switch (ev->ev) {
   for (i = 0; i < eventq.n; i++) {
     ev = &eventq.v[i];
     switch (ev->ev) {
@@ -753,7 +758,7 @@ int main(int argc, char *argv[])
        if (f&f_write)
          bail("overlapping ranges: range from %lu still open at %"PRIu32"",
               start, ev->pos);
        if (f&f_write)
          bail("overlapping ranges: range from %lu still open at %"PRIu32"",
               start, ev->pos);
-       f |= f_write; start = ev->pos;
+       n++; f |= f_write; start = ev->pos;
        break;
       case EV_STOP:
        f &= ~f_write;
        break;
       case EV_STOP:
        f &= ~f_write;
@@ -774,12 +779,14 @@ int main(int argc, char *argv[])
   eventq.n = i;
   if (f&f_fixup) {
     put_event(EV_WRITE, 0, start);
   eventq.n = i;
   if (f&f_fixup) {
     put_event(EV_WRITE, 0, start);
-    f |= f_write;
+    n++; f |= f_write;
   }
   if (f&f_write) {
     src.nsectors += src.limit - start;
     put_event(EV_STOP, 0, src.limit);
   }
   }
   if (f&f_write) {
     src.nsectors += src.limit - start;
     put_event(EV_STOP, 0, src.limit);
   }
+  if (n == 1 && (f&f_write))
+    src.f |= SRCF_ALLPROGRESS;
   f &= ~f_write;
 
 #ifdef DEBUG
   f &= ~f_write;
 
 #ifdef DEBUG