From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@google.com>
Subject: [PATCH 3/4] f2fs_io: add fiemap
Date: Wed, 20 Feb 2019 09:07:44 -0800 [thread overview]
Message-ID: <20190220170745.7328-3-jaegeuk@kernel.org> (raw)
In-Reply-To: <20190220170745.7328-1-jaegeuk@kernel.org>
From: Jaegeuk Kim <jaegeuk@google.com>
f2fs_io fiemap [offset in 4kb] [count] [file_path]
Change-Id: Iee9e8b742ada6a12a9f761b3a6de8d82a60e1b59
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
tools/f2fs_io/f2fs_io.c | 61 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 61 insertions(+)
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 }
};
--
2.19.0.605.g01d371f741-goog
next prev parent reply other threads:[~2019-02-20 17:07 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-02-20 17:07 [PATCH 1/4] f2fs_io: add write Jaegeuk Kim
2019-02-20 17:07 ` [PATCH 2/4] f2fs_io: add read Jaegeuk Kim
2019-02-20 17:07 ` Jaegeuk Kim [this message]
2019-02-20 17:07 ` [PATCH 4/4] f2fs_io: add gc_urgent Jaegeuk Kim
2019-02-28 1:23 ` [PATCH 1/4] f2fs_io: add write Chao Yu
2019-02-28 3:12 ` Jaegeuk Kim
2019-02-28 1:35 ` Chao Yu
2019-02-28 3:11 ` Jaegeuk Kim
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20190220170745.7328-3-jaegeuk@kernel.org \
--to=jaegeuk@kernel.org \
--cc=jaegeuk@google.com \
--cc=linux-f2fs-devel@lists.sourceforge.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.