diff mbox series

[f2fs-dev] f2fs_io: fix output of do_read()

Message ID 20240523134657.2255695-1-chao@kernel.org (mailing list archive)
State New
Headers show
Series [f2fs-dev] f2fs_io: fix output of do_read() | expand

Commit Message

Chao Yu May 23, 2024, 1:46 p.m. UTC
echo 1 > file
f2fs_io read 1 0 1 dio 4096 ./file
Read 0 bytes total_time = 17 us, print 4096 bytes:
00000000 : ffffffd537 ffffffc957 0500 0000 0000 0000 0000 0000
00000100 : 0000 0000 0000 0000 0000 0000 0000 0000
00000200 : 0000 0000 0000 0000 0000 0000 0000 0000
00000300 : 0000 0000 0000 0000 ffffffc10f 0200 0000 0000

For the case reading across EOF, it missed to copy returned
data to print_buf.

After:
f2fs_io read 1 0 1 dio 4096 ./file
pread expected: 4096, readed: 2
Read 2 bytes total_time = 177 us, print 4096 bytes:
00000000 : 310a 0000 0000 0000 0000 0000 0000 0000

Signed-off-by: Chao Yu <chao@kernel.org>
---
 tools/f2fs_io/f2fs_io.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
diff mbox series

Patch

diff --git a/tools/f2fs_io/f2fs_io.c b/tools/f2fs_io/f2fs_io.c
index a7b593a..79b4d04 100644
--- a/tools/f2fs_io/f2fs_io.c
+++ b/tools/f2fs_io/f2fs_io.c
@@ -867,8 +867,15 @@  static void do_read(int argc, char **argv, const struct cmd_desc *cmd)
 	if (!do_mmap) {
 		for (i = 0; i < count; i++) {
 			ret = pread(fd, buf, buf_size, offset + buf_size * i);
-			if (ret != buf_size)
+			if (ret != buf_size) {
+				printf("pread expected: %"PRIu64", readed: %"PRIu64"\n",
+						buf_size, ret);
+				if (ret > 0) {
+					read_cnt += ret;
+					memcpy(print_buf, buf, print_bytes);
+				}
 				break;
+			}
 
 			read_cnt += ret;
 			if (i == 0)