diff options
author | Noah Watkins <noahwatkins@gmail.com> | 2013-07-20 18:41:39 -0700 |
---|---|---|
committer | Noah Watkins <noahwatkins@gmail.com> | 2013-09-17 10:14:38 -0700 |
commit | 00493af984ca4fa4d534fe7d2ab710147a60e087 (patch) | |
tree | 131173efdaff5165310a42600a0885662dd94857 | |
parent | 975c43c56bd8c22ced1bbdd4ac72bf4482617393 (diff) | |
download | ceph-00493af984ca4fa4d534fe7d2ab710147a60e087.tar.gz |
blkdev: support blkdev size query on osx
Support OSX, add checks for platform specific headers.
Signed-off-by: Noah Watkins <noahwatkins@gmail.com>
-rw-r--r-- | configure.ac | 2 | ||||
-rw-r--r-- | src/common/blkdev.cc | 59 |
2 files changed, 46 insertions, 15 deletions
diff --git a/configure.ac b/configure.ac index 9cd605a6825..b80cafe6fb3 100644 --- a/configure.ac +++ b/configure.ac @@ -551,6 +551,8 @@ AC_CHECK_MEMBER([struct stat.st_mtimespec.tv_nsec], [AC_DEFINE(HAVE_STAT_ST_TIMESPEC, 1, [Define if you have struct stat.st_mtimespec.tv_nsec])]) +AC_CHECK_HEADERS([linux/fs.h]) +AC_CHECK_HEADERS([sys/disk.h]) AC_CHECK_HEADERS([sys/prctl.h]) AC_CHECK_FUNCS([prctl]) diff --git a/src/common/blkdev.cc b/src/common/blkdev.cc index b0dc0a54e9e..b70397039d0 100644 --- a/src/common/blkdev.cc +++ b/src/common/blkdev.cc @@ -1,5 +1,6 @@ #include "include/int_types.h" +#include <acconfig.h> #include <fcntl.h> #include <sys/ioctl.h> #include <errno.h> @@ -7,34 +8,62 @@ #include <sys/stat.h> #include <sys/mount.h> #include <iostream> - -#include "acconfig.h" #include "include/compat.h" -#if defined(__FreeBSD__) +#ifdef HAVE_SYS_DISK_H #include <sys/disk.h> #endif +#ifdef HAVE_LINUX_FS_H +#include <linux/fs.h> +#endif + +#ifdef __linux__ + int get_block_device_size(int fd, int64_t *psize) { - int ret = 0; - -#if defined(__FreeBSD__) - ret = ::ioctl(fd, DIOCGMEDIASIZE, psize); -#elif defined(__linux__) #ifdef BLKGETSIZE64 - // ioctl block device - ret = ::ioctl(fd, BLKGETSIZE64, psize); + int ret = ::ioctl(fd, BLKGETSIZE64, psize); #elif BLKGETSIZE - // hrm, try the 32 bit ioctl? unsigned long sectors = 0; - ret = ::ioctl(fd, BLKGETSIZE, §ors); + int ret = ::ioctl(fd, BLKGETSIZE, §ors); *psize = sectors * 512ULL; -#endif #else -#error "Compile error: we don't know how to get the size of a raw block device." -#endif /* !__FreeBSD__ */ +# error "Linux configuration error (get_block_device_size)" +#endif if (ret < 0) ret = -errno; return ret; } + +#elif defined(DARWIN) + +int get_block_device_size(int fd, int64_t *psize) +{ + unsigned long blocksize = 0; + int ret = ::ioctl(fd, DKIOCGETBLOCKSIZE, &blocksize); + if (!ret) { + unsigned long nblocks; + ret = ::ioctl(fd, DKIOCGETBLOCKCOUNT, &nblocks); + if (!ret) + *psize = nblocks * blocksize; + } + if (ret < 0) + ret = -errno; + return ret; +} + +#elif defined(__FreeBSD__) + +int get_block_device_size(int fd, int64_t *psize) +{ + int ret = ::ioctl(fd, DIOCGMEDIASIZE, psize); + if (ret < 0) + ret = -errno; + return ret; +} + +#else +# warning "Unsupported platform. Please report." +# error "Unable to query block device size." +#endif |