summaryrefslogtreecommitdiffstats
path: root/src/disk.c
diff options
context:
space:
mode:
authorPali Rohár <pali.rohar@gmail.com>2014-11-26 16:33:07 +0100
committerPali Rohár <pali.rohar@gmail.com>2014-11-26 16:33:07 +0100
commitef1960cc32a524ab003abea53bb54e2a39fa6421 (patch)
tree801f99677b7447623ad76682bc27ea6f75c9b661 /src/disk.c
parent5633a067102ac35a623258bb71cb5d6396f50986 (diff)
download0xFFFF-ef1960cc32a524ab003abea53bb54e2a39fa6421.tar.bz2
disk: Enable Linux code only on Linux
Diffstat (limited to 'src/disk.c')
-rw-r--r--src/disk.c42
1 files changed, 41 insertions, 1 deletions
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 <fcntl.h>
#include <libgen.h>
+#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
-#include <sys/ioctl.h>
#include <sys/statvfs.h>
+#ifdef __linux__
+#include <sys/ioctl.h>
#include <linux/fs.h>
+#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) {