aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2018-03-09 13:25:22 -0800
committerJaegeuk Kim <jaegeuk@google.com>2018-04-04 11:30:17 -0700
commit4bc7a2a21c96f372d9391280263d813c00901d5d (patch)
treeaba9f6ec4906de31b77ee19aa137fa0d7c3b2b95
parent7bf7f15cdd268fcd238af8dd9246b05f15cbebd3 (diff)
downloadf2fs-tools-4bc7a2a21c96f372d9391280263d813c00901d5d.tar.gz
ANDROID: check_f2fs: add a tool to check basic f2fs features
For Go devices, we need to check f2fs is enabled correctly. Bug: 77144946 Change-Id: Ia3df7d12bc251d9e94c0054d5c2b8572b4b71a8c Merged-In: Ia3df7d12bc251d9e94c0054d5c2b8572b4b71a8c Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
-rw-r--r--tools/check_f2fs.c110
1 files changed, 110 insertions, 0 deletions
diff --git a/tools/check_f2fs.c b/tools/check_f2fs.c
new file mode 100644
index 0000000..f8b960a
--- /dev/null
+++ b/tools/check_f2fs.c
@@ -0,0 +1,110 @@
+#include <stdio.h>
+#include <sys/mman.h>
+#include <sys/ioctl.h>
+#include <sys/socket.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <unistd.h>
+#include <sys/wait.h>
+#include <sys/syscall.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <getopt.h>
+#include <string.h>
+#include <stdlib.h>
+
+#define F2FS_IOCTL_MAGIC 0xf5
+#define F2FS_IOC_START_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 1)
+#define F2FS_IOC_COMMIT_ATOMIC_WRITE _IO(F2FS_IOCTL_MAGIC, 2)
+#define F2FS_IOC_START_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 3)
+#define F2FS_IOC_RELEASE_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 4)
+#define F2FS_IOC_ABORT_VOLATILE_WRITE _IO(F2FS_IOCTL_MAGIC, 5)
+#define F2FS_IOC_GARBAGE_COLLECT _IO(F2FS_IOCTL_MAGIC, 6)
+
+#define DB1_PATH "/data/database_file1"
+#define DB2_PATH "/sdcard/database_file2"
+
+#define BLOCK 4096
+#define BLOCKS (2 * BLOCK)
+
+int buf[BLOCKS];
+char cmd[BLOCK];
+
+static int run(char *cmd)
+{
+ int status;
+
+ fflush(stdout);
+
+ switch (fork()) {
+ case 0:
+ execl("/system/bin/sh", "sh", "-c", cmd, (char *) 0);
+ default:
+ wait(&status);
+ }
+}
+
+static int test_atomic_write(char *path)
+{
+ int db, ret, written, i;
+
+ printf("\tOpen %s... \n", path);
+ db = open(path, O_RDWR|O_CREAT);
+ if (db < 0) {
+ printf("open failed errno:%d\n", errno);
+ return -1;
+ }
+ printf("\tStart ... \n");
+ ret = ioctl(db, F2FS_IOC_START_ATOMIC_WRITE);
+ if (ret) {
+ printf("ioctl failed errno:%d\n", errno);
+ return -1;
+ }
+ printf("\tWrite to the %dkB ... \n", BLOCKS / 1024);
+ written = write(db, buf, BLOCKS);
+ if (written != BLOCKS) {
+ printf("write fail written:%d, errno:%d\n", written, errno);
+ return -1;
+ }
+ printf("\tCheck : Atomic in-memory count: 2\n");
+ run("cat /sys/kernel/debug/f2fs/status | grep atomic");
+
+ printf("\tCommit ... \n");
+ ret = ioctl(db, F2FS_IOC_COMMIT_ATOMIC_WRITE);
+ if (ret) {
+ printf("ioctl failed errno:%d\n", errno);
+ return -1;
+ }
+ return 0;
+}
+
+int main(int argc, char **argv)
+{
+ int db, ret, written, i;
+
+ memset(buf, 0xff, BLOCKS);
+
+ printf("# Test 0: Check F2FS support\n");
+ run("cat /proc/filesystems");
+
+ printf("# Test 1: Check F2FS status on /userata\n");
+ printf("\t= FS type /userata\n");
+ run("mount | grep data");
+
+ printf("\n\t= F2FS features\n");
+ run("ls -1 /sys/fs/f2fs/features/");
+ run("find /sys/fs/f2fs -type f -name \"features\" -print -exec cat {} \\;");
+ run("find /sys/fs/f2fs -type f -name \"ipu_policy\" -print -exec cat {} \\;");
+ run("find /sys/fs/f2fs -type f -name \"discard_granularity\" -print -exec cat {} \\;");
+ run("cat /sys/kernel/debug/f2fs/status");
+
+ printf("\n\n# Test 2: Atomic_write on /userata\n");
+ if (test_atomic_write(DB1_PATH))
+ return -1;
+
+ printf("# Test 3: Atomic_write on /sdcard\n");
+ if (test_atomic_write(DB2_PATH))
+ return -1;
+ return 0;
+}