[PATCH] erofs-utils: lib: justify post-EOD read behavior

Gao Xiang hsiangkao at linux.alibaba.com
Mon Mar 27 13:57:37 AEDT 2023


In the past, errors will be returned when reading post-EOD data.
Let's align this with the generic EOD behavior (zero-filling) instead.

Signed-off-by: Gao Xiang <hsiangkao at linux.alibaba.com>
---
 lib/io.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/lib/io.c b/lib/io.c
index b318d91..2daa3d3 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -284,18 +284,18 @@ int dev_read(int device_id, void *buf, u64 offset, size_t len)
 #else
 		read_count = pread(fd, buf, len, (off_t)offset);
 #endif
-		if (read_count == -1 || read_count == 0) {
-			if (errno) {
+		if (read_count < 1) {
+			if (!read_count) {
+				erofs_err("Reach EOF of device - %s:[%" PRIu64 ", %zd].",
+					  erofs_devname, offset, len);
+				memset(buf, 0, len);
+				read_count = len;
+			} else if (errno != EINTR) {
 				erofs_err("Failed to read data from device - %s:[%" PRIu64 ", %zd].",
 					  erofs_devname, offset, len);
 				return -errno;
-			} else {
-				erofs_err("Reach EOF of device - %s:[%" PRIu64 ", %zd].",
-					  erofs_devname, offset, len);
-				return -EINVAL;
 			}
 		}
-
 		offset += read_count;
 		len -= read_count;
 		buf += read_count;
-- 
2.24.4



More information about the Linux-erofs mailing list