Browse Source

Merge pull request #520 from BernardXiong/master

[DFS] Add fsync function
Bernard Xiong 10 years ago
parent
commit
a6f0b844cf
1 changed files with 30 additions and 0 deletions
  1. 30 0
      components/dfs/src/dfs_posix.c

+ 30 - 0
components/dfs/src/dfs_posix.c

@@ -374,6 +374,36 @@ int fstat(int fildes, struct stat *buf)
 }
 }
 RTM_EXPORT(fstat);
 RTM_EXPORT(fstat);
 
 
+/**
+ * this function is a POSIX compliant version, which shall request that all data 
+ * for the open file descriptor named by fildes is to be transferred to the storage 
+ * device associated with the file described by fildes.
+ *
+ * @param fildes the file description
+ *
+ * @return 0 on successful completion. Otherwise, -1 shall be returned and errno 
+ * set to indicate the error. 
+ */
+int fsync(int fildes)
+{
+    int ret;
+    struct dfs_fd *d;
+
+    /* get the fd */
+    d = fd_get(fildes);
+    if (d == RT_NULL)
+    {
+        rt_set_errno(-DFS_STATUS_EBADF);
+        return -1;
+    }
+
+    ret = dfs_file_flush(d);
+
+    fd_put(d);
+    return ret;
+}
+RTM_EXPORT(fsync);
+
 /**
 /**
  * this function is a POSIX compliant version, which will return the 
  * this function is a POSIX compliant version, which will return the 
  * information about a mounted file system.
  * information about a mounted file system.