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 33789b54698 fs/hostfs: Implement syncfs operation
33789b54698 is described below

commit 33789b54698e86fb69d10872fa0911ffc4e7a593
Author: Xiang Xiao <[email protected]>
AuthorDate: Sun Mar 29 15:22:02 2026 +0800

    fs/hostfs: Implement syncfs operation
    
    Add hostfs_syncfs that iterates all open files on the mount
    and calls host_sync on each file descriptor. Previously the
    syncfs slot in the operations table was NULL, causing
    file_syncfs() to return -EBADF.
    
    Signed-off-by: Xiang Xiao <[email protected]>
    Signed-off-by: jingfei <[email protected]>
---
 fs/hostfs/hostfs.c | 41 ++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 40 insertions(+), 1 deletion(-)

diff --git a/fs/hostfs/hostfs.c b/fs/hostfs/hostfs.c
index 05da77db42d..e47ed88b07b 100644
--- a/fs/hostfs/hostfs.c
+++ b/fs/hostfs/hostfs.c
@@ -116,6 +116,7 @@ static int     hostfs_stat(FAR struct inode *mountpt,
 static int     hostfs_chstat(FAR struct inode *mountpt,
                              FAR const char *relpath,
                              FAR const struct stat *buf, int flags);
+static int     hostfs_syncfs(FAR struct inode *mountpt);
 
 #ifdef CONFIG_FS_LINKS
 static int     hostfs_link(FAR struct inode *mountpt,
@@ -175,7 +176,7 @@ const struct mountpt_operations g_hostfs_operations =
   hostfs_rename,        /* rename */
   hostfs_stat,          /* stat */
   hostfs_chstat,        /* chstat */
-  NULL,                 /* syncfs */
+  hostfs_syncfs,        /* syncfs */
   NULL,                 /* ioctldir */
   NULL,                 /* permission */
 #ifdef CONFIG_FS_LINKS
@@ -1518,6 +1519,44 @@ errout_with_path:
   return ret;
 }
 
+/****************************************************************************
+ * Name: hostfs_syncfs
+ *
+ * Description: Synchronize the filesystem
+ *
+ ****************************************************************************/
+
+static int hostfs_syncfs(FAR struct inode *mountpt)
+{
+  FAR struct hostfs_mountpt_s *fs;
+  FAR struct hostfs_ofile_s *hf;
+  int ret;
+
+  /* Sanity checks */
+
+  DEBUGASSERT(mountpt && mountpt->i_private);
+
+  /* Get the mountpoint private data from the inode structure */
+
+  fs = mountpt->i_private;
+
+  ret = nxmutex_lock(&fs->fs_lock);
+  if (ret < 0)
+    {
+      return ret;
+    }
+
+  /* Iterate over all open files and sync each one */
+
+  for (hf = fs->fs_head; hf != NULL; hf = hf->fnext)
+    {
+      host_sync(hf->fd);
+    }
+
+  nxmutex_unlock(&fs->fs_lock);
+  return OK;
+}
+
 #ifdef CONFIG_FS_LINKS
 /****************************************************************************
  * Name: hostfs_link

Reply via email to