* [PATCH] erofs-utils: lib: fix reads for chunk-based files
@ 2026-10-13 8:35 Yifan Zhao
0 siblings, 0 replies; only message in thread
From: Yifan Zhao @ 2026-10-13 8:35 UTC (permalink / raw)
To: linux-erofs; +Cc: xiang, Yifan Zhao
Use erofs_io_read() to handle chunk read errors and short reads while
retrying EINTR without corrupting the buffer position.
Assisted-by: Codex:gpt-6-astra
Signed-off-by: Yifan Zhao <stopire@gmail.com>
---
lib/blobchunk.c | 9 ++++++---
lib/io.c | 5 +++--
2 files changed, 9 insertions(+), 5 deletions(-)
diff --git a/lib/blobchunk.c b/lib/blobchunk.c
index 8f43dd0..50e4f7e 100644
--- a/lib/blobchunk.c
+++ b/lib/blobchunk.c
@@ -325,6 +325,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
erofs_off_t startoff, int device_id)
{
struct erofs_sb_info *sbi = inode->sbi;
+ struct erofs_vfile vf = { .fd = fd };
unsigned int chunkbits = inode->u.chunkbits;
unsigned int count, unit;
struct erofs_chunkitem *chunk, *lastch;
@@ -332,7 +333,7 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
erofs_off_t pos, len, chunksize, interval_start;
erofs_blk_t minextblks;
u8 *chunkdata;
- int ret;
+ ssize_t ret;
/* if the file is fully sparsed, use one big chunk instead */
if (lseek(fd, startoff, SEEK_DATA) < 0 && errno == ENXIO) {
@@ -407,8 +408,10 @@ int erofs_blob_write_chunked_file(struct erofs_inode *inode, int fd,
}
len = min_t(u64, inode->i_size - pos, chunksize);
- ret = read(fd, chunkdata, len);
- if (ret < len) {
+ ret = erofs_io_read(&vf, chunkdata, len);
+ if (ret < 0)
+ goto err;
+ if (ret != len) {
ret = -EIO;
goto err;
}
diff --git a/lib/io.c b/lib/io.c
index 193b869..3333170 100644
--- a/lib/io.c
+++ b/lib/io.c
@@ -551,11 +551,12 @@ ssize_t erofs_io_read(struct erofs_vfile *vf, void *buf, size_t bytes)
strerror(errno));
return -errno;
}
+ continue;
}
bytes -= ret;
i += ret;
- }
- return i;
+ }
+ return i;
}
ssize_t erofs_io_write(struct erofs_vfile *vf, void *buf, size_t len)
--
2.56.0
^ permalink raw reply related [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-13 8:35 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-13 8:35 [PATCH] erofs-utils: lib: fix reads for chunk-based files Yifan Zhao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox