You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by gn...@apache.org on 2020/05/03 18:16:07 UTC
[incubator-nuttx] 02/09: fs/vfs: Add nx_close function
This is an automated email from the ASF dual-hosted git repository.
gnutt pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit 6418d13b922f96dd7bc02d46fb68bf7245d0c013
Author: Xiang Xiao <xi...@xiaomi.com>
AuthorDate: Sun May 3 11:33:55 2020 +0800
fs/vfs: Add nx_close function
Signed-off-by: Xiang Xiao <xi...@xiaomi.com>
---
fs/vfs/fs_close.c | 96 +++++++++++++++++++++++++++------------------------
include/nuttx/fs/fs.h | 20 +++++++++++
2 files changed, 70 insertions(+), 46 deletions(-)
diff --git a/fs/vfs/fs_close.c b/fs/vfs/fs_close.c
index 6425a2c..f490b2e 100644
--- a/fs/vfs/fs_close.c
+++ b/fs/vfs/fs_close.c
@@ -57,61 +57,38 @@
****************************************************************************/
/****************************************************************************
- * Name: close
+ * Name: nx_close
*
* Description:
- * close() closes a file descriptor, so that it no longer refers to any
- * file and may be reused. Any record locks (see fcntl(2)) held on the file
- * it was associated with, and owned by the process, are removed (regardless
- * of the file descriptor that was used to obtain the lock).
- *
- * If fd is the last copy of a particular file descriptor the resources
- * associated with it are freed; if the descriptor was the last reference
- * to a file which has been removed using unlink(2) the file is deleted.
+ * nx_close() is similar to the standard 'close' interface except that is
+ * not a cancellation point and it does not modify the errno variable.
*
- * Input Parameters:
- * fd file descriptor to close
+ * nx_close() is an internal NuttX interface and should not be called from
+ * applications.
*
* Returned Value:
- * 0 on success; -1 on error with errno set appropriately.
- *
- * Assumptions:
+ * The new file descriptor is returned on success; a negated errno value is
+ * returned on any failure.
*
****************************************************************************/
-int close(int fd)
+int nx_close(int fd)
{
- int errcode;
- int ret;
-
- /* close() is a cancellation point */
-
- enter_cancellation_point();
-
/* Did we get a valid file descriptor? */
- if ((unsigned int)fd >= CONFIG_NFILE_DESCRIPTORS)
+ if (fd >= CONFIG_NFILE_DESCRIPTORS)
{
/* Close a socket descriptor */
#ifdef CONFIG_NET
- if ((unsigned int)fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
+ if (fd < (CONFIG_NFILE_DESCRIPTORS + CONFIG_NSOCKET_DESCRIPTORS))
{
- ret = net_close(fd);
- if (ret < 0)
- {
- errcode = -ret;
- goto errout;
- }
-
- leave_cancellation_point();
- return ret;
+ return net_close(fd);
}
else
#endif
{
- errcode = EBADF;
- goto errout;
+ return -EBADF;
}
}
@@ -125,20 +102,47 @@ int close(int fd)
* vtable.
*/
- ret = files_close(fd);
+ return files_close(fd);
+}
+
+/****************************************************************************
+ * Name: close
+ *
+ * Description:
+ * close() closes a file descriptor, so that it no longer refers to any
+ * file and may be reused. Any record locks (see fcntl(2)) held on the file
+ * it was associated with, and owned by the process, are removed
+ * (regardless of the file descriptor that was used to obtain the lock).
+ *
+ * If fd is the last copy of a particular file descriptor the resources
+ * associated with it are freed; if the descriptor was the last reference
+ * to a file which has been removed using unlink(2) the file is deleted.
+ *
+ * Input Parameters:
+ * fd file descriptor to close
+ *
+ * Returned Value:
+ * 0 on success; -1 on error with errno set appropriately.
+ *
+ * Assumptions:
+ *
+ ****************************************************************************/
+
+int close(int fd)
+{
+ int ret;
+
+ /* close() is a cancellation point */
+
+ enter_cancellation_point();
+
+ ret = nx_close(fd);
if (ret < 0)
{
- /* An error occurred while closing the driver */
-
- errcode = -ret;
- goto errout;
+ set_errno(-ret);
+ ret = ERROR;
}
leave_cancellation_point();
- return OK;
-
-errout:
- set_errno(errcode);
- leave_cancellation_point();
- return ERROR;
+ return ret;
}
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index 4640424..0855d95 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -77,6 +77,7 @@
# else
# define _NX_OPEN nx_open
# endif
+# define _NX_CLOSE(f) nx_close(f)
# define _NX_READ(f,b,s) nx_read(f,b,s)
# define _NX_WRITE(f,b,s) nx_write(f,b,s)
# define _NX_SEEK(f,o,w) nx_seek(f,o,w)
@@ -89,6 +90,7 @@
# else
# define _NX_OPEN open
# endif
+# define _NX_CLOSE(f) close(f)
# define _NX_READ(f,b,s) read(f,b,s)
# define _NX_WRITE(f,b,s) write(f,b,s)
# define _NX_SEEK(f,o,w) lseek(f,o,w)
@@ -861,6 +863,24 @@ int file_detach(int fd, FAR struct file *filep);
int file_close(FAR struct file *filep);
/****************************************************************************
+ * Name: nx_close
+ *
+ * Description:
+ * nx_close() is similar to the standard 'close' interface except that is
+ * not a cancellation point and it does not modify the errno variable.
+ *
+ * nx_close() is an internal NuttX interface and should not be called from
+ * applications.
+ *
+ * Returned Value:
+ * The new file descriptor is returned on success; a negated errno value is
+ * returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_close(int fd);
+
+/****************************************************************************
* Name: open_blockdriver
*
* Description: