You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2020/12/30 18:21:16 UTC
[incubator-nuttx] 01/02: fs/vfs: add nx_unlink support
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx.git
commit f5b59e287a9f78a53811b0c80fb52c8bb424814a
Author: ligd <li...@xiaomi.com>
AuthorDate: Thu Dec 24 18:22:51 2020 +0800
fs/vfs: add nx_unlink support
Change-Id: If9009cb7301bb4e49bdce3aea2d56c243256f5a2
Signed-off-by: ligd <li...@xiaomi.com>
---
fs/vfs/fs_unlink.c | 43 ++++++++++++++++++++++++++++---------------
include/nuttx/fs/fs.h | 17 +++++++++++++++++
2 files changed, 45 insertions(+), 15 deletions(-)
diff --git a/fs/vfs/fs_unlink.c b/fs/vfs/fs_unlink.c
index 91c12ff..dde986b 100644
--- a/fs/vfs/fs_unlink.c
+++ b/fs/vfs/fs_unlink.c
@@ -49,17 +49,16 @@
****************************************************************************/
/****************************************************************************
- * Name: unlink
+ * Name: nx_unlink
*
* Description: Remove a file managed a mountpoint
*
****************************************************************************/
-int unlink(FAR const char *pathname)
+int nx_unlink(FAR const char *pathname)
{
struct inode_search_s desc;
FAR struct inode *inode;
- int errcode;
int ret;
/* Get an inode for this file (without deference the final node in the path
@@ -73,7 +72,6 @@ int unlink(FAR const char *pathname)
{
/* There is no inode that includes in this path */
- errcode = -ret;
goto errout_with_search;
}
@@ -96,13 +94,12 @@ int unlink(FAR const char *pathname)
ret = inode->u.i_mops->unlink(inode, desc.relpath);
if (ret < 0)
{
- errcode = -ret;
goto errout_with_inode;
}
}
else
{
- errcode = ENOSYS;
+ ret = -ENOSYS;
goto errout_with_inode;
}
}
@@ -131,7 +128,6 @@ int unlink(FAR const char *pathname)
ret = inode_semtake();
if (ret < 0)
{
- errcode = -ret;
goto errout_with_inode;
}
@@ -141,7 +137,7 @@ int unlink(FAR const char *pathname)
if (inode->i_child != NULL)
{
- errcode = ENOTEMPTY;
+ ret = -ENOTEMPTY;
inode_semgive();
goto errout_with_inode;
}
@@ -158,7 +154,6 @@ int unlink(FAR const char *pathname)
ret = inode->u.i_ops->unlink(inode);
if (ret < 0)
{
- errcode = -ret;
goto errout_with_inode;
}
}
@@ -170,7 +165,6 @@ int unlink(FAR const char *pathname)
ret = inode->u.i_bops->unlink(inode);
if (ret < 0)
{
- errcode = -ret;
goto errout_with_inode;
}
}
@@ -188,20 +182,19 @@ int unlink(FAR const char *pathname)
if (ret < 0 && ret != -EBUSY)
{
- errcode = -ret;
goto errout_with_inode;
}
}
else
{
- errcode = EISDIR;
+ ret = -EISDIR;
goto errout_with_inode;
}
}
else
#endif
{
- errcode = ENXIO;
+ ret = -ENXIO;
goto errout_with_inode;
}
@@ -216,8 +209,28 @@ errout_with_inode:
errout_with_search:
RELEASE_SEARCH(&desc);
- set_errno(errcode);
- return ERROR;
+ return ret;
+}
+
+/****************************************************************************
+ * Name: unlink
+ *
+ * Description: Remove a file managed a mountpoint
+ *
+ ****************************************************************************/
+
+int unlink(FAR const char *pathname)
+{
+ int ret;
+
+ ret = nx_unlink(pathname);
+ if (ret < 0)
+ {
+ set_errno(-ret);
+ return ERROR;
+ }
+
+ return OK;
}
#endif /* FS_HAVE_UNLINK */
diff --git a/include/nuttx/fs/fs.h b/include/nuttx/fs/fs.h
index e8ad6c4..bb9ad8f 100644
--- a/include/nuttx/fs/fs.h
+++ b/include/nuttx/fs/fs.h
@@ -1458,6 +1458,23 @@ int file_fstat(FAR struct file *filep, FAR struct stat *buf);
int nx_stat(FAR const char *path, FAR struct stat *buf, int resolve);
+/****************************************************************************
+ * Name: nx_unlink
+ *
+ * Description:
+ * nx_unlink() is similar to the standard 'unlink' interface except that
+ * is not a cancellation point and it does not modify the errno variable.
+ *
+ * nx_unlink() is an internal NuttX interface and should not be called
+ * from applications.
+ *
+ * Returned Value:
+ * Zero is returned on success; a negated value is returned on any failure.
+ *
+ ****************************************************************************/
+
+int nx_unlink(FAR const char *pathname);
+
#undef EXTERN
#if defined(__cplusplus)
}