From ef1960cc32a524ab003abea53bb54e2a39fa6421 Mon Sep 17 00:00:00 2001 From: Pali Rohár Date: Wed, 26 Nov 2014 16:33:07 +0100 Subject: disk: Enable Linux code only on Linux --- src/disk.c | 42 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) (limited to 'src/disk.c') diff --git a/src/disk.c b/src/disk.c index efd2441..86394f4 100644 --- a/src/disk.c +++ b/src/disk.c @@ -18,13 +18,16 @@ #include #include +#include #include #include -#include #include +#ifdef __linux__ +#include #include +#endif #include "disk.h" #include "global.h" @@ -37,6 +40,8 @@ static char global_buf[1 << 22]; /* 4MB */ int disk_open_dev(int maj, int min, int partition, int readonly) { +#ifdef __linux__ + int fd; struct stat st; DIR * dir; @@ -140,6 +145,17 @@ int disk_open_dev(int maj, int min, int partition, int readonly) { return fd; +#else + + ERROR("Not implemented yet"); + (void)min; + (void)maj; + (void)partition; + (void)readonly; + return -1; + +#endif + } int disk_dump_dev(int fd, const char * file) { @@ -154,11 +170,25 @@ int disk_dump_dev(int fd, const char * file) { printf("Dump block device to file %s...\n", file); +#ifdef __linux__ + if ( ioctl(fd, BLKGETSIZE64, &blksize) != 0 ) { ERROR_INFO("Cannot get size of block device"); return -1; } +#else + + blksize = lseek(fd, 0, SEEK_END); + if ( blksize == (off_t)-1 ) { + ERROR_INFO("Cannot get size of block device"); + return -1; + } + + lseek(fd, 0, SEEK_SET); + +#endif + if ( blksize > ULLONG_MAX ) { ERROR("Block device is too big"); return -1; @@ -226,6 +256,8 @@ int disk_flash_dev(int fd, const char * file) { int disk_init(struct usb_device_info * dev) { +#ifdef __linux__ + int fd; int maj; int min; @@ -316,6 +348,14 @@ int disk_init(struct usb_device_info * dev) { dev->data = fd; return 0; +#else + + ERROR("Not implemented yet"); + (void)dev; + return -1; + +#endif + } enum device disk_get_device(struct usb_device_info * dev) { -- cgit v1.2.3