dvd-sector-copy.c: Add option to verify source id.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 6 Mar 2022 20:34:50 +0000 (20:34 +0000)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 6 Mar 2022 20:34:50 +0000 (20:34 +0000)
dvd-sector-copy.c

index ea34461..2017689 100644 (file)
@@ -3,7 +3,7 @@
 static void usage(FILE *fp)
 {
   fprintf(fp,
-         "usage: %s [-c] [-B PARAM=VALUE,...] [-R MAP]\n"
+         "usage: %s [-ci] [-B PARAM=VALUE,...] [-R MAP]\n"
          "\t[-b OUTMAP] [-r [START]-[END]] DEVICE OUTFILE\n",
          prog);
 }
@@ -955,7 +955,8 @@ int main(int argc, char *argv[])
   struct timeval tv0, tv1;
   double t, rate, tot;
   const char *rateunit, *totunit;
-  char timebuf[TIMESTRMAX];
+  char timebuf[TIMESTRMAX], id_in[MAXIDSZ], id_out[MAXIDSZ];
+  dvd_reader_t *dvd_out;
   struct stat st;
 #ifdef DEBUG
   const struct file *file;
@@ -966,11 +967,12 @@ int main(int argc, char *argv[])
 #define f_continue 2u
 #define f_fixup 4u
 #define f_stats 8u
+#define f_checkid 16u
 #define f_write 256u
 
   set_prog(argv[0]);
   for (;;) {
-    opt = getopt(argc, argv, "hB:E:FR:X:b:cr:s"); if (opt < 0) break;
+    opt = getopt(argc, argv, "hB:E:FR:X:b:cir:s"); if (opt < 0) break;
     switch (opt) {
       case 'h': usage(stderr); exit(0);
       case 'B':
@@ -1109,6 +1111,16 @@ int main(int argc, char *argv[])
     bail("device `%s' volume size %"PRIu64" not a multiple of %d",
         device, volsz, SECTORSZ);
 
+  if (f&f_checkid) {
+    open_dvd(outfile, 0, &dvd_out);
+    if (dvd_id(id_in, dvd, DIF_MUSTIFOHASH, device) ||
+       dvd_id(id_out, dvd_out, DIF_MUSTIFOHASH, device))
+      exit(2);
+    if (STRCMP(id_in, !=, id_out))
+      bail("DVD id mismatch: input `%s' is `%s'; output `%s' is `%s'",
+          device, id_in, outfile, id_out);
+  }
+
   outfd = open(outfile, O_WRONLY | O_CREAT, 0666);
   if (outfd < 0)
     bail_syserr(errno, "failed to create output file `%s'", outfile);