aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGao Xiang <hsiangkao@linux.alibaba.com>2023-03-27 10:57:37 +0800
committerGao Xiang <hsiangkao@linux.alibaba.com>2023-03-27 11:29:13 +0800
commitf09c4fa35959771e2e595657fb9fa03251b4d023 (patch)
tree403e3f7010689e38b7c60c6f1be2d1f77177a151
parent3f7334454e22a9c6d3f5a966ae200ffc2c175092 (diff)
downloaderofs-utils-f09c4fa35959771e2e595657fb9fa03251b4d023.tar.gz
erofs-utils: lib: justify post-EOD read behavior
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@linux.alibaba.com> Link: https://lore.kernel.org/r/20230327025737.62488-1-hsiangkao@linux.alibaba.com
-rw-r--r--lib/io.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/lib/io.c b/lib/io.c
index b318d91..9e30b7e 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_info("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;