disk: Enable Linux code only on Linux
This commit is contained in:
1 parent
5633a06710
commit
ef1960cc32
1 file changed
+41
-1
+41
-1
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user