This is an automated email from the ASF dual-hosted git repository.

xiaoxiang781216 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit e98e937499fa2023acda35961747641c6d3e7a78
Author: Xiang Xiao <[email protected]>
AuthorDate: Wed Nov 11 23:51:51 2026 +0800

    fs/userfs: fix the response codes of truncate and chstat
    
    userfs_truncate() expects USERFS_RESP_FSTAT, and the daemon side in
    lib_userfs.c replies to a truncate with USERFS_RESP_FSTAT as well, so
    the two only agree by sharing the wrong code.  Add
    USERFS_RESP_TRUNCATE and use it on both sides.
    
    userfs_chstat() expects USERFS_RESP_STAT, but the daemon replies with
    USERFS_RESP_CHSTAT, so every chstat through userfs fails with -EIO.
    Check for USERFS_RESP_CHSTAT instead.
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/userfs/fs_userfs.c         | 4 ++--
 include/nuttx/fs/userfs.h     | 3 ++-
 libs/libc/userfs/lib_userfs.c | 2 +-
 3 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/fs/userfs/fs_userfs.c b/fs/userfs/fs_userfs.c
index cc7a83abfe1..39ab75a7cb2 100644
--- a/fs/userfs/fs_userfs.c
+++ b/fs/userfs/fs_userfs.c
@@ -1130,7 +1130,7 @@ static int userfs_truncate(FAR struct file *filep, off_t 
length)
     }
 
   resp = (FAR struct userfs_truncate_response_s *)priv->iobuffer;
-  if (resp->resp != USERFS_RESP_FSTAT)
+  if (resp->resp != USERFS_RESP_TRUNCATE)
     {
       ferr("ERROR: Incorrect response: %u\n", resp->resp);
       nxmutex_unlock(&priv->lock);
@@ -2330,7 +2330,7 @@ static int userfs_chstat(FAR struct inode *mountpt, FAR 
const char *relpath,
     }
 
   resp = (FAR struct userfs_chstat_response_s *)priv->iobuffer;
-  if (resp->resp != USERFS_RESP_STAT)
+  if (resp->resp != USERFS_RESP_CHSTAT)
     {
       ferr("ERROR: Incorrect response: %u\n", resp->resp);
       nxmutex_unlock(&priv->lock);
diff --git a/include/nuttx/fs/userfs.h b/include/nuttx/fs/userfs.h
index fc98df7c7c0..69e56dc13b5 100644
--- a/include/nuttx/fs/userfs.h
+++ b/include/nuttx/fs/userfs.h
@@ -158,6 +158,7 @@ enum userfs_resp_e
   USERFS_RESP_SYNC,
   USERFS_RESP_DUP,
   USERFS_RESP_FSTAT,
+  USERFS_RESP_TRUNCATE,
   USERFS_RESP_OPENDIR,
   USERFS_RESP_CLOSEDIR,
   USERFS_RESP_READDIR,
@@ -371,7 +372,7 @@ struct userfs_truncate_request_s
 
 struct userfs_truncate_response_s
 {
-  uint8_t resp;             /* Must be USERFS_RESP_FSTAT */
+  uint8_t resp;             /* Must be USERFS_RESP_TRUNCATE */
   int ret;                  /* Result of the operation */
 };
 
diff --git a/libs/libc/userfs/lib_userfs.c b/libs/libc/userfs/lib_userfs.c
index efb47d24133..a65b8de78f2 100644
--- a/libs/libc/userfs/lib_userfs.c
+++ b/libs/libc/userfs/lib_userfs.c
@@ -440,7 +440,7 @@ static inline int userfs_truncate_dispatch(FAR struct 
userfs_info_s *info,
 
   /* Send the response */
 
-  resp.resp = USERFS_RESP_FSTAT;
+  resp.resp = USERFS_RESP_TRUNCATE;
   nsent     = sendto(info->sockfd, &resp,
                      sizeof(struct userfs_truncate_response_s),
                      0, (FAR struct sockaddr *)&info->client,

Reply via email to