X-Git-Url: https://git.distorted.org.uk/~mdw/dvdrip/blobdiff_plain/0049c6b5106e540f8fe6d91016de35fe9082bff9..refs/heads/mdw/cleanup:/chkdvdimg.c diff --git a/chkdvdimg.c b/chkdvdimg.c index 0fbb48e..3a94463 100644 --- a/chkdvdimg.c +++ b/chkdvdimg.c @@ -4,8 +4,10 @@ static int status = 0; static unsigned flags = 0; #define F_FIX 1u +static void set_status(int st) + { if (st > status) status = st; } static void vgripe_syserr(int st, int err, const char *fmt, va_list ap) - { vmoan_syserr(err, fmt, ap); if (st > status) status = st; } + { vmoan_syserr(err, fmt, ap); set_status(st); } static void vgripe(int st, const char *fmt, va_list ap) { vgripe_syserr(st, 0, fmt, ap); } PRINTF_LIKE(3, 4) @@ -96,23 +98,22 @@ static int all_zero_p(const unsigned char *p, size_t sz) static void check_img(const char *file) { int fd = -1; - struct stat st; unsigned char b[SECTORSZ], bb[SECTORSZ]; + off_t volsz; + int blksz; secaddr end; unsigned i, j; - fd = open(file, (flags&F_FIX) ? O_RDWR : O_RDONLY); - if (fd < 0) - { gripe_syserr(2, errno, "failed to open `%s'", file); goto end; } - if (fstat(fd, &st)) { - gripe_syserr(2, errno, "failed to retrieve file status for `%s'", file); - goto end; - } - if (st.st_size%SECTORSZ) { + if (open_dvd(file, (flags&F_FIX) ? O_RDWR : O_RDONLY, &fd, 0)) + { set_status(2); goto end; } + blksz = SECTORSZ; volsz = device_size(fd, file, &blksz); + if (SECTORSZ != 2048) + { gripe(2, "device sector size %d /= 2048", blksz); goto end; } + if (volsz%SECTORSZ) { gripe(2, "bad length for `%s' -- not whole number of sectors", file); goto end; } - end = st.st_size/SECTORSZ; + end = volsz/SECTORSZ; if (carefully_read(fd, 256*SECTORSZ, b, SECTORSZ, file) || check_anchor_header(b, 256, CAHF_GRIPE | CAHF_FULL, file)) @@ -124,7 +125,7 @@ static void check_img(const char *file) if (bb[0] || !all_zero_p(bb, SECTORSZ)) goto nonzero; } gripe(1, "too many trailing zero sectors: " - "couldn't find backup anchor descriptor"); + "couldn't find backup anchor descriptor in `%s'", file); goto end; nonzero: j = i; @@ -193,7 +194,9 @@ int main(int argc, char *argv[]) } if (optind >= argc) f |= f_bogus; if (f&f_bogus) { usage(stderr); exit(2); } - + setlocale(LC_ALL, ""); + progress_init(&progress); for (i = optind; i < argc; i++) check_img(argv[i]); + progress_free(&progress); return (status); }