mirror of
https://github.com/apache/nuttx.git
synced 2026-05-27 03:05:40 +08:00
fs/vfs: add nx_unlink support
Change-Id: If9009cb7301bb4e49bdce3aea2d56c243256f5a2 Signed-off-by: ligd <liguiding1@xiaomi.com>
This commit is contained in:
+28
-15
@@ -49,17 +49,16 @@
|
|||||||
****************************************************************************/
|
****************************************************************************/
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name: unlink
|
* Name: nx_unlink
|
||||||
*
|
*
|
||||||
* Description: Remove a file managed a mountpoint
|
* 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;
|
struct inode_search_s desc;
|
||||||
FAR struct inode *inode;
|
FAR struct inode *inode;
|
||||||
int errcode;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
/* Get an inode for this file (without deference the final node in the path
|
/* 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 */
|
/* There is no inode that includes in this path */
|
||||||
|
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_search;
|
goto errout_with_search;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,13 +94,12 @@ int unlink(FAR const char *pathname)
|
|||||||
ret = inode->u.i_mops->unlink(inode, desc.relpath);
|
ret = inode->u.i_mops->unlink(inode, desc.relpath);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errcode = ENOSYS;
|
ret = -ENOSYS;
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -131,7 +128,6 @@ int unlink(FAR const char *pathname)
|
|||||||
ret = inode_semtake();
|
ret = inode_semtake();
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +137,7 @@ int unlink(FAR const char *pathname)
|
|||||||
|
|
||||||
if (inode->i_child != NULL)
|
if (inode->i_child != NULL)
|
||||||
{
|
{
|
||||||
errcode = ENOTEMPTY;
|
ret = -ENOTEMPTY;
|
||||||
inode_semgive();
|
inode_semgive();
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
@@ -158,7 +154,6 @@ int unlink(FAR const char *pathname)
|
|||||||
ret = inode->u.i_ops->unlink(inode);
|
ret = inode->u.i_ops->unlink(inode);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -170,7 +165,6 @@ int unlink(FAR const char *pathname)
|
|||||||
ret = inode->u.i_bops->unlink(inode);
|
ret = inode->u.i_bops->unlink(inode);
|
||||||
if (ret < 0)
|
if (ret < 0)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,20 +182,19 @@ int unlink(FAR const char *pathname)
|
|||||||
|
|
||||||
if (ret < 0 && ret != -EBUSY)
|
if (ret < 0 && ret != -EBUSY)
|
||||||
{
|
{
|
||||||
errcode = -ret;
|
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
errcode = EISDIR;
|
ret = -EISDIR;
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
#endif
|
#endif
|
||||||
{
|
{
|
||||||
errcode = ENXIO;
|
ret = -ENXIO;
|
||||||
goto errout_with_inode;
|
goto errout_with_inode;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -216,8 +209,28 @@ errout_with_inode:
|
|||||||
|
|
||||||
errout_with_search:
|
errout_with_search:
|
||||||
RELEASE_SEARCH(&desc);
|
RELEASE_SEARCH(&desc);
|
||||||
set_errno(errcode);
|
return ret;
|
||||||
return ERROR;
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* 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 */
|
#endif /* FS_HAVE_UNLINK */
|
||||||
|
|||||||
@@ -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);
|
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
|
#undef EXTERN
|
||||||
#if defined(__cplusplus)
|
#if defined(__cplusplus)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user