aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDaeho Jeong <daehojeong@google.com>2020-09-10 14:29:48 +0900
committerJaegeuk Kim <jaegeuk@kernel.org>2020-12-07 09:25:12 -0800
commit717d70db600fbe09354ed141977f83b50b38104a (patch)
treecd63fe6931457653e4fd379aa1a220a98462258f
parentd41dcbdf46dc3841cd0a0507e6573e38cb6c55bb (diff)
downloadf2fs-tools-717d70db600fbe09354ed141977f83b50b38104a.tar.gz
f2fs_io: change fibmap to fiemap
Currently we support fiemap command using fibmap. It's simple and easy to use, but we cannot use this for compressed file. To support more different types of files, we need to change this to use fiemap. Signed-off-by: Daeho Jeong <daehojeong@google.com> Reviewed-by: Chao Yu <yuchao0@huawei.com> [Jaegeuk Kim: add Android build] Signed-off-by: Jaegeuk Kim <jaegeuk@kernel.org>
-rw-r--r--configure.ac1
-rw-r--r--include/android_config.h2
-rw-r--r--tools/f2fs_io/Makefile.am2
-rw-r--r--tools/f2fs_io/f2fs_io.c49
-rw-r--r--tools/f2fs_io/f2fs_io.h10
5 files changed, 42 insertions, 22 deletions
diff --git a/configure.ac b/configure.ac
index 1e5619d..c1c3e07 100644
--- a/configure.ac
+++ b/configure.ac
@@ -93,6 +93,7 @@ AC_CHECK_HEADERS(m4_flatten([
linux/posix_acl.h
linux/types.h
linux/xattr.h
+ linux/fiemap.h
mach/mach_time.h
mntent.h
scsi/sg.h
diff --git a/include/android_config.h b/include/android_config.h
index 0613400..0a03d35 100644
--- a/include/android_config.h
+++ b/include/android_config.h
@@ -7,6 +7,8 @@
#define HAVE_POSIX_ACL_H 1
#define HAVE_LINUX_TYPES_H 1
#define HAVE_LINUX_XATTR_H 1
+#define HAVE_LINUX_FS_H 1
+#define HAVE_LINUX_FIEMAP_H 1
#define HAVE_MNTENT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRING_H 1
diff --git a/tools/f2fs_io/Makefile.am b/tools/f2fs_io/Makefile.am
index 73ce525..6c17db1 100644
--- a/tools/f2fs_io/Makefile.am
+++ b/tools/f2fs_io/Makefile.am
@@ -1,7 +1,7 @@
## Makefile.am
if LINUX
-AM_CPPFLAGS = -I./include
+AM_CPPFLAGS = -I../../include
AM_CFLAGS = -Wall
sbin_PROGRAMS = f2fs_io
f2fs_io_SOURCES = f2fs_io.c
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 6177d29..5223903 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -42,6 +42,8 @@
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
+#include <android_config.h>
+
#include "f2fs_io.h"
struct cmd_desc {
@@ -662,27 +664,18 @@ static void do_randread(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
-struct file_ext {
- __u32 f_pos;
- __u32 start_blk;
- __u32 end_blk;
- __u32 blk_count;
-};
-
-#ifndef FIBMAP
-#define FIBMAP _IO(0x00, 1) /* bmap access */
-#endif
-
#define fiemap_desc "get block address in file"
#define fiemap_help \
"f2fs_io fiemap [offset in 4kb] [count] [file_path]\n\n"\
+#if defined(HAVE_LINUX_FIEMAP_H) && defined(HAVE_LINUX_FS_H)
static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
{
- u64 offset;
- u32 blknum;
unsigned count, i;
int fd;
+ __u64 phy_addr;
+ struct fiemap *fm = xmalloc(sizeof(struct fiemap) +
+ sizeof(struct fiemap_extent));
if (argc != 4) {
fputs("Excess arguments\n\n", stderr);
@@ -690,23 +683,37 @@ static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
exit(1);
}
- offset = atoi(argv[1]);
+ fm->fm_start = atoi(argv[1]) * F2FS_BLKSIZE;
+ fm->fm_length = F2FS_BLKSIZE;
+ fm->fm_extent_count = 1;
count = atoi(argv[2]);
fd = xopen(argv[3], O_RDONLY | O_LARGEFILE, 0);
- printf("Fiemap: offset = %08"PRIx64" len = %d\n", offset, count);
+ printf("Fiemap: offset = %08"PRIx64" len = %d\n",
+ (u64)fm->fm_start / F2FS_BLKSIZE, count);
for (i = 0; i < count; i++) {
- blknum = offset + i;
-
- if (ioctl(fd, FIBMAP, &blknum) < 0)
- die_errno("FIBMAP failed");
-
- printf("%u ", blknum);
+ if (ioctl(fd, FS_IOC_FIEMAP, fm) < 0)
+ die_errno("FIEMAP failed");
+
+ phy_addr = fm->fm_extents[0].fe_physical / F2FS_BLKSIZE;
+ if (phy_addr == NEW_ADDR)
+ printf("NEW_ADDR ");
+ else
+ printf("%llu ", phy_addr);
+ fm->fm_start += F2FS_BLKSIZE;
}
printf("\n");
+ free(fm);
exit(0);
}
+#else
+static void do_fiemap(int UNUSED(argc), char **UNUSED(argv),
+ const struct cmd_desc *UNUSED(cmd))
+{
+ die("Not support for this platform");
+}
+#endif
#define gc_urgent_desc "start/end/run gc_urgent for given time period"
#define gc_urgent_help \
diff --git a/tools/f2fs_io/f2fs_io.h b/tools/f2fs_io/f2fs_io.h
index bd19ff9..05d4cfe 100644
--- a/tools/f2fs_io/f2fs_io.h
+++ b/tools/f2fs_io/f2fs_io.h
@@ -10,6 +10,13 @@
#ifdef HAVE_LINUX_TYPES_H
#include <linux/types.h>
#endif
+#ifdef HAVE_LINUX_FIEMAP_H
+#include <linux/fiemap.h>
+#endif
+#ifdef HAVE_LINUX_FS_H
+#include <linux/fs.h>
+#endif
+
#include <sys/types.h>
#ifdef UNUSED
@@ -38,6 +45,9 @@ typedef u16 __be16;
typedef u32 __be32;
#endif
+#define F2FS_BLKSIZE 4096
+#define NEW_ADDR 0xFFFFFFFF
+
#ifndef FS_IOC_GETFLAGS
#define FS_IOC_GETFLAGS _IOR('f', 1, long)
#endif