check_f2fs: fix wrong calculation of # of sectors

Bug: 279519292
Change-Id: Ief3718f35f8ad10bc3b2efc2e1d3445016ee20da
Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
diff --git a/tools/check_f2fs.c b/tools/check_f2fs.c
index f92b04c..46be1f8 100644
--- a/tools/check_f2fs.c
+++ b/tools/check_f2fs.c
@@ -26,10 +26,12 @@
 #define DB2_PATH "/mnt/androidwritable/0/emulated/0/Android/data/database_file2"
 #define FILE_PATH "/data/testfile"
 
+#define F2FS_BLKSIZE 4096
+#define BLKS_TO_SECTOR_BITS 3
 #define BLOCK 4096
 #define BLOCKS (2 * BLOCK)
 
-int buf[BLOCKS];
+char buf[BLOCKS];
 char cmd[BLOCK];
 
 static int run(const char *cmd)
@@ -97,6 +99,7 @@
 	int fd, written;
 	struct stat sb;
 	int large_size = 1024 * 1024 * 100;	/* 100 MB */
+	int blocks;
 
 	printf("\tOpen  %s... \n", path);
 	fd = open(path, O_RDWR|O_CREAT|O_TRUNC, 0666);
@@ -123,7 +126,11 @@
 		return -1;
 	}
 
-	if ((long long)sb.st_size / 512 != (long long)sb.st_blocks) {
+	blocks = (long long)sb.st_size / F2FS_BLKSIZE;
+	if (sb.st_size % F2FS_BLKSIZE)
+		blocks++;
+
+	if (blocks << BLKS_TO_SECTOR_BITS != (long long)sb.st_blocks) {
 		printf("FAIL: Mismatch i_size and i_blocks: %lld %lld\n",
 			(long long)sb.st_size, (long long)sb.st_blocks);
 		printf("FAIL: missing patch "