You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2024/11/05 08:57:11 UTC
(nuttx) branch master updated: file_readv_compat/file_writev_compat: Fix partial success handling
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new 8241a10ebc file_readv_compat/file_writev_compat: Fix partial success handling
8241a10ebc is described below
commit 8241a10ebcc259d4b9a9a82337d7124514ffeabd
Author: YAMAMOTO Takashi <ya...@midokura.com>
AuthorDate: Fri Nov 1 13:17:49 2024 +0900
file_readv_compat/file_writev_compat: Fix partial success handling
The problem has been inherited from the original libc readv/writev
implementation. However, now it's exposed in more situations because
this implemenation is used to back read/write as well.
I expect this fixes the regressions observed on the Espressif CI.
https://github.com/apache/nuttx/pull/13498#issuecomment-2448031197
Note that, even with this fix, these "compat" readv/writev
implementations are still inheritedly broken. (E.g. consider that
a data boundary happens to match one of iovec boundaries) However,
this fix is enough for read/write, where iovcnt is always 1.
---
fs/vfs/fs_read.c | 48 +++++++++++++++++++++---------------------------
fs/vfs/fs_write.c | 43 ++++++++++++++++++++++---------------------
2 files changed, 43 insertions(+), 48 deletions(-)
diff --git a/fs/vfs/fs_read.c b/fs/vfs/fs_read.c
index f6b40a0f6f..5e4f3e789b 100644
--- a/fs/vfs/fs_read.c
+++ b/fs/vfs/fs_read.c
@@ -68,42 +68,36 @@ static ssize_t file_readv_compat(FAR struct file *filep,
{
/* Ignore zero-length reads */
- if (iov[i].iov_len > 0)
+ if (iov[i].iov_len == 0)
{
- buffer = iov[i].iov_base;
- remaining = iov[i].iov_len;
-
- /* Read repeatedly as necessary to fill buffer */
+ continue;
+ }
- do
- {
- nread = inode->u.i_ops->read(filep, (void *)buffer,
- remaining);
+ buffer = iov[i].iov_base;
+ remaining = iov[i].iov_len;
- /* Check for a read error */
+ nread = inode->u.i_ops->read(filep, (void *)buffer, remaining);
- if (nread < 0)
- {
- return ntotal ? ntotal : nread;
- }
+ /* Check for a read error */
- /* Check for an end-of-file condition */
+ if (nread < 0)
+ {
+ return ntotal ? ntotal : nread;
+ }
- else if (nread == 0)
- {
- return ntotal;
- }
+ ntotal += nread;
- /* Update pointers and counts in order to handle partial
- * buffer reads.
- */
+ /* Check for a parital success condition, including an end-of-file */
- buffer += nread;
- remaining -= nread;
- ntotal += nread;
- }
- while (remaining > 0);
+ if (nread < remaining)
+ {
+ return ntotal;
}
+
+ /* Update the pointer */
+
+ buffer += nread;
+ remaining -= nread;
}
return ntotal;
diff --git a/fs/vfs/fs_write.c b/fs/vfs/fs_write.c
index 41ce33cf0f..e8b33bf5b4 100644
--- a/fs/vfs/fs_write.c
+++ b/fs/vfs/fs_write.c
@@ -68,35 +68,36 @@ static ssize_t file_writev_compat(FAR struct file *filep,
{
/* Ignore zero-length writes */
- if (iov[i].iov_len > 0)
+ if (iov[i].iov_len == 0)
{
- buffer = iov[i].iov_base;
- remaining = iov[i].iov_len;
+ continue;
+ }
+
+ buffer = iov[i].iov_base;
+ remaining = iov[i].iov_len;
- /* Write repeatedly as necessary to write the entire buffer */
+ nwritten = inode->u.i_ops->write(filep, (void *)buffer, remaining);
- do
- {
- nwritten = inode->u.i_ops->write(filep, (void *)buffer,
- remaining);
+ /* Check for a write error */
- /* Check for a write error */
+ if (nwritten < 0)
+ {
+ return ntotal ? ntotal : nwritten;
+ }
- if (nwritten < 0)
- {
- return ntotal ? ntotal : nwritten;
- }
+ ntotal += nwritten;
- /* Update pointers and counts in order to handle partial
- * buffer writes.
- */
+ /* Check for a parital success condition */
- buffer += nwritten;
- remaining -= nwritten;
- ntotal += nwritten;
- }
- while (remaining > 0);
+ if (nwritten < remaining)
+ {
+ return ntotal;
}
+
+ /* Update the pointer */
+
+ buffer += nwritten;
+ remaining -= nwritten;
}
return ntotal;