erofs-utils: lib: fix reads for chunk-based files
PATCH 1/1 erofs-utils: lib: fix reads for chunk-based files
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 <[email protected]>
--- lib/blobchunk.c | 9 ++++++--- lib/io.c | 5 +++-- 2 files changed, 9 insertions(+), 5 deletions(-)
lib/blobchunk.c +6 -3
@@ -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; }
lib/io.c +3 -2
@@ -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)
Signature · 1 line
2.56.0