From 3dc5f1570454bc8dffe15bac1e7cdda5db01a776 Mon Sep 17 00:00:00 2001 From: Heiko Stuebner Date: Wed, 18 May 2011 22:59:28 +0200 Subject: [PATCH] Fix build-failure with BLKGETSIZE64 on non Linux systems The BLKGETSIZE64 ioctl is Linux specific. Signed-off-by: Heiko Stuebner --- abootimg.c | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/abootimg.c b/abootimg.c index 372d44e..303c3e5 100644 --- a/abootimg.c +++ b/abootimg.c @@ -24,8 +24,27 @@ #include #include #include + + +#ifdef __linux__ #include -#include +#include /* BLKGETSIZE64 */ +#endif + +#ifdef __CYGWIN__ +#include +#include /* BLKGETSIZE64 */ +#endif + +#if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) +#include /* DIOCGMEDIASIZE */ +#include +#endif + +#if defined(__APPLE__) +# include +#endif + #ifdef HAS_BLKID #include @@ -284,7 +303,16 @@ void check_if_block_device(t_abootimg* img) abort_perror(img->fname); unsigned long long bsize = 0; +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (ioctl(fd, DIOCGMEDIASIZE, &bsize)) +# elif defined(__APPLE__) + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &bsize)) +# elif defined(__NetBSD__) +// if (ioctl(fd, DIOCGDINFO, &label) == -1) + if (1) //does a suitable ioctl exist? +# else if (ioctl(fd, BLKGETSIZE64, &bsize)) +# endif abort_perror(img->fname); img->size = bsize; @@ -320,7 +348,17 @@ void read_header(t_abootimg* img) if (S_ISBLK(s.st_mode)) { unsigned long long bsize = 0; + +# if defined(__FreeBSD__) || defined(__FreeBSD_kernel__) + if (ioctl(fd, DIOCGMEDIASIZE, &bsize)) +# elif defined(__APPLE__) + if (ioctl(fd, DKIOCGETBLOCKCOUNT, &bsize)) +# elif defined(__NetBSD__) +// if (ioctl(fd, DIOCGDINFO, &label) == -1) + if (1) //does a suitable ioctl exist? +# else if (ioctl(fd, BLKGETSIZE64, &bsize)) +# endif abort_perror(img->fname); img->size = bsize; img->is_blkdev = 1;