summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'util.c')
-rw-r--r--util.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/util.c b/util.c
index 6148ff8..ffb113c 100644
--- a/util.c
+++ b/util.c
@@ -773,6 +773,28 @@ struct supertype *guess_super(int fd)
return NULL;
}
+/* Return size of device in bytes */
+int get_dev_size(int fd, char *dname, unsigned long long *sizep)
+{
+ unsigned long long ldsize;
+#ifdef BLKGETSIZE64
+ if (ioctl(fd, BLKGETSIZE64, &ldsize) != 0)
+#endif
+ {
+ unsigned long dsize;
+ if (ioctl(fd, BLKGETSIZE, &dsize) == 0) {
+ ldsize = dsize;
+ ldsize <<= 9;
+ } else {
+ if (dname)
+ fprintf(stderr, Name ": Cannot get size of %s: %s\b",
+ dname, strerror(errno));
+ return 0;
+ }
+ }
+ *sizep = ldsize;
+ return 1;
+}
#ifdef __TINYC__
/* tinyc doesn't optimize this check in ioctl.h out ... */