{
unsigned f = 0;
const char *p;
- uint64_t volsz;
+ off_t volsz;
secaddr pos;
off_t off;
secaddr start, end, last;
const char *rateunit, *totunit;
char timebuf[TIMESTRMAX], id_in[MAXIDSZ], id_out[MAXIDSZ];
dvd_reader_t *dvd_out;
- struct stat st;
#ifdef DEBUG
const struct file *file;
char fn[MAXFNSZ];
}
open_dvd(device, &dvdfd, &dvd);
- if (fstat(dvdfd, &st))
- bail_syserr(errno, "failed to stat device `%s'", device);
- if (S_ISREG(st.st_mode)) {
- blksz = SECTORSZ;
- volsz = st.st_size;
- } else if (S_ISBLK(st.st_mode)) {
- if (ioctl(dvdfd, BLKSSZGET, &blksz))
- bail_syserr(errno, "failed to get block size for `%s'", device);
- if (ioctl(dvdfd, BLKGETSIZE64, &volsz))
- bail_syserr(errno, "failed to get volume size for `%s'", device);
- } else
- bail("can't use `%s' as source: expected file or block device", device);
+ blksz = SECTORSZ; volsz = device_size(dvdfd, device, &blksz);
if (blksz != SECTORSZ)
bail("device `%s' block size %d /= %d", device, blksz, SECTORSZ);
if (volsz%SECTORSZ)
bail_syserr(errno, "error writing %s file", what);
}
+off_t device_size(int fd, const char *file, int *blksz_out)
+{
+ struct stat st;
+ uint64_t volsz;
+
+ if (fstat(fd, &st))
+ bail_syserr(errno, "failed to obtain status for `%s'", file);
+ if (S_ISREG(st.st_mode))
+ volsz = st.st_size;
+ else if (S_ISBLK(st.st_mode)) {
+ if (ioctl(fd, BLKGETSIZE64, &volsz))
+ bail_syserr(errno, "failed to get volume size for `%s'", file);
+ if (ioctl(fd, BLKSSZGET, blksz_out))
+ bail_syserr(errno, "failed to get block size for `%s'", file);
+ } else
+ bail("can't read size for `%s': expected file or block device", file);
+ return ((off_t)volsz);
+}
+
void store_filename(char *buf, ident id)
{
switch (id_kind(id)) {
const char *what);
extern void check_write(FILE *fp, const char *what);
extern void carefully_fclose(FILE *fp, const char *what);
+extern off_t device_size(int fd, const char *file, int *blksz_out);
enum { RAW, IFO, VOB, BUP };
typedef uint_least32_t ident;