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

Function dfs_file_close

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

* @brief Close a file and release associated resources * * This function closes a file and performs necessary cleanup operations: * - Flushes page cache if enabled (RT_USING_PAGECACHE) * - Calls filesystem-specific close operation if available * - Decrements reference count and releases resources when count reaches zero * * @param[in,out] file Pointer to the file structure to close * * @r

Source from the content-addressed store, hash-verified

838 * - Negative error code on failure
839 */
840int dfs_file_close(struct dfs_file *file)
841{
842 int ret = -RT_ERROR;
843
844 if (file)
845 {
846 if (dfs_file_lock() == RT_EOK)
847 {
848 rt_atomic_t ref_count = rt_atomic_load(&(file->ref_count));
849
850 if (ref_count == 1 && file->fops && file->fops->close)
851 {
852 DLOG(msg, "dfs_file", file->dentry->mnt->fs_ops->name, DLOG_MSG, "fops->close(file)");
853#ifdef RT_USING_PAGECACHE
854 if (file->vnode->aspace)
855 {
856 dfs_aspace_flush(file->vnode->aspace);
857 }
858#endif
859 ret = file->fops->close(file);
860
861 if (ret == 0) /* close file sucessfully */
862 {
863 DLOG(msg, "dfs_file", "dfs_file", DLOG_MSG, "dfs_file_unref(file)");
864 dfs_file_unref(file);
865 }
866 else
867 {
868 LOG_W("close file:%s failed on low level file system", file->dentry->pathname);
869 }
870 }
871 else
872 {
873 DLOG(msg, "dfs_file", "dfs_file", DLOG_MSG, "dfs_file_unref(file)");
874 dfs_file_unref(file);
875 ret = 0;
876 }
877 dfs_file_unlock();
878 }
879 }
880
881 return ret;
882}
883
884/**
885 * @brief Read data from a file at specified offset

Callers 13

closeFunction · 0.70
mkdirFunction · 0.70
opendirFunction · 0.70
closedirFunction · 0.70
on_varea_closeFunction · 0.70
dfs_fdtable_drop_fdFunction · 0.70
dfs_dup_fromFunction · 0.70
sys_dup2Function · 0.70
dfs_file_accessFunction · 0.70
lsFunction · 0.70
catFunction · 0.70
copyfileFunction · 0.70

Calls 4

dfs_aspace_flushFunction · 0.85
dfs_file_unrefFunction · 0.85
dfs_file_lockFunction · 0.70
dfs_file_unlockFunction · 0.70

Tested by

no test coverage detected