LOCAL_PATH:= $(call my-dir)
-ifeq ($(HOST_OS),linux)
+ifneq (,$(filter linux darwin,$(HOST_OS)))
include $(CLEAR_VARS)
LOCAL_MODULE := libf2fs_utils_host
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 \
#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);
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;
}
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;
#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() */
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)
{
}
#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,
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;
}