OSDN Git Service

libdiskconfig: Enable Mac OS X host build
authorAndrew P. Boie <andrew.p.boie@intel.com>
Fri, 31 Aug 2012 19:05:55 +0000 (12:05 -0700)
committerChih-Wei Huang <cwhuang@linux.org.tw>
Sat, 6 May 2017 14:51:40 +0000 (22:51 +0800)
Change-Id: Iacc7d5463364d0cd15ca9fabaa58ad05857d9e78
Signed-off-by: Andrew P. Boie <andrew.p.boie@intel.com>
include/diskconfig/diskconfig.h
libdiskconfig/Android.mk
libdiskconfig/diskconfig.c

index d45b99e..de311b7 100644 (file)
 #include <stdint.h>
 #include <sys/types.h>
 
+#ifdef __APPLE__
+typedef int64_t loff_t;
+#define lseek64 lseek
+#endif
+
 #ifdef __cplusplus
 extern "C" {
 #endif
index 624e385..8baacd7 100644 (file)
@@ -15,11 +15,9 @@ LOCAL_SYSTEM_SHARED_LIBRARIES := libcutils liblog libc
 LOCAL_CFLAGS := -Werror
 include $(BUILD_SHARED_LIBRARY)
 
-ifeq ($(HOST_OS),linux)
 include $(CLEAR_VARS)
 LOCAL_SRC_FILES := $(commonSources)
 LOCAL_MODULE := libdiskconfig_host
 LOCAL_MODULE_TAGS := optional
-LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE
+LOCAL_CFLAGS := -O2 -g -W -Wall -Werror -D_LARGEFILE64_SOURCE -DHOST_BUILD
 include $(BUILD_HOST_STATIC_LIBRARY)
-endif # HOST_OS == linux
index 8f337cf..11a4fd6 100644 (file)
@@ -27,7 +27,9 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 
+#ifndef HOST_BUILD
 #include <linux/fs.h>
+#endif
 
 #include <cutils/config_utils.h>
 #include <log/log.h>
@@ -236,6 +238,7 @@ fail:
     return NULL;
 }
 
+#ifndef HOST_BUILD
 static int
 sync_ptable(int fd)
 {
@@ -256,6 +259,13 @@ sync_ptable(int fd)
 
     return 0;
 }
+#else
+static int sync_ptable(int fd)
+{
+    (void)fd;
+    return 0;
+}
+#endif
 
 /* This function verifies that the disk info provided is valid, and if so,
  * returns an open file descriptor.
@@ -272,7 +282,6 @@ static int
 validate(struct disk_info *dinfo)
 {
     int fd;
-    int sect_sz;
     uint64_t disk_size;
     uint64_t total_size;
     int cnt;
@@ -298,6 +307,12 @@ validate(struct disk_info *dinfo)
     /* Verify that we can operate on the device that was requested.
      * We presently only support block devices and regular file images. */
     if (S_ISBLK(stat.st_mode)) {
+#ifdef HOST_BUILD
+        ALOGE("Block device manipulation on host forbidden");
+        goto fail;
+#else
+        int sect_sz;
+
         /* get the sector size and make sure we agree */
         if (ioctl(fd, BLKSSZGET, &sect_sz) < 0) {
             ALOGE("Cannot get sector size (errno=%d)", errno);
@@ -319,6 +334,7 @@ validate(struct disk_info *dinfo)
             dinfo->num_lba = (uint32_t)(disk_size / (uint64_t)dinfo->sect_size);
         } else
             disk_size = (uint64_t)dinfo->num_lba * (uint64_t)dinfo->sect_size;
+#endif
     } else if (S_ISREG(stat.st_mode)) {
         ALOGI("Requesting operation on a regular file, not block device.");
         if (!dinfo->sect_size) {