From: Jaegeuk Kim <jaegeuk@kernel.org>
To: linux-f2fs-devel@lists.sourceforge.net
Cc: Jaegeuk Kim <jaegeuk@google.com>
Subject: [PATCH 2/4] f2fs_io: add read
Date: Wed, 20 Feb 2019 09:07:43 -0800 [thread overview]
Message-ID: <20190220170745.7328-2-jaegeuk@kernel.org> (raw)
In-Reply-To: <20190220170745.7328-1-jaegeuk@kernel.org>
From: Jaegeuk Kim <jaegeuk@google.com>
f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]
Read data in file_path and print nbytes
IO can be
buffered : buffered IO
dio : direct IO
Change-Id: I912adc4f443c3656ad067d29a1e2f581b79d28e6
Signed-off-by: Jaegeuk Kim <jaegeuk@google.com>
---
tools/f2fs_io/f2fs_io.c | 86 +++++++++++++++++++++++++++++++++++++++++
1 file changed, 86 insertions(+)
diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index 0515108..d09f732 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -214,6 +214,91 @@ static void do_write(int argc, char **argv, const struct cmd_desc *cmd)
exit(0);
}
+#define read_desc "read data from file"
+#define read_help \
+"f2fs_io read [chunk_size in 4kb] [offset in chunk_size] [count] [IO] [print_nbytes] [file_path]\n\n" \
+"Read data in file_path and print nbytes\n" \
+"IO can be\n" \
+" buffered : buffered IO\n" \
+" dio : direct IO\n" \
+
+static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
+{
+ u64 buf_size = 0, ret = 0, read_cnt = 0;
+ loff_t offset;
+ char *buf = NULL;
+ char *print_buf = NULL;
+ unsigned bs, count, i, print_bytes;
+ int flags = 0;
+ int fd;
+
+ if (argc != 7) {
+ fputs("Excess arguments\n\n", stderr);
+ fputs(cmd->cmd_help, stderr);
+ exit(1);
+ }
+
+ bs = atoi(argv[1]);
+ if (bs > 1024) {
+ fputs("Too big chunk size - limit: 4MB\n\n", stderr);
+ exit(1);
+ }
+ buf_size = bs * 4096;
+
+ offset = atoi(argv[2]) * buf_size;
+
+ buf = aligned_alloc(4096, buf_size);
+ if (!buf) {
+ fputs("Memory alloc failed\n\n", stderr);
+ exit(1);
+ }
+ count = atoi(argv[3]);
+ if (!strcmp(argv[4], "buffered")) {
+ flags |= O_DIRECT;
+ } else if (strcmp(argv[4], "dio")) {
+ fputs("Wrong IO type\n\n", stderr);
+ exit(1);
+ }
+
+ print_bytes = atoi(argv[5]);
+ if (print_bytes > buf_size) {
+ fputs("Print_nbytes should be less then chunk_size in kb\n\n", stderr);
+ exit(1);
+ }
+ print_buf = malloc(print_bytes);
+ if (!print_buf) {
+ fputs("Memory alloc failed\n\n", stderr);
+ exit(1);
+ }
+
+ fd = open(argv[6], O_RDONLY | flags);
+ if (fd == -1) {
+ fputs("Open failed\n\n", stderr);
+ exit(1);
+ }
+
+ for (i = 0; i < count; i++) {
+ ret = pread(fd, buf, buf_size, offset + buf_size * i);
+ if (ret != buf_size)
+ break;
+
+ read_cnt += ret;
+ if (i == 0)
+ memcpy(print_buf, buf, print_bytes);
+ }
+ printf("Read %lu bytes and print %d bytes:\n", read_cnt, print_bytes);
+ printf("%08lx : ", offset);
+ for (i = 1; i <= print_bytes; i++) {
+ printf("%02x", print_buf[i - 1]);
+ if (i % 16 == 0)
+ printf("\n%08lx : ", offset + 16 * i);
+ else if (i % 2 == 0)
+ printf(" ");
+ }
+ 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 }
@@ -224,6 +309,7 @@ const struct cmd_desc cmd_list[] = {
CMD(shutdown),
CMD(pinfile),
CMD(write),
+ CMD(read),
{ 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 ` Jaegeuk Kim [this message]
2019-02-20 17:07 ` [PATCH 3/4] f2fs_io: add fiemap Jaegeuk Kim
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-2-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.