lib.h: Add missing documentation of FILE argument to `device_size'.
[dvdrip] / dvd-sector-copy.c
index 4c19389..f1f6d4e 100644 (file)
@@ -8,30 +8,6 @@ static void usage(FILE *fp)
          prog);
 }
 
-static double tvdiff(const struct timeval *tv_lo,
-                    const struct timeval *tv_hi)
-{
-  return ((tv_hi->tv_sec - tv_lo->tv_sec) +
-         (tv_hi->tv_usec - tv_lo->tv_usec)/1.0e6);
-}
-
-#define DEFVEC(vtype, etype)                                           \
-       typedef struct { etype *v; size_t n, sz; } vtype
-#define VEC_INIT { 0, 0, 0 }
-#define VEC_FREE(vv) do {                                              \
-  free((vv)->v); (vv)->v 0; (vv)->n = (vv)->sz = 0;                    \
-} while (0)
-#define VEC_PUSH(p, vv) do {                                           \
-  size_t _want;                                                                \
-  if ((vv)->n >= (vv)->sz) {                                           \
-    (vv)->sz = (vv)->sz ? 2*(vv)->sz : 32;                             \
-    _want = (vv)->sz*sizeof(*(vv)->v);                                 \
-    (vv)->v = realloc((vv)->v, _want);                                 \
-    if (!(vv)->v) bail("out of memory allocating %zu bytes", _want);   \
-  }                                                                    \
-  (p) = &(vv)->v[(vv)->n++];                                           \
-} while (0)
-
 #define MAXFILES (1 + 2*99 + 1)
 struct file {
   ident id;
@@ -347,7 +323,10 @@ static ssize_t read_sectors(secaddr pos, void *buf, secaddr want)
 #endif
       if (pos < bad->start) { D( printf("high\n"); ) best = bad; hi = mid; }
       else if (pos >= bad->end) { D( printf("low\n"); ) lo = mid + 1; }
-      else { D( printf("match!\n"); ) errno = EIO; return (-1); }
+      else {
+       D( printf("match!\n"); )
+       errno = EIO; sit(bad_block_delay); return (-1);
+      }
     }
 #ifdef DEBUG
     if (best)
@@ -730,16 +709,16 @@ static ssize_t find_good_sector(secaddr *pos_inout, secaddr end,
     if (n == want) good = pos;
     else bad_hi = pos + n + 1;
   }
-  recovered(bad_lo, bad_hi); *pos_inout = good;
-  if (good < r.pos + r.start || r.pos + r.end <= good)
+  recovered(bad_lo, bad_hi); *pos_inout = bad_hi;
+  if (bad_hi < r.pos + r.start || r.pos + r.end <= bad_hi)
     n = 0;
   else {
-    n = r.pos + r.end - good;
-    rearrange_sectors(&r, 0, good - r.pos, n);
+    n = r.pos + r.end - bad_hi;
+    rearrange_sectors(&r, 0, bad_hi - r.pos, n);
   }
 #ifdef DEBUG
   show_recovery_buffer_map(&r, "returning %zd good sectors at %"PRIuSEC"",
-                          n, good);
+                          n, bad_hi);
 #endif
   return (n);
 }
@@ -1099,7 +1078,7 @@ int main(int argc, char *argv[])
 #endif
   }
 
-  open_dvd(device, &dvdfd, &dvd);
+  open_dvd(device, O_RDONLY, &dvdfd, &dvd);
 
   blksz = SECTORSZ; volsz = device_size(dvdfd, device, &blksz);
   if (blksz != SECTORSZ)
@@ -1109,7 +1088,7 @@ int main(int argc, char *argv[])
         device, volsz, SECTORSZ);
 
   if (f&f_checkid) {
-    open_dvd(outfile, 0, &dvd_out);
+    open_dvd(outfile, O_RDONLY, 0, &dvd_out);
     if (dvd_id(id_in, dvd, DIF_MUSTIFOHASH, device) ||
        dvd_id(id_out, dvd_out, DIF_MUSTIFOHASH, device))
       exit(2);