aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJaegeuk Kim <jaegeuk@google.com>2019-01-16 15:17:25 -0800
committerJaegeuk Kim <jaegeuk@kernel.org>2019-02-11 18:36:47 -0800
commit70f937a263567659b3ff79d450082253c39ce371 (patch)
tree3cb4e8704f0fb8068648b5ff2ae12cce142b6de2
parentd69fb9879d2bcc8b0dc7e1d2da290a2b6ce176ac (diff)
downloadf2fs-tools-70f937a263567659b3ff79d450082253c39ce371.tar.gz
f2fs_io: add fiemap
f2fs_io fiemap [offset in 4kb] [count] [file_path] Change-Id: Iee9e8b742ada6a12a9f761b3a6de8d82a60e1b59 Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
-rw-r--r--tools/f2fs_io/f2fs_io.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index d09f732..70fde6e 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -9,6 +9,15 @@
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
+#ifndef _LARGEFILE_SOURCE
+#define _LARGEFILE_SOURCE
+#endif
+#ifndef _LARGEFILE64_SOURCE
+#define _LARGEFILE64_SOURCE
+#endif
+#ifndef O_LARGEFILE
+#define O_LARGEFILE 0
+#endif
#include <stdio.h>
#include <fcntl.h>
@@ -299,6 +308,57 @@ static void do_read(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"\
+
+static void do_fiemap(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ loff_t offset;
+ u32 blknum;
+ unsigned count, i;
+ int fd;
+
+ if (argc != 4) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ offset = atoi(argv[1]);
+ count = atoi(argv[2]);
+
+ fd = open(argv[3], O_RDONLY | O_LARGEFILE);
+ if (fd == -1) {
+ fputs("Open failed\n\n", stderr);
+ exit(1);
+ }
+
+ printf("Fiemap: offset = %08lx len = %d\n", offset, count);
+ for (i = 0; i < count; i++) {
+ blknum = offset + i;
+
+ if (ioctl(fd, FIBMAP, &blknum) < 0) {
+ fputs("FIBMAP failed\n\n", stderr);
+ exit(1);
+ }
+ printf("%u ", blknum);
+ }
+ printf("\n");
+ exit(0);
+}
+
#define CMD_HIDDEN 0x0001
#define CMD(name) { #name, do_##name, name##_desc, name##_help, 0 }
#define _CMD(name) { #name, do_##name, NULL, NULL, CMD_HIDDEN }
@@ -310,6 +370,7 @@ const struct cmd_desc cmd_list[] = {
CMD(pinfile),
CMD(write),
CMD(read),
+ CMD(fiemap),
{ NULL, NULL, NULL, NULL, 0 }
};