summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKeith Mok <kmok@cyngn.com>2015-09-03 11:36:51 -0700
committerMichael Bestas <mikeioannina@gmail.com>2017-01-02 01:29:10 +0200
commit9c339d72fd3cc86283e66deccf806d8585dceaf3 (patch)
treea9bc4e624c5a49685c3272bddf159af74c00c04e
parentf7cec4f08be3b704ab8cb9f60a577ac723aceeba (diff)
downloadandroid_system_extras-9c339d72fd3cc86283e66deccf806d8585dceaf3.tar.gz
android_system_extras-9c339d72fd3cc86283e66deccf806d8585dceaf3.tar.bz2
android_system_extras-9c339d72fd3cc86283e66deccf806d8585dceaf3.zip
Add darwin support for the host tools
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
-rw-r--r--f2fs_utils/Android.mk4
-rw-r--r--f2fs_utils/f2fs_dlutils.c31
-rw-r--r--f2fs_utils/f2fs_ioutils.c15
-rw-r--r--f2fs_utils/f2fs_utils.c30
4 files changed, 57 insertions, 23 deletions
diff --git a/f2fs_utils/Android.mk b/f2fs_utils/Android.mk
index 647c390b..79cf63b0 100644
--- a/f2fs_utils/Android.mk
+++ b/f2fs_utils/Android.mk
@@ -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 \
diff --git a/f2fs_utils/f2fs_dlutils.c b/f2fs_utils/f2fs_dlutils.c
index 40be4161..10e49d97 100644
--- a/f2fs_utils/f2fs_dlutils.c
+++ b/f2fs_utils/f2fs_dlutils.c
@@ -35,10 +35,20 @@
#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;
diff --git a/f2fs_utils/f2fs_ioutils.c b/f2fs_utils/f2fs_ioutils.c
index 01efd53f..d85b2140 100644
--- a/f2fs_utils/f2fs_ioutils.c
+++ b/f2fs_utils/f2fs_ioutils.c
@@ -29,11 +29,13 @@
#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)
{
}
diff --git a/f2fs_utils/f2fs_utils.c b/f2fs_utils/f2fs_utils.c
index 6254c080..9833ace5 100644
--- a/f2fs_utils/f2fs_utils.c
+++ b/f2fs_utils/f2fs_utils.c
@@ -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;
}