+static off_t get_blk_size(int fd)
+{
+ uint64_t size;
+ if (ioctl(fd, BLKGETSIZE64, &size))
+ errp("ioctl(BLKGETSIZE64) failed");
+ return size;
+}
+
+static off_t get_size(int fd)
+{
+ struct stat st;
+
+ if (fstat(fd, &st))
+ errp("could not stat %i", fd);
+
+ if (S_ISREG(st.st_mode))
+ return st.st_size;
+ else if (S_ISBLK(st.st_mode))
+ return get_blk_size(fd);
+
+ errno = EINVAL;
+ errp("unknown type of file");
+}
+