X-Git-Url: https://git.distorted.org.uk/~mdw/dvdrip/blobdiff_plain/87a145d259478ae7d7dcc789d368b8fa3566f323..69f3ec3767748b38fedbb9dcc06386cd77f7d6ac:/dvd-sector-copy.c diff --git a/dvd-sector-copy.c b/dvd-sector-copy.c index a43adb2..b1f4a53 100644 --- a/dvd-sector-copy.c +++ b/dvd-sector-copy.c @@ -43,8 +43,8 @@ static int status = 0; static void usage(FILE *fp) { fprintf(fp, - "usage: %s [-c] [-D DEV] [-R MAP] " - "[-b OUTMAP] [-o OUTFILE] [-r [START]-[END]]\n", + "usage: %s [-c] [-R MAP] [-b OUTMAP] [-r [START]-[END]]\n" + "\tDEVICE OUTFILE\n", prog); } @@ -524,8 +524,7 @@ static void emit(secaddr start, secaddr end) if (ferror(mapfp)) bail_syserr(errno, "error writing bad-sector map file"); } - if (outfd >= 0 && - lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0) + if (lseek(outfd, (off_t)(bad_hi - bad_lo)*SECTORSZ, SEEK_CUR) < 0) bail_syserr(errno, "failed to seek past bad sectors"); status = 1; } @@ -648,7 +647,7 @@ int main(int argc, char *argv[]) off_t off; secaddr start, end; const struct event *ev; - const char *device = "/dev/dvd", *outfile = 0; + const char *device, *outfile; int opt, blksz; unsigned n; size_t i; @@ -667,10 +666,9 @@ int main(int argc, char *argv[]) p = strrchr(argv[0], '/'); prog = p ? p + 1 : argv[0]; for (;;) { - opt = getopt(argc, argv, "hD:FR:b:co:r:"); if (opt < 0) break; + opt = getopt(argc, argv, "hFR:X:b:cr:"); if (opt < 0) break; switch (opt) { case 'h': usage(stderr); exit(0); - case 'D': device = optarg; break; case 'F': f |= f_fixup; break; case 'R': fp = fopen(optarg, "r"); @@ -698,7 +696,6 @@ int main(int argc, char *argv[]) mapfile = optarg; break; case 'c': f |= f_continue; break; - case 'o': outfile = optarg; break; case 'r': start = 0; end = -1; if (parse_range(optarg, PRF_HYPHEN, &start, &end)) @@ -711,9 +708,11 @@ int main(int argc, char *argv[]) default: f |= f_bogus; break; } } - if (optind < argc) f |= f_bogus; + if (argc - optind != 2) f |= f_bogus; if (f&f_bogus) { usage(stderr); exit(2); } + device = argv[optind]; outfile = argv[optind + 1]; + dvdfd = open(device, O_RDONLY); if (dvdfd < 0) bail_syserr(errno, "failed to open device `%s'", device); @@ -743,7 +742,6 @@ int main(int argc, char *argv[]) } if (f&f_continue) { - if (!outfile) bail("can't continue without output file"); off = lseek(outfd, 0, SEEK_END); if (off < 0) bail_syserr(errno, "failed to seek to end of output file `%s'", @@ -846,8 +844,7 @@ int main(int argc, char *argv[]) break; case EV_WRITE: gettimeofday(&last_time, 0); last_pos = pos; - if (outfd >= 0 && - lseek(outfd, (off_t)ev->pos*SECTORSZ, SEEK_SET) < 0) + if (lseek(outfd, (off_t)ev->pos*SECTORSZ, SEEK_SET) < 0) bail_syserr(errno, "failed to seek to resume position " "(sector %"PRIuSEC") in output file `%s'", @@ -879,7 +876,7 @@ int main(int argc, char *argv[]) if (progresslen) putchar('\n'); - if (outfd >= 0 && ftruncate(outfd, (off_t)limit*SECTORSZ) < 0) + if (ftruncate(outfd, (off_t)limit*SECTORSZ) < 0) bail_syserr(errno, "failed to set output file `%s' length", outfile); if (dvd) DVDClose(dvd);