diff options
author | Gao Xiang <hsiangkao@linux.alibaba.com> | 2023-03-27 10:57:37 +0800 |
---|---|---|
committer | Gao Xiang <hsiangkao@linux.alibaba.com> | 2023-03-27 11:29:13 +0800 |
commit | f09c4fa35959771e2e595657fb9fa03251b4d023 (patch) | |
tree | 403e3f7010689e38b7c60c6f1be2d1f77177a151 | |
parent | 3f7334454e22a9c6d3f5a966ae200ffc2c175092 (diff) | |
download | erofs-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.c | 14 |
1 files changed, 7 insertions, 7 deletions
@@ -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; |