From: Yifan Zhao <stopire@gmail.com>
To: linux-erofs@lists.ozlabs.org
Cc: xiang@kernel.org, Yifan Zhao <stopire@gmail.com>
Subject: [PATCH] erofs-utils: lib: fix reads for chunk-based files
Date: Tue, 13 Oct 2026 16:35:17 +0800 [thread overview]
Message-ID: <20261013083517.2435363-1-stopire@gmail.com> (raw)
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
reply other threads:[~2026-10-13 8:35 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261013083517.2435363-1-stopire@gmail.com \
--to=stopire@gmail.com \
--cc=linux-erofs@lists.ozlabs.org \
--cc=xiang@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.