* @brief Destroy a virtual node (vnode) and free its resources * * @param[in] vnode Pointer to the vnode to be destroyed * * @return int Always returns 0. Note that this does not guarantee success, as errors may occur internally. */
| 71 | * @return int Always returns 0. Note that this does not guarantee success, as errors may occur internally. |
| 72 | */ |
| 73 | int dfs_vnode_destroy(struct dfs_vnode* vnode) |
| 74 | { |
| 75 | rt_err_t ret = RT_EOK; |
| 76 | |
| 77 | if (vnode) |
| 78 | { |
| 79 | ret = dfs_file_lock(); |
| 80 | if (ret == RT_EOK) |
| 81 | { |
| 82 | if (rt_atomic_load(&(vnode->ref_count)) == 1) |
| 83 | { |
| 84 | LOG_I("free a vnode: %p", vnode); |
| 85 | #ifdef RT_USING_PAGECACHE |
| 86 | if (vnode->aspace) |
| 87 | { |
| 88 | dfs_aspace_destroy(vnode->aspace); |
| 89 | } |
| 90 | #endif |
| 91 | if (vnode->mnt) |
| 92 | { |
| 93 | DLOG(msg, "vnode", vnode->mnt->fs_ops->name, DLOG_MSG, "fs_ops->free_vnode"); |
| 94 | vnode->mnt->fs_ops->free_vnode(vnode); |
| 95 | } |
| 96 | else |
| 97 | { |
| 98 | DLOG(msg, "vnode", "vnode", DLOG_MSG, "destroy vnode(mnt=NULL)"); |
| 99 | } |
| 100 | |
| 101 | dfs_file_unlock(); |
| 102 | |
| 103 | rt_free(vnode); |
| 104 | } |
| 105 | else |
| 106 | { |
| 107 | dfs_file_unlock(); |
| 108 | } |
| 109 | } |
| 110 | } |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
| 115 | /** |
| 116 | * @brief Increase reference count of a virtual node (vnode) |
no test coverage detected