Skip to contentSkip to conversation

f2fs_io: fix output of do_read()

PATCH New Chao Yu 1 participant 1 message May 23, 2024

lore
Share & tools
lore

Chao Yu

author
#0 lore raw

PATCH 1/1 f2fs_io: fix output of do_read()

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

---
 tools/f2fs_io/f2fs_io.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)
tools/f2fs_io/f2fs_io.c +8 -1
index a7b593a..79b4d04 100644
@@ -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)
Signature · 8 lines
2.40.1



_______________________________________________
Linux-f2fs-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/linux-f2fs-devel