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


The following commit(s) were added to refs/heads/master by this push:
     new 91e6b146105 fs/v9fs: Do not report a missing file as an error.
91e6b146105 is described below

commit 91e6b146105dc488c7e51ff28de86c11bbe60782
Author: Marco Casaroli <[email protected]>
AuthorDate: Thu Oct 29 22:20:32 2026 +0100

    fs/v9fs: Do not report a missing file as an error.
    
    Each failed walk gave an error message, also when the path does not
    exist: "v9fs_vfs_stat: ERROR: Can't find the fid of the relpath: -2".  A
    missing file is a normal result of stat(), lstat() and open(): a search
    of PATH, a test for a configuration file.  With CONFIG_DEBUG_FS_ERROR
    and a file system on 9P, each such call gave one error line, and the
    real messages left the RAM log.
    
    Report a failed walk only when its error is not ENOENT or ENOTDIR.  The
    other errors (EIO, ENOMEM, EACCES, ENAMETOOLONG, ...) give the message
    as before.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 fs/v9fs/v9fs.c | 57 +++++++++++++++++++++++++++++++++++++++------------------
 1 file changed, 39 insertions(+), 18 deletions(-)

diff --git a/fs/v9fs/v9fs.c b/fs/v9fs/v9fs.c
index c14438bd143..dbebbadce97 100644
--- a/fs/v9fs/v9fs.c
+++ b/fs/v9fs/v9fs.c
@@ -40,6 +40,26 @@
 #include "client.h"
 #include "fs_heap.h"
 
+/****************************************************************************
+ * Pre-processor Definitions
+ ****************************************************************************/
+
+/* Report a failed walk; fmt takes ret as its argument.  A path that does
+ * not exist is a normal result, not an error of the file system: stat()
+ * and open() look for missing files all the time (a search of PATH, a
+ * test for a file).
+ */
+
+#define v9fs_walkerr(ret, fmt) \
+  do \
+    { \
+      if ((ret) != -ENOENT && (ret) != -ENOTDIR) \
+        { \
+          ferr(fmt, ret); \
+        } \
+    } \
+  while (0)
+
 /****************************************************************************
  * Private Type
  ****************************************************************************/
@@ -225,7 +245,8 @@ static int v9fs_vfs_open(FAR struct file *filep, FAR const 
char *relpath,
       ret = v9fs_client_walk(client, relpath, &relpath, false);
       if (ret < 0)
         {
-          ferr("ERROR: Can't find the parent fid of relpath: %d\n", ret);
+          v9fs_walkerr(ret,
+                       "ERROR: Can't find the parent fid of relpath: %d\n");
           goto err_free;
         }
 
@@ -241,7 +262,7 @@ static int v9fs_vfs_open(FAR struct file *filep, FAR const 
char *relpath,
     {
       /* We expect to open this file */
 
-      ferr("ERROR: Can't find the fid of relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the fid of relpath: %d\n");
       goto err_free;
     }
 
@@ -570,7 +591,7 @@ static int v9fs_vfs_opendir(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath, NULL, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the fid of the relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the fid of the relpath: %d\n");
       goto err;
     }
 
@@ -753,7 +774,7 @@ static int v9fs_vfs_unlink(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath, &filename, true);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the parent fid of relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the parent fid of relpath: %d\n");
       return ret;
     }
 
@@ -769,7 +790,7 @@ static int v9fs_vfs_unlink(FAR struct inode *mountpt,
       ret = v9fs_client_walk(client, relpath, NULL, true);
       if (ret < 0)
         {
-          ferr("ERROR: Can't find the fid of relpath: %d\n", ret);
+          v9fs_walkerr(ret, "ERROR: Can't find the fid of relpath: %d\n");
           return ret;
         }
 
@@ -803,7 +824,7 @@ static int v9fs_vfs_mkdir(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath, &relpath, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the parent fid of relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the parent fid of relpath: %d\n");
       return ret;
     }
 
@@ -836,7 +857,7 @@ static int v9fs_vfs_rmdir(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath, &dirname, true);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the parent fid of relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the parent fid of relpath: %d\n");
       return ret;
     }
 
@@ -852,7 +873,7 @@ static int v9fs_vfs_rmdir(FAR struct inode *mountpt,
       ret = v9fs_client_walk(client, relpath, NULL, true);
       if (ret < 0)
         {
-          ferr("ERROR: Can't find the fid of relpath: %d\n", ret);
+          v9fs_walkerr(ret, "ERROR: Can't find the fid of relpath: %d\n");
           return ret;
         }
 
@@ -888,7 +909,7 @@ static int v9fs_vfs_rename(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, oldrelpath, NULL, true);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the fid of the oldrelpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the fid of the oldrelpath: %d\n");
       return ret;
     }
 
@@ -896,8 +917,8 @@ static int v9fs_vfs_rename(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, newrelpath, &newrelpath, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the new parent fid of the newrelpath: %d\n",
-           ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the new parent fid of "
+                        "the newrelpath: %d\n");
       v9fs_fid_put(client, oldfid);
       return ret;
     }
@@ -932,7 +953,7 @@ static int v9fs_vfs_stat(FAR struct inode *mountpt, FAR 
const char *relpath,
   ret = v9fs_client_walk(client, relpath, NULL, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the fid of the relpath: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the fid of the relpath: %d\n");
       return ret;
     }
 
@@ -966,7 +987,7 @@ static int v9fs_vfs_chstat(FAR struct inode *mountpt,
                          (flags & CH_STAT_NOFOLLOW) != 0);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the fid of the relpath %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the fid of the relpath %d\n");
       return ret;
     }
 
@@ -1054,7 +1075,7 @@ static int v9fs_vfs_link(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath1, NULL, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the target file: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the target file: %d\n");
       return ret;
     }
 
@@ -1065,7 +1086,7 @@ static int v9fs_vfs_link(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath2, &relpath2, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find parent directory: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find parent directory: %d\n");
       v9fs_fid_put(client, fid);
       return ret;
     }
@@ -1105,7 +1126,7 @@ static int v9fs_vfs_symlink(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath2, &relpath2, false);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find parent directory: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find parent directory: %d\n");
       return ret;
     }
 
@@ -1144,7 +1165,7 @@ static ssize_t v9fs_vfs_readlink(FAR struct inode 
*mountpt,
   ret = v9fs_client_walk(client, relpath, NULL, true);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the symbolic link: %zd\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the symbolic link: %zd\n");
       return ret;
     }
 
@@ -1198,7 +1219,7 @@ static int v9fs_vfs_lstat(FAR struct inode *mountpt,
   ret = v9fs_client_walk(client, relpath, NULL, true);
   if (ret < 0)
     {
-      ferr("ERROR: Can't find the file: %d\n", ret);
+      v9fs_walkerr(ret, "ERROR: Can't find the file: %d\n");
       return ret;
     }
 

Reply via email to