aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authordhacker29 <davidhackerdvm@gmail.com>2014-10-09 08:32:04 -0500
committerDan Pasanen <dan.pasanen@gmail.com>2014-10-09 08:32:04 -0500
commitd834ae7ec2b4dd3cf606f4bb047e2ea11e19fedf (patch)
tree88f77533c796643e65052b194c23d3a1e1b24dac
parentcfeb015e887db6edbd13ad41597d82f1e565fc33 (diff)
downloadandroid_external_f2fs-tools-d834ae7ec2b4dd3cf606f4bb047e2ea11e19fedf.tar.gz
android_external_f2fs-tools-d834ae7ec2b4dd3cf606f4bb047e2ea11e19fedf.tar.bz2
android_external_f2fs-tools-d834ae7ec2b4dd3cf606f4bb047e2ea11e19fedf.zip
f2fs-tools: add support for building for android
Change-Id: I11a6197c8beb0a1a430ce37f55ce1bddec0ab584
-rw-r--r--Android.mk71
-rw-r--r--fsck/f2fs.h4
-rw-r--r--fsck/fsck_f2fs_main.c21
-rw-r--r--fsck/main.c6
-rw-r--r--include/f2fs_fs.h8
-rw-r--r--include/f2fs_version.h4
-rw-r--r--lib/libf2fs.c6
-rw-r--r--lib/libf2fs_io.c4
-rw-r--r--mkfs/f2fs_format.c42
-rw-r--r--mkfs/f2fs_format_main.c10
-rw-r--r--mkfs/f2fs_format_utils.c4
-rw-r--r--mkfs/f2fs_format_utils.h4
-rw-r--r--mkfs/main.c21
-rw-r--r--tools/f2fstat.c4
-rw-r--r--tools/f2fstat_main.c21
-rw-r--r--tools/fibmap.c4
-rw-r--r--tools/fibmap_main.c21
17 files changed, 255 insertions, 0 deletions
diff --git a/Android.mk b/Android.mk
new file mode 100644
index 0000000..406df2c
--- /dev/null
+++ b/Android.mk
@@ -0,0 +1,71 @@
+LOCAL_PATH:= $(call my-dir)
+
+LOCAL_CFLAGS := -DANDROID
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := mkfs/f2fs_format.c mkfs/f2fs_format_main.c mkfs/f2fs_format_utils.c lib/libf2fs.c lib/libf2fs_io.c
+LOCAL_MODULE := libmake_f2fs
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := mkfs/main.c
+LOCAL_MODULE := mkfs.f2fs
+LOCAL_MODULE_TAGS := optional
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_STATIC_LIBRARIES := libmake_f2fs libcutils liblog libc
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := fsck/main.c fsck/fsck.c fsck/dump.c fsck/mount.c lib/libf2fs.c lib/libf2fs_io.c
+LOCAL_MODULE := libfsck_f2fs
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := fsck/fsck_f2fs_main.c
+LOCAL_MODULE := fsck.f2fs
+LOCAL_MODULE_TAGS := optional
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_STATIC_LIBRARIES := libfsck_f2fs libcutils liblog libc
+include $(BUILD_EXECUTABLE)
+
+SYMLINKS := $(addprefix $(TARGET_OUT)/bin/,dump.f2fs)
+$(SYMLINKS):
+ @echo "Symlink: $@ -> /system/bin/fsck.f2fs"
+ @mkdir -p $(dir $@)
+ @rm -rf $@
+ $(hide) ln -sf ../bin/fsck.f2fs $@
+
+ALL_DEFAULT_INSTALLED_MODULES += $(SYMLINKS)
+
+ALL_MODULES.$(LOCAL_MODULE).INSTALLED := \
+ $(ALL_MODULES.$(LOCAL_MODULE).INSTALLED) $(SYMLINKS)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := tools/fibmap.c
+LOCAL_MODULE := libfibmap_f2fs
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := tools/fibmap_main.c
+LOCAL_MODULE := fibmap.f2fs
+LOCAL_MODULE_TAGS := optional
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_STATIC_LIBRARIES := libfibmap_f2fs libcutils liblog libc
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := tools/f2fstat.c
+LOCAL_MODULE := libf2fstat_f2fs
+LOCAL_MODULE_TAGS := optional
+include $(BUILD_STATIC_LIBRARY)
+
+include $(CLEAR_VARS)
+LOCAL_SRC_FILES := tools/f2fstat_main.c
+LOCAL_MODULE := f2fstat
+LOCAL_MODULE_TAGS := optional
+LOCAL_FORCE_STATIC_EXECUTABLE := true
+LOCAL_STATIC_LIBRARIES := libf2fstat_f2fs libcutils liblog libc
+include $(BUILD_EXECUTABLE)
diff --git a/fsck/f2fs.h b/fsck/f2fs.h
index edb1480..ef045e0 100644
--- a/fsck/f2fs.h
+++ b/fsck/f2fs.h
@@ -26,7 +26,11 @@
#include <sys/mount.h>
#include <assert.h>
+#ifndef ANDROID
#include <f2fs_fs.h>
+#else
+#include "include/f2fs_fs.h"
+#endif
#define EXIT_ERR_CODE (-1)
#define ver_after(a, b) (typecheck(unsigned long long, a) && \
diff --git a/fsck/fsck_f2fs_main.c b/fsck/fsck_f2fs_main.c
new file mode 100644
index 0000000..ca09916
--- /dev/null
+++ b/fsck/fsck_f2fs_main.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern int fsck_f2fs_main(int argc, char **argv);
+
+int main(int argc, char **argv) {
+ return fsck_f2fs_main(argc, argv);
+}
diff --git a/fsck/main.c b/fsck/main.c
index 2af3daf..d9c0e77 100644
--- a/fsck/main.c
+++ b/fsck/main.c
@@ -177,7 +177,11 @@ cleanup:
fsck_free(sbi);
}
+#ifndef ANDROID
int main(int argc, char **argv)
+#else
+int fsck_f2fs_main(int argc, char **argv)
+#endif
{
struct f2fs_sb_info *sbi;
int ret = 0;
@@ -186,8 +190,10 @@ int main(int argc, char **argv)
f2fs_parse_options(argc, argv);
+#ifndef ANDROID
if (f2fs_dev_is_umounted(&config) < 0)
return -1;
+#endif
/* Get device */
if (f2fs_get_device_info(&config) < 0)
diff --git a/include/f2fs_fs.h b/include/f2fs_fs.h
index 6367e05..8b744aa 100644
--- a/include/f2fs_fs.h
+++ b/include/f2fs_fs.h
@@ -15,6 +15,10 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
+#else
+#ifdef ANDROID
+#include "include/f2fs_version.h"
+#endif
#endif
typedef u_int64_t u64;
@@ -142,7 +146,9 @@ typedef unsigned long pgoff_t;
snprintf(buf, len, #member)
/* these are defined in kernel */
+#ifndef PAGE_SIZE
#define PAGE_SIZE 4096
+#endif
#define PAGE_CACHE_SIZE 4096
#define BITS_PER_BYTE 8
#define F2FS_SUPER_MAGIC 0xF2F52010 /* F2FS Magic Number */
@@ -677,7 +683,9 @@ extern u_int32_t f2fs_cal_crc32(u_int32_t, void *, int);
extern int f2fs_crc_valid(u_int32_t blk_crc, void *buf, int len);
extern void f2fs_init_configuration(struct f2fs_configuration *);
+#ifndef ANDROID
extern int f2fs_dev_is_umounted(struct f2fs_configuration *);
+#endif
extern int f2fs_get_device_info(struct f2fs_configuration *);
extern void f2fs_finalize_device(struct f2fs_configuration *);
diff --git a/include/f2fs_version.h b/include/f2fs_version.h
new file mode 100644
index 0000000..9a10fb8
--- /dev/null
+++ b/include/f2fs_version.h
@@ -0,0 +1,4 @@
+#define F2FS_MAJOR_VERSION 1
+#define F2FS_MINOR_VERSION 4
+#define F2FS_TOOLS_VERSION "1.4.0"
+#define F2FS_TOOLS_DATE "2014-09-18"
diff --git a/lib/libf2fs.c b/lib/libf2fs.c
index 01ef4e9..651138e 100644
--- a/lib/libf2fs.c
+++ b/lib/libf2fs.c
@@ -21,7 +21,11 @@
#include <sys/ioctl.h>
#include <linux/hdreg.h>
+#ifndef ANDROID
#include <f2fs_fs.h>
+#else
+#include "include/f2fs_fs.h"
+#endif
void ASCIIToUNICODE(u_int16_t *out_buf, u_int8_t *in_buf)
{
@@ -363,6 +367,7 @@ void f2fs_init_configuration(struct f2fs_configuration *c)
c->trim = 1;
}
+#ifndef ANDROID
static int is_mounted(const char *mpt, const char *device)
{
FILE *file = NULL;
@@ -417,6 +422,7 @@ int f2fs_dev_is_umounted(struct f2fs_configuration *c)
}
return 0;
}
+#endif
int f2fs_get_device_info(struct f2fs_configuration *c)
{
diff --git a/lib/libf2fs_io.c b/lib/libf2fs_io.c
index 0c89ee4..7cd71de 100644
--- a/lib/libf2fs_io.c
+++ b/lib/libf2fs_io.c
@@ -21,7 +21,11 @@
#include <sys/ioctl.h>
#include <linux/hdreg.h>
+#ifndef ANDROID
#include <f2fs_fs.h>
+#else
+#include "include/f2fs_fs.h"
+#endif
struct f2fs_configuration config;
diff --git a/mkfs/f2fs_format.c b/mkfs/f2fs_format.c
index e300731..e09baf5 100644
--- a/mkfs/f2fs_format.c
+++ b/mkfs/f2fs_format.c
@@ -16,9 +16,14 @@
#include <sys/stat.h>
#include <sys/mount.h>
#include <time.h>
+#ifndef ANDROID
#include <uuid/uuid.h>
#include "f2fs_fs.h"
+#else
+#include "include/f2fs_fs.h"
+#endif
+
#include "f2fs_format_utils.h"
extern struct f2fs_configuration config;
@@ -91,6 +96,43 @@ static void configure_extension_list(void)
free(config.extension_list);
}
+#ifdef ANDROID
+/*
+ This generates a version 4 universally unique identifier (UUID).
+ The format is: xxxxxxxx-xxxx-4xxx-8xxx-xxxxxxxxxxxx
+ where each x is 4 bits populated by /dev/urandom.
+ The algorithm is derived from Theodore T'so's original e2fsprogs source.
+
+ 16 bytes will be written to the passed pointer, so allocate
+ at least that much space before calling uuid_generate.
+*/
+#define RANDOM "/dev/urandom"
+void uuid_generate(unsigned char *uuid)
+{
+ int fd;
+
+ fd = open(RANDOM, O_RDONLY);
+ if(-1 == fd)
+ {
+ perror("Error while opening " RANDOM);
+ return;
+ }
+
+ if(16 != read(fd, uuid, 16))
+ {
+ perror("Error while reading from " RANDOM);
+ }
+
+ uuid[6] &= 0x0F;
+ uuid[6] |= 0x40;
+
+ uuid[8] &= 0x3F;
+ uuid[8] |= 0x80;
+
+ close(fd);
+}
+#endif
+
static int f2fs_prepare_super_block(void)
{
u_int32_t blk_size_bytes;
diff --git a/mkfs/f2fs_format_main.c b/mkfs/f2fs_format_main.c
index 19c52e4..0c9e5e8 100644
--- a/mkfs/f2fs_format_main.c
+++ b/mkfs/f2fs_format_main.c
@@ -17,9 +17,13 @@
#include <sys/mount.h>
#include <time.h>
//#include <linux/fs.h>
+#ifndef ANDROID
#include <uuid/uuid.h>
#include "f2fs_fs.h"
+#else
+#include "include/f2fs_fs.h"
+#endif
#include "f2fs_format_utils.h"
extern struct f2fs_configuration config;
@@ -111,7 +115,11 @@ static void f2fs_parse_options(int argc, char *argv[])
* config.segs_per_sec;
}
+#ifndef ANDROID
int main(int argc, char *argv[])
+#else
+int make_f2fs_main(int argc, char *argv[])
+#endif
{
MSG(0, "\n\tF2FS-tools: mkfs.f2fs Ver: %s (%s)\n\n",
F2FS_TOOLS_VERSION,
@@ -120,8 +128,10 @@ int main(int argc, char *argv[])
f2fs_parse_options(argc, argv);
+#ifndef ANDROID
if (f2fs_dev_is_umounted(&config) < 0)
return -1;
+#endif
if (f2fs_get_device_info(&config) < 0)
return -1;
diff --git a/mkfs/f2fs_format_utils.c b/mkfs/f2fs_format_utils.c
index 9892a8f..6792ce0 100644
--- a/mkfs/f2fs_format_utils.c
+++ b/mkfs/f2fs_format_utils.c
@@ -13,7 +13,11 @@
#include <sys/ioctl.h>
#include <sys/stat.h>
+#ifndef ANDROID
#include "f2fs_fs.h"
+#else
+#include "include/f2fs_fs.h"
+#endif
#ifdef HAVE_LINUX_FS_H
#include <linux/fs.h>
diff --git a/mkfs/f2fs_format_utils.h b/mkfs/f2fs_format_utils.h
index 9eb2cea..9f531ee 100644
--- a/mkfs/f2fs_format_utils.h
+++ b/mkfs/f2fs_format_utils.h
@@ -8,7 +8,11 @@
*/
#define _LARGEFILE64_SOURCE
+#ifndef ANDROID
#include "f2fs_fs.h"
+#else
+#include "include/f2fs_fs.h"
+#endif
extern struct f2fs_configuration config;
diff --git a/mkfs/main.c b/mkfs/main.c
new file mode 100644
index 0000000..29dd742
--- /dev/null
+++ b/mkfs/main.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern int make_f2fs_main(int argc, char **argv);
+
+int main(int argc, char **argv) {
+ return make_f2fs_main(argc, argv);
+}
diff --git a/tools/f2fstat.c b/tools/f2fstat.c
index c9c1d30..4301a43 100644
--- a/tools/f2fstat.c
+++ b/tools/f2fstat.c
@@ -218,7 +218,11 @@ void print_head(void)
fprintf(stderr, "util node data free valid dirty prefree node dent meta sit nat fnid cp gc ssr lfs total node meta\n");
}
+#ifndef ANDROID
int main(int argc, char *argv[])
+#else
+int f2fstat_main(int argc, char *argv[])
+#endif
{
char format[] = "%3ld %6ld %6ld %6ld %6ld %6ld %6ld %5ld %5ld %3ld %5ld %5ld %3ld %3ld %3ld %6ld %6ld %6ld %6ld %6ld\n";
int head_interval;
diff --git a/tools/f2fstat_main.c b/tools/f2fstat_main.c
new file mode 100644
index 0000000..9704dbe
--- /dev/null
+++ b/tools/f2fstat_main.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern int f2fstat_main(int argc, char **argv);
+
+int main(int argc, char **argv) {
+ return f2fstat_main(argc, argv);
+}
diff --git a/tools/fibmap.c b/tools/fibmap.c
index a6a112b..e4086b1 100644
--- a/tools/fibmap.c
+++ b/tools/fibmap.c
@@ -80,7 +80,11 @@ out:
}
+#ifndef ANDROID
int main(int argc, char *argv[])
+#else
+int fibmap_main(int argc, char *argv[])
+#endif
{
int fd;
int ret = 0;
diff --git a/tools/fibmap_main.c b/tools/fibmap_main.c
new file mode 100644
index 0000000..05cc30c
--- /dev/null
+++ b/tools/fibmap_main.c
@@ -0,0 +1,21 @@
+/*
+ * Copyright (C) 2010 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+extern int fibmap_main(int argc, char **argv);
+
+int main(int argc, char **argv) {
+ return fibmap_main(argc, argv);
+}