MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / dfs_file_unlink

Function dfs_file_unlink

components/dfs/dfs_v2/src/dfs_file.c:1682–1768  ·  view source on GitHub ↗

* @brief Delete a file or directory entry from the filesystem * * This function removes a filesystem entry (file or empty directory) specified by path. * * @param[in] path The filesystem path to be deleted * * @return int Operation result: * - 0 on success * -RT_ERROR if general error occurred * -ENOENT if file not found * -ENOMEM if memory allocation fail

Source from the content-addressed store, hash-verified

1680 * @note Mount points cannot be removed while mounted
1681 */
1682int dfs_file_unlink(const char *path)
1683{
1684 int ret = -RT_ERROR;
1685 char *fullpath = RT_NULL;
1686 struct dfs_mnt *mnt = RT_NULL;
1687 struct dfs_dentry *dentry = RT_NULL;
1688
1689 fullpath = dfs_normalize_path(NULL, path);
1690 if (fullpath)
1691 {
1692 DLOG(msg, "dfs_file", "mnt", DLOG_MSG, "dfs_mnt_lookup(%s)", fullpath);
1693 mnt = dfs_mnt_lookup(fullpath);
1694 if (mnt)
1695 {
1696 char *tmp = dfs_file_realpath(&mnt, fullpath, DFS_REALPATH_EXCEPT_LAST);
1697 if (tmp)
1698 {
1699 rt_free(fullpath);
1700 fullpath = tmp;
1701 }
1702
1703 if (strcmp(mnt->fullpath, fullpath) != 0)
1704 {
1705 DLOG(msg, "dfs_file", "dentry", DLOG_MSG, "dfs_dentry_lookup(mnt, %s)", fullpath);
1706 dentry = dfs_dentry_lookup(mnt, fullpath, 0);
1707 if (dentry)
1708 {
1709 rt_bool_t has_child = RT_FALSE;
1710
1711 has_child = dfs_mnt_has_child_mnt(mnt, fullpath);
1712#ifdef RT_USING_PAGECACHE
1713 if (dentry->vnode->aspace)
1714 {
1715 dfs_aspace_clean(dentry->vnode->aspace);
1716 }
1717#endif
1718 dfs_file_lock();
1719
1720 if (has_child == RT_FALSE)
1721 {
1722 /* no child mnt point, unlink it */
1723 ret = -RT_ERROR;
1724
1725 if (mnt->fs_ops->unlink)
1726 {
1727 if (dfs_is_mounted(mnt) == 0)
1728 {
1729 ret = mnt->fs_ops->unlink(dentry);
1730 }
1731 }
1732 }
1733 else
1734 {
1735 ret = -EBUSY;
1736 }
1737 dfs_file_unlock();
1738
1739 /* release this dentry */

Callers 2

unlinkFunction · 0.70
rmdirFunction · 0.70

Calls 11

dfs_mnt_lookupFunction · 0.85
dfs_file_realpathFunction · 0.85
rt_freeFunction · 0.85
dfs_dentry_lookupFunction · 0.85
dfs_mnt_has_child_mntFunction · 0.85
dfs_aspace_cleanFunction · 0.85
dfs_is_mountedFunction · 0.85
dfs_dentry_unrefFunction · 0.85
dfs_normalize_pathFunction · 0.70
dfs_file_lockFunction · 0.70
dfs_file_unlockFunction · 0.70

Tested by

no test coverage detected