OSDN Git Service

Add darwin support for the host tools
authorKeith Mok <kmok@cyngn.com>
Thu, 3 Sep 2015 18:36:51 +0000 (11:36 -0700)
committerSteve Kondik <steve@cyngn.com>
Thu, 25 Aug 2016 00:31:37 +0000 (17:31 -0700)
There is some symbol name conflict in the make_f2fs and the library
it loaded which darwin and linux handle that in a different way.
Remove the symbol name conflicts as cannot find a way to set symbol
resolving priority in darwin.

Change-Id: Iabe5c1b594daacd65b9ec2f694a2b5ab5575cfce

f2fs_utils/Android.mk
f2fs_utils/f2fs_dlutils.c
f2fs_utils/f2fs_ioutils.c
f2fs_utils/f2fs_utils.c

index 647c390..79cf63b 100644 (file)
@@ -2,7 +2,7 @@
 
 LOCAL_PATH:= $(call my-dir)
 
-ifeq ($(HOST_OS),linux)
+ifneq (,$(filter linux darwin,$(HOST_OS)))
 
 include $(CLEAR_VARS)
 LOCAL_MODULE := libf2fs_utils_host
@@ -41,7 +41,7 @@ LOCAL_MODULE := make_f2fs
 LOCAL_LDFLAGS := -ldl -rdynamic
 # The following libf2fs_* are from system/extras/f2fs_utils,
 # and do not use code in external/f2fs-tools.
-LOCAL_STATIC_LIBRARIES := libf2fs_utils_host libf2fs_ioutils_host libf2fs_dlutils_host
+LOCAL_STATIC_LIBRARIES := libf2fs_utils_host libf2fs_dlutils_host
 LOCAL_REQUIRED_MODULES := libf2fs_fmt_host_dyn
 LOCAL_STATIC_LIBRARIES += \
     libsparse_host \
index 40be416..10e49d9 100644 (file)
 
 #include <f2fs_fs.h>
 #include <f2fs_format_utils.h>
+#if defined(__linux__)
 #define F2FS_DYN_LIB "libf2fs_fmt_host_dyn.so"
+#elif defined(__APPLE__) && defined(__MACH__)
+#define F2FS_DYN_LIB "libf2fs_fmt_host_dyn.dylib"
+#else
+#error "Not supported OS"
+#endif
 
 int (*f2fs_format_device_dl)(void);
 void (*f2fs_init_configuration_dl)(struct f2fs_configuration *);
+void (*flush_sparse_buffs_dl)(void);
+void (*init_sparse_file_dl)(unsigned int, int64_t);
+void (*finalize_sparse_file_dl)(int);
+struct f2fs_configuration *f2fs_config;
 
 int f2fs_format_device(void) {
        assert(f2fs_format_device_dl);
@@ -48,7 +58,18 @@ void f2fs_init_configuration(struct f2fs_configuration *config) {
        assert(f2fs_init_configuration_dl);
        f2fs_init_configuration_dl(config);
 }
-
+void flush_sparse_buffs(void) {
+       assert(flush_sparse_buffs_dl);
+       return flush_sparse_buffs_dl();
+}
+void init_sparse_file(unsigned int block_size, int64_t len) {
+       assert(init_sparse_file_dl);
+       return init_sparse_file_dl(block_size, len);
+}
+void finalize_sparse_file(int fd) {
+       assert(finalize_sparse_file_dl);
+       return finalize_sparse_file_dl(fd);
+}
 int dlopenf2fs() {
        void* f2fs_lib;
 
@@ -58,7 +79,13 @@ int dlopenf2fs() {
        }
        f2fs_format_device_dl = dlsym(f2fs_lib, "f2fs_format_device");
        f2fs_init_configuration_dl = dlsym(f2fs_lib, "f2fs_init_configuration");
-       if (!f2fs_format_device_dl || !f2fs_init_configuration_dl) {
+       flush_sparse_buffs_dl = dlsym(f2fs_lib, "flush_sparse_buffs");
+       init_sparse_file_dl = dlsym(f2fs_lib, "init_sparse_file");
+       finalize_sparse_file_dl = dlsym(f2fs_lib, "finalize_sparse_file");
+       f2fs_config = dlsym(f2fs_lib, "config");
+       if (!f2fs_format_device_dl || !f2fs_init_configuration_dl ||
+                       !flush_sparse_buffs_dl || !f2fs_config ||
+                       !init_sparse_file_dl || !finalize_sparse_file_dl) {
                return -1;
        }
        return 0;
index 01efd53..d85b214 100644 (file)
 #define _LARGEFILE64_SOURCE
 
 #include <assert.h>
-#include <asm/types.h>
 #include <dlfcn.h>
 #include <errno.h>
 #include <fcntl.h>
+#ifdef __linux__
+#include <asm/types.h>
 #include <linux/fs.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>  /* memset() */
@@ -138,6 +140,17 @@ static int dev_write_sparse(void *buf, __u64 byte_offset, size_t byte_len)
        return 0;
 }
 
+void init_sparse_file(unsigned int block_size, int64_t len)
+{
+       f2fs_sparse_file = sparse_file_new(block_size, len);
+}
+
+void finalize_sparse_file(int fd)
+{
+       sparse_file_write(f2fs_sparse_file, fd, /*gzip*/0, /*sparse*/1, /*crc*/0);
+       sparse_file_destroy(f2fs_sparse_file);
+}
+
 void f2fs_finalize_device(struct f2fs_configuration *c)
 {
 }
index 6254c08..9833ace 100644 (file)
@@ -41,20 +41,16 @@ struct selabel_handle;
 #include "make_f2fs.h"
 
 extern void flush_sparse_buffs();
+extern void init_sparse_file(unsigned int block_size, int64_t len);
+extern void finalize_sparse_file(int fd);
 
-struct f2fs_configuration config;
-struct sparse_file *f2fs_sparse_file;
+extern struct f2fs_configuration *f2fs_config;
 extern int dlopenf2fs();
 
 static void reset_f2fs_info() {
-       // Reset all the global data structures used by make_f2fs so it
-       // can be called again.
-       memset(&config, 0, sizeof(config));
-       config.fd = -1;
-       if (f2fs_sparse_file) {
-               sparse_file_destroy(f2fs_sparse_file);
-               f2fs_sparse_file = NULL;
-       }
+       memset(f2fs_config, 0, sizeof(*f2fs_config));
+       f2fs_config->fd = -1;
+       f2fs_config->kd = -1;
 }
 
 int make_f2fs_sparse_fd(int fd, long long len,
@@ -64,15 +60,13 @@ int make_f2fs_sparse_fd(int fd, long long len,
                return -1;
        }
        reset_f2fs_info();
-       f2fs_init_configuration(&config);
-       len &= ~((__u64)(F2FS_BLKSIZE - 1));
-       config.total_sectors = len / config.sector_size;
-       config.start_sector = 0;
-       f2fs_sparse_file = sparse_file_new(F2FS_BLKSIZE, len);
+       f2fs_init_configuration(f2fs_config);
+       len &= ~((__u64)F2FS_BLKSIZE);
+       f2fs_config->total_sectors = len / f2fs_config->sector_size;
+       f2fs_config->start_sector = 0;
+       init_sparse_file(F2FS_BLKSIZE, len);
        f2fs_format_device();
-       sparse_file_write(f2fs_sparse_file, fd, /*gzip*/0, /*sparse*/1, /*crc*/0);
-       sparse_file_destroy(f2fs_sparse_file);
+       finalize_sparse_file(fd);
        flush_sparse_buffs();
-       f2fs_sparse_file = NULL;
        return 0;
 }