summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorNeil Brown <neilb@suse.de>2006-12-14 17:32:57 +1100
committerNeil Brown <neilb@suse.de>2006-12-14 17:32:57 +1100
commitbeae1dfe2e5a3f11e6e52a93fbf617d644708415 (patch)
treeca12b130f76d63e7156e43ac89d76c11b2c140b8 /util.c
parentab5303d695eb7249b9462f9ad4e973711622a9c5 (diff)
downloadmdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.tar.gz
mdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.tar.xz
mdadm-beae1dfe2e5a3f11e6e52a93fbf617d644708415.zip
Central calls to ioctl BLKGETSIZE
Instead of opencoding the same thing everywhere.
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 ... */